Qt 4.8
qtranslator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qplatformdefs.h"
43 
44 #include "qtranslator.h"
45 
46 #ifndef QT_NO_TRANSLATION
47 
48 #include "qfileinfo.h"
49 #include "qstring.h"
50 #include "qstringlist.h"
51 #include "qcoreapplication.h"
52 #include "qcoreapplication_p.h"
53 #include "qdatastream.h"
54 #include "qdir.h"
55 #include "qfile.h"
56 #include "qmap.h"
57 #include "qalgorithms.h"
58 #include "qhash.h"
59 #include "qtranslator_p.h"
60 #include "qlocale.h"
61 #include "qresource.h"
62 
63 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) && !defined(Q_OS_INTEGRITY)
64 #define QT_USE_MMAP
65 #include "private/qcore_unix_p.h"
66 #endif
67 
68 #ifdef Q_OS_SYMBIAN
69 #include "private/qcore_symbian_p.h"
70 #endif
71 
72 // most of the headers below are already included in qplatformdefs.h
73 // also this lacks Large File support but that's probably irrelevant
74 #if defined(QT_USE_MMAP)
75 // for mmap
76 #include <sys/mman.h>
77 #include <errno.h>
78 #endif
79 
80 #include <stdlib.h>
81 
82 #include "qobject_p.h"
83 
85 
88 /*
89 $ mcookie
90 3cb86418caef9c95cd211cbf60a1bddd
91 $
92 */
93 
94 // magic number for the file
95 static const int MagicLength = 16;
96 static const uchar magic[MagicLength] = {
97  0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
98  0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd
99 };
100 
101 static bool match(const uchar* found, const char* target, uint len)
102 {
103  // catch the case if \a found has a zero-terminating symbol and \a len includes it.
104  // (normalize it to be without the zero-terminating symbol)
105  if (len > 0 && found[len-1] == '\0')
106  --len;
107  return (memcmp(found, target, len) == 0 && target[len] == '\0');
108 }
109 
110 static uint elfHash(const char *name)
111 {
112  const uchar *k;
113  uint h = 0;
114  uint g;
115 
116  if (name) {
117  k = (const uchar *) name;
118  while (*k) {
119  h = (h << 4) + *k++;
120  if ((g = (h & 0xf0000000)) != 0)
121  h ^= g >> 24;
122  h &= ~g;
123  }
124  }
125  if (!h)
126  h = 1;
127  return h;
128 }
129 
130 static int numerusHelper(int n, const uchar *rules, int rulesSize)
131 {
132 #define CHECK_RANGE \
133  do { \
134  if (i >= rulesSize) \
135  return -1; \
136  } while (0)
137 
138  int result = 0;
139  int i = 0;
140 
141  if (rulesSize == 0)
142  return 0;
143 
144  for (;;) {
145  bool orExprTruthValue = false;
146 
147  for (;;) {
148  bool andExprTruthValue = true;
149 
150  for (;;) {
151  bool truthValue = true;
152 
153  CHECK_RANGE;
154  int opcode = rules[i++];
155 
156  int leftOperand = n;
157  if (opcode & Q_MOD_10) {
158  leftOperand %= 10;
159  } else if (opcode & Q_MOD_100) {
160  leftOperand %= 100;
161  } else if (opcode & Q_LEAD_1000) {
162  while (leftOperand >= 1000)
163  leftOperand /= 1000;
164  }
165 
166  int op = opcode & Q_OP_MASK;
167 
168  CHECK_RANGE;
169  int rightOperand = rules[i++];
170 
171  switch (op) {
172  default:
173  return -1;
174  case Q_EQ:
175  truthValue = (leftOperand == rightOperand);
176  break;
177  case Q_LT:
178  truthValue = (leftOperand < rightOperand);
179  break;
180  case Q_LEQ:
181  truthValue = (leftOperand <= rightOperand);
182  break;
183  case Q_BETWEEN:
184  int bottom = rightOperand;
185  CHECK_RANGE;
186  int top = rules[i++];
187  truthValue = (leftOperand >= bottom && leftOperand <= top);
188  }
189 
190  if (opcode & Q_NOT)
191  truthValue = !truthValue;
192 
193  andExprTruthValue = andExprTruthValue && truthValue;
194 
195  if (i == rulesSize || rules[i] != Q_AND)
196  break;
197  ++i;
198  }
199 
200  orExprTruthValue = orExprTruthValue || andExprTruthValue;
201 
202  if (i == rulesSize || rules[i] != Q_OR)
203  break;
204  ++i;
205  }
206 
207  if (orExprTruthValue)
208  return result;
209 
210  ++result;
211 
212  if (i == rulesSize)
213  return result;
214 
215  if (rules[i++] != Q_NEWRULE)
216  break;
217  }
218  return -1;
219 }
220 
222 {
224 public:
225  enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69, NumerusRules = 0x88 };
226 
228  : used_mmap(0), unmapPointer(0), unmapLength(0), resource(0),
231 
232  // for mmap'ed files, this is what needs to be unmapped.
233  bool used_mmap : 1;
235  unsigned int unmapLength;
236 
237  // The resource object in case we loaded the translations from a resource
239 
240  // for squeezed but non-file data, this is what needs to be deleted
249 
250  bool do_load(const QString &filename);
251  bool do_load(const uchar *data, int len);
252  QString do_translate(const char *context, const char *sourceText, const char *comment,
253  int n) const;
254  void clear();
255 };
256 
343  : QObject(*new QTranslatorPrivate, parent)
344 {
345 }
346 
347 #ifdef QT3_SUPPORT
348 
353  : QObject(*new QTranslatorPrivate, parent)
354 {
356 }
357 #endif
358 
364 {
367  Q_D(QTranslator);
368  d->clear();
369 }
370 
411 bool QTranslator::load(const QString & filename, const QString & directory,
412  const QString & search_delimiters,
413  const QString & suffix)
414 {
415  Q_D(QTranslator);
416  d->clear();
417 
418  QString fname = filename;
419  QString prefix;
420  if (QFileInfo(filename).isRelative()) {
421 #ifdef Q_OS_SYMBIAN
422  //TFindFile doesn't like path in the filename
423  QString dir(directory);
424  int slash = filename.lastIndexOf(QLatin1Char('/'));
425  slash = qMax(slash, filename.lastIndexOf(QLatin1Char('\\')));
426  if (slash >=0) {
427  //so move the path component into the directory prefix
428  if (dir.isEmpty())
429  dir = filename.left(slash + 1);
430  else
431  dir = dir + QLatin1Char('/') + filename.left(slash + 1);
432  fname = fname.mid(slash + 1);
433  }
434  if (dir.isEmpty())
436  else
437  prefix = QFileInfo(dir).absoluteFilePath(); //TFindFile doesn't like dirty paths
438  if (prefix.length() > 2 && prefix.at(1) == QLatin1Char(':') && prefix.at(0).isLetter())
439  prefix[0] = QLatin1Char('Y');
440 #else
441  prefix = directory;
442 #endif
443  if (prefix.length() && !prefix.endsWith(QLatin1Char('/')))
444  prefix += QLatin1Char('/');
445  }
446 
447 #ifdef Q_OS_SYMBIAN
448  QString nativePrefix = QDir::toNativeSeparators(prefix);
449 #endif
450 
451  QString realname;
452  QString delims;
453  delims = search_delimiters.isNull() ? QString::fromLatin1("_.") : search_delimiters;
454 
455  for (;;) {
456  QFileInfo fi;
457 
458 #ifdef Q_OS_SYMBIAN
459  //search for translations on other drives, e.g. Qt may be in Z, while app is in C
460  //note this uses symbian search rules, i.e. y:->a:, followed by z:
461  TFindFile finder(qt_s60GetRFs());
462  QString fname2 = fname + (suffix.isNull() ? QString::fromLatin1(".qm") : suffix);
463  TInt err = finder.FindByDir(
464  qt_QString2TPtrC(fname2),
465  qt_QString2TPtrC(nativePrefix));
466  if (err != KErrNone)
467  err = finder.FindByDir(qt_QString2TPtrC(fname), qt_QString2TPtrC(nativePrefix));
468  if (err == KErrNone) {
469  fi.setFile(qt_TDesC2QString(finder.File()));
470  realname = fi.canonicalFilePath();
471  if (fi.isReadable() && fi.isFile())
472  break;
473  }
474 #endif
475 
476  realname = prefix + fname + (suffix.isNull() ? QString::fromLatin1(".qm") : suffix);
477  fi.setFile(realname);
478  if (fi.isReadable() && fi.isFile())
479  break;
480 
481  realname = prefix + fname;
482  fi.setFile(realname);
483  if (fi.isReadable() && fi.isFile())
484  break;
485 
486  int rightmost = 0;
487  for (int i = 0; i < (int)delims.length(); i++) {
488  int k = fname.lastIndexOf(delims[i]);
489  if (k > rightmost)
490  rightmost = k;
491  }
492 
493  // no truncations? fail
494  if (rightmost == 0)
495  return false;
496 
497  fname.truncate(rightmost);
498  }
499 
500  // realname is now the fully qualified name of a readable file.
501  return d->do_load(realname);
502 }
503 
505 {
506  QTranslatorPrivate *d = this;
507  bool ok = false;
508 
509  const bool isResourceFile = realname.startsWith(QLatin1Char(':'));
510  if (isResourceFile) {
511  // If the translation is in a non-compressed resource file, the data is already in
512  // memory, so no need to use QFile to copy it again.
513  Q_ASSERT(!d->resource);
514  d->resource = new QResource(realname);
515  if (d->resource->isValid() && !d->resource->isCompressed()) {
516  d->unmapLength = d->resource->size();
517  d->unmapPointer = reinterpret_cast<char *>(const_cast<uchar *>(d->resource->data()));
518  d->used_mmap = false;
519  ok = true;
520  } else {
521  delete d->resource;
522  d->resource = 0;
523  }
524  }
525 
526 #ifdef QT_USE_MMAP
527 
528 #ifndef MAP_FILE
529 #define MAP_FILE 0
530 #endif
531 #ifndef MAP_FAILED
532 #define MAP_FAILED -1
533 #endif
534 
535  else {
536  int fd = QT_OPEN(QFile::encodeName(realname), O_RDONLY,
537 #if defined(Q_OS_WIN)
539 #else
540  0666
541 #endif
542  );
543 
544  if (fd >= 0) {
545  QT_STATBUF st;
546  if (!QT_FSTAT(fd, &st)) {
547  char *ptr;
548  ptr = reinterpret_cast<char *>(
549  mmap(0, st.st_size, // any address, whole file
550  PROT_READ, // read-only memory
551  MAP_FILE | MAP_PRIVATE, // swap-backed map from file
552  fd, 0)); // from offset 0 of fd
553  if (ptr && ptr != reinterpret_cast<char *>(MAP_FAILED)) {
554  d->used_mmap = true;
555  d->unmapPointer = ptr;
556  d->unmapLength = st.st_size;
557  ok = true;
558  }
559  }
560  ::close(fd);
561  }
562  }
563 #endif // QT_USE_MMAP
564 
565  if (!ok) {
566  QFile file(realname);
567  d->unmapLength = file.size();
568  if (!d->unmapLength)
569  return false;
570  d->unmapPointer = new char[d->unmapLength];
571 
572  if (file.open(QIODevice::ReadOnly))
573  ok = (d->unmapLength == (uint)file.read(d->unmapPointer, d->unmapLength));
574 
575  if (!ok) {
576  delete [] d->unmapPointer;
577  d->unmapPointer = 0;
578  d->unmapLength = 0;
579  return false;
580  }
581  }
582 
583  return d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength);
584 }
585 
586 static QString find_translation(const QLocale & locale,
587  const QString & filename,
588  const QString & prefix,
589  const QString & directory,
590  const QString & suffix)
591 {
592  QString path;
593  if (QFileInfo(filename).isRelative()) {
594  path = directory;
595  if (!path.isEmpty() && !path.endsWith(QLatin1Char('/')))
596  path += QLatin1Char('/');
597  }
598 
599  QFileInfo fi;
600  QString realname;
601  QStringList fuzzyLocales;
602 
603  // see http://www.unicode.org/reports/tr35/#LanguageMatching for inspiration
604 
605  QStringList languages = locale.uiLanguages();
606 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
607  for (int i = languages.size()-1; i >= 0; --i) {
608  QString lang = languages.at(i);
609  QString lowerLang = lang.toLower();
610  if (lang != lowerLang)
611  languages.insert(i+1, lowerLang);
612  }
613 #endif
614 
615  // try explicit locales names first
616  foreach (QString localeName, languages) {
617  localeName.replace(QLatin1Char('-'), QLatin1Char('_'));
618 
619  realname = path + filename + prefix + localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix);
620  fi.setFile(realname);
621  if (fi.isReadable() && fi.isFile())
622  return realname;
623 
624  realname = path + filename + prefix + localeName;
625  fi.setFile(realname);
626  if (fi.isReadable() && fi.isFile())
627  return realname;
628 
629  fuzzyLocales.append(localeName);
630  }
631 
632  // start guessing
633  foreach (QString localeName, fuzzyLocales) {
634  for (;;) {
635  int rightmost = localeName.lastIndexOf(QLatin1Char('_'));
636  // no truncations? fail
637  if (rightmost <= 0)
638  break;
639  localeName.truncate(rightmost);
640 
641  realname = path + filename + prefix + localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix);
642  fi.setFile(realname);
643  if (fi.isReadable() && fi.isFile())
644  return realname;
645 
646  realname = path + filename + prefix + localeName;
647  fi.setFile(realname);
648  if (fi.isReadable() && fi.isFile())
649  return realname;
650  }
651  }
652 
653  if (!suffix.isNull()) {
654  realname = path + filename + suffix;
655  fi.setFile(realname);
656  if (fi.isReadable() && fi.isFile())
657  return realname;
658  }
659 
660  realname = path + filename + prefix;
661  fi.setFile(realname);
662  if (fi.isReadable() && fi.isFile())
663  return realname;
664 
665  realname = path + filename;
666  fi.setFile(realname);
667  if (fi.isReadable() && fi.isFile())
668  return realname;
669 
670  return QString();
671 }
672 
718 bool QTranslator::load(const QLocale & locale,
719  const QString & filename,
720  const QString & prefix,
721  const QString & directory,
722  const QString & suffix)
723 {
724  Q_D(QTranslator);
725  d->clear();
726  QString fname = find_translation(locale, filename, prefix, directory, suffix);
727  return !fname.isEmpty() && d->do_load(fname);
728 }
729 
740 bool QTranslator::load(const uchar *data, int len)
741 {
742  Q_D(QTranslator);
743  d->clear();
744  return d->do_load(data, len);
745 }
746 
747 static quint8 read8(const uchar *data)
748 {
749  return *data;
750 }
751 
752 static quint16 read16(const uchar *data)
753 {
754  return (data[0] << 8) | (data[1]);
755 }
756 
757 static quint32 read32(const uchar *data)
758 {
759  return (data[0] << 24)
760  | (data[1] << 16)
761  | (data[2] << 8)
762  | (data[3]);
763 }
764 
766 {
767  if (!data || len < MagicLength || memcmp(data, magic, MagicLength))
768  return false;
769 
770  bool ok = true;
771  const uchar *end = data + len;
772 
773  data += MagicLength;
774 
775  while (data < end - 4) {
776  quint8 tag = read8(data++);
777  quint32 blockLen = read32(data);
778  data += 4;
779  if (!tag || !blockLen)
780  break;
781  if (data + blockLen > end) {
782  ok = false;
783  break;
784  }
785 
786  if (tag == QTranslatorPrivate::Contexts) {
787  contextArray = data;
788  contextLength = blockLen;
789  } else if (tag == QTranslatorPrivate::Hashes) {
790  offsetArray = data;
791  offsetLength = blockLen;
792  } else if (tag == QTranslatorPrivate::Messages) {
793  messageArray = data;
794  messageLength = blockLen;
795  } else if (tag == QTranslatorPrivate::NumerusRules) {
796  numerusRulesArray = data;
797  numerusRulesLength = blockLen;
798  }
799 
800  data += blockLen;
801  }
802 
803  return ok;
804 }
805 
806 static QString getMessage(const uchar *m, const uchar *end, const char *context,
807  const char *sourceText, const char *comment, int numerus)
808 {
809  const uchar *tn = 0;
810  uint tn_length = 0;
811  int currentNumerus = -1;
812 
813  for (;;) {
814  uchar tag = 0;
815  if (m < end)
816  tag = read8(m++);
817  switch((Tag)tag) {
818  case Tag_End:
819  goto end;
820  case Tag_Translation: {
821  int len = read32(m);
822  if (len % 1)
823  return QString();
824  m += 4;
825  if (++currentNumerus == numerus) {
826  tn_length = len;
827  tn = m;
828  }
829  m += len;
830  break;
831  }
832  case Tag_Obsolete1:
833  m += 4;
834  break;
835  case Tag_SourceText: {
836  quint32 len = read32(m);
837  m += 4;
838  if (!match(m, sourceText, len))
839  return QString();
840  m += len;
841  }
842  break;
843  case Tag_Context: {
844  quint32 len = read32(m);
845  m += 4;
846  if (!match(m, context, len))
847  return QString();
848  m += len;
849  }
850  break;
851  case Tag_Comment: {
852  quint32 len = read32(m);
853  m += 4;
854  if (*m && !match(m, comment, len))
855  return QString();
856  m += len;
857  }
858  break;
859  default:
860  return QString();
861  }
862  }
863 end:
864  if (!tn)
865  return QString();
866  QString str = QString((const QChar *)tn, tn_length/2);
867  if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
868  for (int i = 0; i < str.length(); ++i)
869  str[i] = QChar((str.at(i).unicode() >> 8) + ((str.at(i).unicode() << 8) & 0xff00));
870  }
871  return str;
872 }
873 
874 QString QTranslatorPrivate::do_translate(const char *context, const char *sourceText,
875  const char *comment, int n) const
876 {
877  if (context == 0)
878  context = "";
879  if (sourceText == 0)
880  sourceText = "";
881  if (comment == 0)
882  comment = "";
883 
884  if (!offsetLength)
885  return QString();
886 
887  /*
888  Check if the context belongs to this QTranslator. If many
889  translators are installed, this step is necessary.
890  */
891  if (contextLength) {
892  quint16 hTableSize = read16(contextArray);
893  uint g = elfHash(context) % hTableSize;
894  const uchar *c = contextArray + 2 + (g << 1);
895  quint16 off = read16(c);
896  c += 2;
897  if (off == 0)
898  return QString();
899  c = contextArray + (2 + (hTableSize << 1) + (off << 1));
900 
901  for (;;) {
902  quint8 len = read8(c++);
903  if (len == 0)
904  return QString();
905  if (match(c, context, len))
906  break;
907  c += len;
908  }
909  }
910 
911  size_t numItems = offsetLength / (2 * sizeof(quint32));
912  if (!numItems)
913  return QString();
914 
915  int numerus = 0;
916  if (n >= 0)
917  numerus = numerusHelper(n, numerusRulesArray, numerusRulesLength);
918 
919  for (;;) {
920  quint32 h = elfHash(QByteArray(QByteArray(sourceText) + comment).constData());
921 
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);
926  uint hash = read32(middle);
927  if (h == hash) {
928  start = middle;
929  break;
930  } else if (hash < h) {
931  start = middle + 8;
932  } else {
933  end = middle - 8;
934  }
935  }
936 
937  if (start <= end) {
938  // go back on equal key
939  while (start != offsetArray && read32(start) == read32(start-8))
940  start -= 8;
941 
942  while (start < offsetArray + offsetLength) {
943  quint32 rh = read32(start);
944  start += 4;
945  if (rh != h)
946  break;
947  quint32 ro = read32(start);
948  start += 4;
949  QString tn = getMessage(messageArray + ro, messageArray + messageLength, context,
950  sourceText, comment, numerus);
951  if (!tn.isNull())
952  return tn;
953  }
954  }
955  if (!comment[0])
956  break;
957  comment = "";
958  }
959  return QString();
960 }
961 
969 {
970  Q_Q(QTranslator);
971  if (unmapPointer && unmapLength) {
972 #if defined(QT_USE_MMAP)
973  if (used_mmap)
974  munmap(unmapPointer, unmapLength);
975  else
976 #endif
977  if (!resource)
978  delete [] unmapPointer;
979  }
980 
981  delete resource;
982  resource = 0;
983  unmapPointer = 0;
984  unmapLength = 0;
985  messageArray = 0;
986  contextArray = 0;
987  offsetArray = 0;
988  numerusRulesArray = 0;
989  messageLength = 0;
990  contextLength = 0;
991  offsetLength = 0;
992  numerusRulesLength = 0;
993 
997 }
998 
1009 QString QTranslator::translate(const char *context, const char *sourceText, const char *disambiguation) const
1010 {
1011  Q_D(const QTranslator);
1012  return d->do_translate(context, sourceText, disambiguation, -1);
1013 }
1014 
1015 
1031 QString QTranslator::translate(const char *context, const char *sourceText, const char *disambiguation,
1032  int n) const
1033 {
1034  Q_D(const QTranslator);
1035  // this step is necessary because the 3-parameter translate() overload is virtual
1036  if (n == -1)
1037  return translate(context, sourceText, disambiguation);
1038  return d->do_translate(context, sourceText, disambiguation, n);
1039 }
1040 
1046 {
1047  Q_D(const QTranslator);
1048  return !d->unmapPointer && !d->unmapLength && !d->messageArray &&
1049  !d->offsetArray && !d->contextArray;
1050 }
1051 
1059 
1060 #endif // QT_NO_TRANSLATION
Tag
Definition: qtranslator.cpp:86
double d
Definition: qnumeric_p.h:62
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
const uchar * offsetArray
~QTranslator()
Destroys the object and frees any allocated resources.
#define _S_IREAD
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
Definition: qchar.cpp:653
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
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)
Definition: qstring.cpp:2005
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static QString getMessage(const uchar *m, const uchar *end, const char *context, const char *sourceText, const char *comment, int numerus)
#define O_RDONLY
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.
Definition: qstring.cpp:3734
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
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)
unsigned char quint8
Definition: qglobal.h:934
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int numerusHelper(int n, const uchar *rules, int rulesSize)
qint64 size() const
Returns the size of the data backing the resource.
Definition: qresource.cpp:510
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static quint32 read32(const uchar *data)
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
#define MAP_FAILED
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
unsigned int unmapLength
QStringList uiLanguages() const
Returns an ordered list of locale names for translation purposes in preference order.
Definition: qlocale.cpp:3410
static const int MagicLength
Definition: qtranslator.cpp:95
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...
unsigned char uchar
Definition: qglobal.h:994
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static QString applicationDirPath()
Returns the directory that contains the application executable.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isValid() const
Returns true if the resource really exists in the resource hierarchy, false otherwise.
Definition: qresource.cpp:470
The QResource class provides an interface for reading directly from resources.
Definition: qresource.h:58
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const uchar * data() const
Returns direct access to a read only segment of data that this resource represents.
Definition: qresource.cpp:526
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
Definition: qfileinfo.cpp:468
void clear()
Empties this translator of all contents.
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
bool isCompressed() const
Returns true if the resource represents a file and the data backing it is in a compressed format...
Definition: qresource.cpp:497
QResource * resource
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.
Definition: qfile.cpp:1707
The QTranslator class provides internationalization support for text output.
Definition: qtranslator.h:59
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
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...
Definition: qstring.cpp:3706
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)
Definition: qglobal.h:2477
#define QT_OPEN
Definition: qcore_unix_p.h:186
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static QCoreApplication * instance()
Returns a pointer to the application&#39;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
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
static bool isTranslatorInstalled(QTranslator *translator)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
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.
Definition: qstring.cpp:5389
QByteArray suffix
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
Definition: qfileinfo.cpp:971
QObject * parent
Definition: qobject.h:92
#define Q_OS_WIN
Definition: qglobal.h:270
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&#39;s loca...
Definition: qfile.cpp:528
const uchar * messageArray
#define _S_IWRITE
bool isReadable() const
Returns true if the user can read the file; otherwise returns false.
Definition: qfileinfo.cpp:896
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.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
static const KeyPair *const end
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
static const uchar magic[MagicLength]
Definition: qtranslator.cpp:96
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define CHECK_RANGE
#define MAP_FILE
static QString find_translation(const QLocale &locale, const QString &filename, const QString &prefix, const QString &directory, const QString &suffix)