42 #include "qplatformdefs.h" 46 #ifndef QT_NO_TRANSLATION 63 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) && !defined(Q_OS_INTEGRITY) 65 #include "private/qcore_unix_p.h" 69 #include "private/qcore_symbian_p.h" 74 #if defined(QT_USE_MMAP) 97 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
98 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd
105 if (len > 0 && found[len-1] ==
'\0')
107 return (memcmp(found, target, len) == 0 && target[len] ==
'\0');
117 k = (
const uchar *) name;
120 if ((g = (h & 0xf0000000)) != 0)
132 #define CHECK_RANGE \ 134 if (i >= rulesSize) \ 145 bool orExprTruthValue =
false;
148 bool andExprTruthValue =
true;
151 bool truthValue =
true;
154 int opcode = rules[i++];
162 while (leftOperand >= 1000)
169 int rightOperand = rules[i++];
175 truthValue = (leftOperand == rightOperand);
178 truthValue = (leftOperand < rightOperand);
181 truthValue = (leftOperand <= rightOperand);
184 int bottom = rightOperand;
186 int top = rules[i++];
187 truthValue = (leftOperand >= bottom && leftOperand <= top);
191 truthValue = !truthValue;
193 andExprTruthValue = andExprTruthValue && truthValue;
195 if (i == rulesSize || rules[i] !=
Q_AND)
200 orExprTruthValue = orExprTruthValue || andExprTruthValue;
202 if (i == rulesSize || rules[i] !=
Q_OR)
207 if (orExprTruthValue)
412 const QString & search_delimiters,
429 dir = filename.
left(slash + 1);
432 fname = fname.
mid(slash + 1);
461 TFindFile finder(qt_s60GetRFs());
463 TInt err = finder.FindByDir(
464 qt_QString2TPtrC(fname2),
465 qt_QString2TPtrC(nativePrefix));
467 err = finder.FindByDir(qt_QString2TPtrC(fname), qt_QString2TPtrC(nativePrefix));
468 if (err == KErrNone) {
469 fi.
setFile(qt_TDesC2QString(finder.File()));
481 realname = prefix + fname;
487 for (
int i = 0; i < (int)delims.
length(); i++) {
488 int k = fname.lastIndexOf(delims[i]);
497 fname.truncate(rightmost);
501 return d->do_load(realname);
510 if (isResourceFile) {
532 #define MAP_FAILED -1 546 if (!QT_FSTAT(fd, &st)) {
548 ptr =
reinterpret_cast<char *
>(
553 if (ptr && ptr != reinterpret_cast<char *>(
MAP_FAILED)) {
563 #endif // QT_USE_MMAP 566 QFile file(realname);
606 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) 607 for (
int i = languages.
size()-1; i >= 0; --i) {
610 if (lang != lowerLang)
611 languages.
insert(i+1, lowerLang);
616 foreach (
QString localeName, languages) {
624 realname = path + filename + prefix + localeName;
629 fuzzyLocales.
append(localeName);
633 foreach (
QString localeName, fuzzyLocales) {
646 realname = path + filename + prefix + localeName;
654 realname = path + filename +
suffix;
660 realname = path + filename + prefix;
665 realname = path + filename;
727 return !fname.
isEmpty() &&
d->do_load(fname);
744 return d->do_load(data, len);
754 return (data[0] << 8) | (data[1]);
759 return (data[0] << 24)
775 while (data < end - 4) {
779 if (!tag || !blockLen)
781 if (data + blockLen > end) {
788 contextLength = blockLen;
791 offsetLength = blockLen;
794 messageLength = blockLen;
796 numerusRulesArray =
data;
797 numerusRulesLength = blockLen;
807 const char *sourceText,
const char *comment,
int numerus)
811 int currentNumerus = -1;
825 if (++currentNumerus == numerus) {
838 if (!
match(m, sourceText, len))
846 if (!
match(m, context, len))
854 if (*m && !
match(m, comment, len))
867 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
868 for (
int i = 0; i < str.
length(); ++i)
875 const char *comment,
int n)
const 894 const uchar *
c = contextArray + 2 + (g << 1);
899 c = contextArray + (2 + (hTableSize << 1) + (off << 1));
905 if (
match(c, context, len))
911 size_t numItems = offsetLength / (2 *
sizeof(
quint32));
917 numerus =
numerusHelper(n, numerusRulesArray, numerusRulesLength);
922 const uchar *start = offsetArray;
923 const uchar *
end = start + ((numItems-1) << 3);
924 while (start <= end) {
925 const uchar *middle = start + (((end - start) >> 4) << 3);
930 }
else if (hash < h) {
939 while (start != offsetArray &&
read32(start) ==
read32(start-8))
942 while (start < offsetArray + offsetLength) {
949 QString tn =
getMessage(messageArray + ro, messageArray + messageLength, context,
950 sourceText, comment, numerus);
971 if (unmapPointer && unmapLength) {
972 #if defined(QT_USE_MMAP) 974 munmap(unmapPointer, unmapLength);
978 delete [] unmapPointer;
988 numerusRulesArray = 0;
992 numerusRulesLength = 0;
1012 return d->do_translate(context, sourceText, disambiguation, -1);
1037 return translate(context, sourceText, disambiguation);
1038 return d->do_translate(context, sourceText, disambiguation, n);
1048 return !
d->unmapPointer && !
d->unmapLength && !
d->messageArray &&
1049 !
d->offsetArray && !
d->contextArray;
1060 #endif // QT_NO_TRANSLATION
static uint hash(const uchar *p, int n)
const uchar * offsetArray
~QTranslator()
Destroys the object and frees any allocated resources.
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
#define QT_END_NAMESPACE
This macro expands to.
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
const QChar at(int i) const
Returns the character at the given index position in the string.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
static void removeTranslator(QTranslator *messageFile)
Removes the translation file translationFile from the list of translation files used by this applicat...
QString & replace(int i, int len, QChar after)
The QByteArray class provides an array of bytes.
int length() const
Returns the number of characters in this string.
static QString getMessage(const uchar *m, const uchar *end, const char *context, const char *sourceText, const char *comment, int numerus)
static bool match(const uchar *found, const char *target, uint len)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
void insert(int i, const T &t)
Inserts value at index position i in the list.
QString absoluteFilePath() const
Returns an absolute path including the file name.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QString do_translate(const char *context, const char *sourceText, const char *comment, int n) const
bool do_load(const QString &filename)
The QString class provides a Unicode character string.
static int numerusHelper(int n, const uchar *rules, int rulesSize)
qint64 size() const
Returns the size of the data backing the resource.
The QObject class is the base class of all Qt objects.
static quint32 read32(const uchar *data)
The QChar class provides a 16-bit Unicode character.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setObjectName(const QString &name)
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
QStringList uiLanguages() const
Returns an ordered list of locale names for translation purposes in preference order.
static const int MagicLength
bool load(const QString &filename, const QString &directory=QString(), const QString &search_delimiters=QString(), const QString &suffix=QString())
Loads filename + suffix (".qm" if the suffix is not specified), which may be an absolute file name or...
void append(const T &t)
Inserts value at the end of the list.
static QString applicationDirPath()
Returns the directory that contains the application executable.
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isValid() const
Returns true if the resource really exists in the resource hierarchy, false otherwise.
The QResource class provides an interface for reading directly from resources.
void truncate(int pos)
Truncates the string at the given position index.
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
const uchar * data() const
Returns direct access to a read only segment of data that this resource represents.
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
void clear()
Empties this translator of all contents.
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
static const char * data(const QByteArray &arr)
bool isCompressed() const
Returns true if the resource represents a file and the data backing it is in a compressed format...
const T * ptr(const T &t)
static uint elfHash(const char *name)
static quint16 read16(const uchar *data)
qint64 size() const
Returns the size of the file.
The QTranslator class provides internationalization support for text output.
bool isNull() const
Returns true if this string is null; otherwise returns false.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
virtual QString translate(const char *context, const char *sourceText, const char *disambiguation=0) const
Returns the translation for the key (context, sourceText, disambiguation).
const uchar * numerusRulesArray
#define Q_DECLARE_PUBLIC(Class)
The QFile class provides an interface for reading from and writing to files.
static QCoreApplication * instance()
Returns a pointer to the application's QCoreApplication (or QApplication) instance.
virtual bool isEmpty() const
Returns true if this translator is empty, otherwise returns false.
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
static bool isTranslatorInstalled(QTranslator *translator)
QObject * parent() const
Returns a pointer to the parent object.
QTranslator(QObject *parent=0)
Constructs an empty message file object with parent parent that is not connected to any file...
#define st(var, type, card)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
int size() const
Returns the number of items in the list.
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
static quint8 read8(const uchar *data)
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
const uchar * messageArray
bool isReadable() const
Returns true if the user can read the file; otherwise returns false.
const uchar * contextArray
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
The QFileInfo class provides system-independent file information.
static const KeyPair *const end
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the '/' separators converted to separators that are appropriate for the underly...
The QEvent class is the base class of all event classes.
static const uchar magic[MagicLength]
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
static QString find_translation(const QLocale &locale, const QString &filename, const QString &prefix, const QString &directory, const QString &suffix)