summaryrefslogtreecommitdiffstats
path: root/tools/linguist
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-09-02 07:29:55 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-09-02 07:29:55 (GMT)
commitb22697903a004fa947bae916a152ac3311346510 (patch)
tree4639df95de79474e3c5089d89f3de28964b73129 /tools/linguist
parentb6d47ea4872e188d8da6886cb1922f1a89245825 (diff)
parent63eab5ef720936dbb5ee76686c6558e18a79e587 (diff)
downloadQt-b22697903a004fa947bae916a152ac3311346510.zip
Qt-b22697903a004fa947bae916a152ac3311346510.tar.gz
Qt-b22697903a004fa947bae916a152ac3311346510.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/lconvert/main.cpp21
-rw-r--r--tools/linguist/linguist/phrase.cpp7
-rw-r--r--tools/linguist/lrelease/main.cpp52
-rw-r--r--tools/linguist/lupdate/cpp.cpp83
-rw-r--r--tools/linguist/lupdate/java.cpp29
-rw-r--r--tools/linguist/lupdate/main.cpp32
-rw-r--r--tools/linguist/lupdate/merge.cpp18
-rw-r--r--tools/linguist/lupdate/qdeclarative.cpp166
-rw-r--r--tools/linguist/lupdate/qscript.cpp52
-rw-r--r--tools/linguist/lupdate/qscript.g51
-rw-r--r--tools/linguist/lupdate/ui.cpp19
11 files changed, 381 insertions, 149 deletions
diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp
index 094406c..d691548 100644
--- a/tools/linguist/lconvert/main.cpp
+++ b/tools/linguist/lconvert/main.cpp
@@ -45,11 +45,17 @@
#include <QtCore/QDebug>
#include <QtCore/QString>
#include <QtCore/QStringList>
+#include <QtCore/QTranslator>
+#include <QtCore/QLibraryInfo>
#include <iostream>
QT_USE_NAMESPACE
+class LC {
+ Q_DECLARE_TR_FUNCTIONS(LConvert)
+};
+
static int usage(const QStringList &args)
{
Q_UNUSED(args);
@@ -59,7 +65,7 @@ static int usage(const QStringList &args)
foreach (Translator::FileFormat format, Translator::registeredFileFormats())
loaders += line.arg(format.extension, -5).arg(format.description);
- std::cerr << qPrintable(QString(QLatin1String("\nUsage:\n"
+ std::cerr << qPrintable(LC::tr("\nUsage:\n"
" lconvert [options] <infile> [<infile>...]\n\n"
"lconvert is part of Qt's Linguist tool chain. It can be used as a\n"
"stand-alone tool to convert and filter translation data files.\n"
@@ -121,7 +127,7 @@ static int usage(const QStringList &args)
" 0 on success\n"
" 1 on command line parse failures\n"
" 2 on read failures\n"
- " 3 on write failures\n")).arg(loaders));
+ " 3 on write failures\n").arg(loaders));
return 1;
}
@@ -134,8 +140,17 @@ struct File
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
- QStringList args = app.arguments();
+ QTranslator translator;
+ QTranslator qtTranslator;
+ QString sysLocale = QLocale::system().name();
+ QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
+ if (translator.load(QLatin1String("linguist_") + sysLocale, resourceDir)
+ && qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)) {
+ app.installTranslator(&translator);
+ app.installTranslator(&qtTranslator);
+ }
+ QStringList args = app.arguments();
QList<File> inFiles;
QString inFormat(QLatin1String("auto"));
QString outFileName;
diff --git a/tools/linguist/linguist/phrase.cpp b/tools/linguist/linguist/phrase.cpp
index 254daf4..709ec35 100644
--- a/tools/linguist/linguist/phrase.cpp
+++ b/tools/linguist/linguist/phrase.cpp
@@ -188,10 +188,9 @@ bool QphHandler::characters(const QString &ch)
bool QphHandler::fatalError(const QXmlParseException &exception)
{
if (ferrorCount++ == 0) {
- QString msg;
- msg.sprintf("Parse error at line %d, column %d (%s).",
- exception.lineNumber(), exception.columnNumber(),
- exception.message().toLatin1().constData());
+ QString msg = PhraseBook::tr("Parse error at line %1, column %2 (%3).")
+ .arg(exception.lineNumber()).arg(exception.columnNumber())
+ .arg(exception.message());
QMessageBox::information(0,
QObject::tr("Qt Linguist"), msg);
}
diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp
index b5cff90..19377ef 100644
--- a/tools/linguist/lrelease/main.cpp
+++ b/tools/linguist/lrelease/main.cpp
@@ -65,6 +65,17 @@ static void initBinaryDir(
const char *argv0
#endif
);
+
+struct LR {
+ static inline QString tr(const char *sourceText, const char *comment = 0)
+ {
+ return QCoreApplication::translate("LRelease", sourceText, comment);
+ }
+};
+#else
+class LR {
+ Q_DECLARE_TR_FUNCTIONS(LRelease)
+};
#endif
static void printOut(const QString & out)
@@ -75,7 +86,7 @@ static void printOut(const QString & out)
static void printUsage()
{
- printOut(QCoreApplication::tr(
+ printOut(LR::tr(
"Usage:\n"
" lrelease [options] project-file\n"
" lrelease [options] ts-files [-qm qm-file]\n\n"
@@ -108,7 +119,7 @@ static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbo
ConversionData cd;
bool ok = tor.load(tsFileName, cd, QLatin1String("auto"));
if (!ok) {
- std::cerr << "lrelease error: " << qPrintable(cd.error());
+ std::cerr << qPrintable(LR::tr("lrelease error: %1").arg(cd.error()));
} else {
if (!cd.errors().isEmpty())
printOut(cd.error());
@@ -123,17 +134,17 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName,
tor.reportDuplicates(tor.resolveDuplicates(), qmFileName, cd.isVerbose());
if (cd.isVerbose())
- printOut(QCoreApplication::tr( "Updating '%1'...\n").arg(qmFileName));
+ printOut(LR::tr("Updating '%1'...\n").arg(qmFileName));
if (removeIdentical) {
if (cd.isVerbose())
- printOut(QCoreApplication::tr( "Removing translations equal to source text in '%1'...\n").arg(qmFileName));
+ printOut(LR::tr("Removing translations equal to source text in '%1'...\n").arg(qmFileName));
tor.stripIdenticalSourceTranslations();
}
QFile file(qmFileName);
if (!file.open(QIODevice::WriteOnly)) {
- std::cerr << "lrelease error: cannot create '" << qPrintable(qmFileName)
- << "': " << qPrintable(file.errorString()) << std::endl;
+ std::cerr << qPrintable(LR::tr("lrelease error: cannot create '%1': %2\n")
+ .arg(qmFileName, file.errorString()));
return false;
}
@@ -142,8 +153,8 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName,
file.close();
if (!ok) {
- std::cerr << "lrelease error: cannot save '" << qPrintable(qmFileName)
- << "': " << qPrintable(cd.error());
+ std::cerr << qPrintable(LR::tr("lrelease error: cannot save '%1': %2")
+ .arg(qmFileName, cd.error()));
} else if (!cd.errors().isEmpty()) {
printOut(cd.error());
}
@@ -181,8 +192,14 @@ int main(int argc, char **argv)
#else
QCoreApplication app(argc, argv);
QTranslator translator;
- if (translator.load(QLatin1String("lrelease_") + QLocale::system().name()))
+ QTranslator qtTranslator;
+ QString sysLocale = QLocale::system().name();
+ QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
+ if (translator.load(QLatin1String("linguist_") + sysLocale, resourceDir)
+ && qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)) {
app.installTranslator(&translator);
+ app.installTranslator(&qtTranslator);
+ }
#endif
ConversionData cd;
@@ -221,7 +238,7 @@ int main(int argc, char **argv)
cd.m_verbose = true;
continue;
} else if (!strcmp(argv[i], "-version")) {
- printOut(QCoreApplication::tr( "lrelease version %1\n").arg(QLatin1String(QT_VERSION_STR)) );
+ printOut(LR::tr("lrelease version %1\n").arg(QLatin1String(QT_VERSION_STR)));
return 0;
} else if (!strcmp(argv[i], "-qm")) {
if (i == argc - 1) {
@@ -255,20 +272,23 @@ int main(int argc, char **argv)
visitor.setVerbose(cd.isVerbose());
if (!visitor.queryProFile(&pro)) {
- std::cerr << "lrelease error: cannot read project file '"
- << qPrintable(inputFile) << "'.\n";
+ std::cerr << qPrintable(LR::tr(
+ "lrelease error: cannot read project file '%1'.\n")
+ .arg(inputFile));
continue;
}
if (!visitor.accept(&pro)) {
- std::cerr << "lrelease error: cannot process project file '"
- << qPrintable(inputFile) << "'.\n";
+ std::cerr << qPrintable(LR::tr(
+ "lrelease error: cannot process project file '%1'.\n")
+ .arg(inputFile));
continue;
}
QStringList translations = visitor.values(QLatin1String("TRANSLATIONS"));
if (translations.isEmpty()) {
- std::cerr << "lrelease warning: Met no 'TRANSLATIONS' entry in project file '"
- << qPrintable(inputFile) << "'\n";
+ std::cerr << qPrintable(LR::tr(
+ "lrelease warning: Met no 'TRANSLATIONS' entry in project file '%1'\n")
+ .arg(inputFile));
} else {
QDir proDir(fi.absolutePath());
foreach (const QString &trans, translations)
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp
index bc9bb26..970d44b 100644
--- a/tools/linguist/lupdate/cpp.cpp
+++ b/tools/linguist/lupdate/cpp.cpp
@@ -50,6 +50,7 @@
#include <QtCore/QString>
#include <QtCore/QTextCodec>
#include <QtCore/QTextStream>
+#include <QtCore/QCoreApplication>
#include <iostream>
@@ -57,6 +58,10 @@
QT_BEGIN_NAMESPACE
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate)
+};
+
/* qmake ignore Q_OBJECT */
static QString MagicComment(QLatin1String("TRANSLATOR"));
@@ -624,8 +629,8 @@ uint CppParser::getToken()
|| yyBraceDepth != is.braceDepth1st
|| yyParenDepth != is.parenDepth1st)
yyMsg(is.elseLine)
- << "Parenthesis/bracket/brace mismatch between "
- "#if and #else branches; using #if branch\n";
+ << qPrintable(LU::tr("Parenthesis/bracket/brace mismatch between "
+ "#if and #else branches; using #if branch\n"));
} else {
is.bracketDepth1st = yyBracketDepth;
is.braceDepth1st = yyBraceDepth;
@@ -647,8 +652,8 @@ uint CppParser::getToken()
|| yyBraceDepth != is.braceDepth1st
|| yyParenDepth != is.parenDepth1st)
yyMsg(is.elseLine)
- << "Parenthesis/brace mismatch between "
- "#if and #else branches; using #if branch\n";
+ << qPrintable(LU::tr("Parenthesis/brace mismatch between "
+ "#if and #else branches; using #if branch\n"));
yyBracketDepth = is.bracketDepth1st;
yyBraceDepth = is.braceDepth1st;
yyParenDepth = is.parenDepth1st;
@@ -674,7 +679,7 @@ uint CppParser::getToken()
forever {
yyCh = getChar();
if (yyCh == EOF) {
- yyMsg() << "Unterminated C++ comment\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n"));
break;
}
@@ -804,7 +809,7 @@ uint CppParser::getToken()
forever {
yyCh = getChar();
if (yyCh == EOF) {
- yyMsg() << "Unterminated C++ comment\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n"));
break;
}
*ptr++ = yyCh;
@@ -837,7 +842,7 @@ uint CppParser::getToken()
yyWord.resize(ptr - (ushort *)yyWord.unicode());
if (yyCh != '"')
- yyMsg() << "Unterminated C++ string\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated C++ string\n"));
else
yyCh = getChar();
return Tok_String;
@@ -894,8 +899,8 @@ uint CppParser::getToken()
if (yyBraceDepth == yyMinBraceDepth) {
if (!inDefine)
yyMsg(yyCurLineNo)
- << "Excess closing brace in C++ code"
- " (or abuse of the C++ preprocessor)\n";
+ << qPrintable(LU::tr("Excess closing brace in C++ code"
+ " (or abuse of the C++ preprocessor)\n"));
// Avoid things getting messed up even more
yyCh = getChar();
return Tok_Semicolon;
@@ -912,8 +917,8 @@ uint CppParser::getToken()
case ')':
if (yyParenDepth == 0)
yyMsg(yyCurLineNo)
- << "Excess closing parenthesis in C++ code"
- " (or abuse of the C++ preprocessor)\n";
+ << qPrintable(LU::tr("Excess closing parenthesis in C++ code"
+ " (or abuse of the C++ preprocessor)\n"));
else
yyParenDepth--;
yyCh = getChar();
@@ -927,8 +932,8 @@ uint CppParser::getToken()
case ']':
if (yyBracketDepth == 0)
yyMsg(yyCurLineNo)
- << "Excess closing bracket in C++ code"
- " (or abuse of the C++ preprocessor)\n";
+ << qPrintable(LU::tr("Excess closing bracket in C++ code"
+ " (or abuse of the C++ preprocessor)\n"));
else
yyBracketDepth--;
yyCh = getChar();
@@ -1296,7 +1301,7 @@ void CppParser::processInclude(const QString &file, ConversionData &cd,
QString cleanFile = QDir::cleanPath(file);
if (inclusions.contains(cleanFile)) {
- yyMsg() << "circular inclusion of " << qPrintable(cleanFile) << std::endl;
+ yyMsg() << qPrintable(LU::tr("circular inclusion of %1\n").arg(cleanFile));
return;
}
@@ -1320,9 +1325,7 @@ void CppParser::processInclude(const QString &file, ConversionData &cd,
QFile f(cleanFile);
if (!f.open(QIODevice::ReadOnly)) {
- yyMsg()
- << "Cannot open " << qPrintable(cleanFile) << ": "
- << qPrintable(f.errorString()) << std::endl;
+ yyMsg() << qPrintable(LU::tr("Cannot open %1: %2\n").arg(cleanFile, f.errorString()));
return;
}
@@ -1766,7 +1769,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (!tor)
goto case_default;
if (!sourcetext.isEmpty())
- yyMsg() << "//% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n";
+ yyMsg() << qPrintable(LU::tr("//% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n"));
utf8 = (yyTok == Tok_trUtf8);
line = yyLineNo;
yyTok = getToken();
@@ -1787,9 +1790,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
QStringList unresolved;
if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) {
functionContextUnresolved = unresolved.join(strColons);
- yyMsg() << "Qualifying with unknown namespace/class "
- << qPrintable(stringifyNamespace(functionContext)) << "::"
- << qPrintable(unresolved.first()) << std::endl;
+ yyMsg() << qPrintable(LU::tr("Qualifying with unknown namespace/class %1::%2\n")
+ .arg(stringifyNamespace(functionContext)).arg(unresolved.first()));
}
pendingContext.clear();
}
@@ -1797,7 +1799,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (functionContextUnresolved.isEmpty()) {
int idx = functionContext.length();
if (idx < 2) {
- yyMsg() << "tr() cannot be called without context\n";
+ yyMsg() << qPrintable(LU::tr("tr() cannot be called without context\n"));
break;
}
Namespace *fctx;
@@ -1806,8 +1808,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
context = stringifyNamespace(functionContext);
fctx = findNamespace(functionContext)->classDef;
if (!fctx->complained) {
- yyMsg() << "Class '" << qPrintable(context)
- << "' lacks Q_OBJECT macro\n";
+ yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n")
+ .arg(context));
fctx->complained = true;
}
goto gotctx;
@@ -1835,8 +1837,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
int last = prefix.lastIndexOf(strColons);
QString className = prefix.mid(last == -1 ? 0 : last + 2);
if (!className.isEmpty() && className == functionName) {
- yyMsg() << "It is not recommended to call tr() from within a constructor '"
- << qPrintable(className) << "::" << qPrintable(functionName) << "'\n";
+ yyMsg() << qPrintable(LU::tr("It is not recommended to call tr() from within a constructor '%1::%2'\n")
+ .arg(className).arg(functionName));
}
#endif
prefix.chop(2);
@@ -1851,7 +1853,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
context = fctx->trQualification;
}
if (!fctx->hasTrFunctions && !fctx->complained) {
- yyMsg() << "Class '" << qPrintable(context) << "' lacks Q_OBJECT macro\n";
+ yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n").arg(context));
fctx->complained = true;
}
} else {
@@ -1873,7 +1875,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (!tor)
goto case_default;
if (!sourcetext.isEmpty())
- yyMsg() << "//% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n";
+ yyMsg() << qPrintable(LU::tr("//% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n"));
utf8 = (yyTok == Tok_translateUtf8);
line = yyLineNo;
yyTok = getToken();
@@ -1928,7 +1930,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (!tor)
goto case_default;
if (!msgid.isEmpty())
- yyMsg() << "//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n";
+ yyMsg() << qPrintable(LU::tr("//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n"));
//utf8 = false; // Maybe use //%% or something like that
line = yyLineNo;
yyTok = getToken();
@@ -1995,13 +1997,13 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (isspace(c))
continue;
if (c != '"') {
- yyMsg() << "Unexpected character in meta string\n";
+ yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n"));
break;
}
forever {
if (p >= yyWord.length()) {
whoops:
- yyMsg() << "Unterminated meta string\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated meta string\n"));
break;
}
c = yyWord.unicode()[p++].unicode();
@@ -2054,7 +2056,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
case Tok_Arrow:
yyTok = getToken();
if (yyTok == Tok_tr || yyTok == Tok_trUtf8)
- yyMsg() << "Cannot invoke tr() like this\n";
+ yyMsg() << qPrintable(LU::tr("Cannot invoke tr() like this\n"));
break;
case Tok_ColonColon:
if (yyBraceDepth == namespaceDepths.count() && yyParenDepth == 0 && !yyTokColonSeen)
@@ -2087,7 +2089,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
prospectiveContext.clear();
prefix.clear();
if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
- yyMsg() << "Discarding unconsumed meta data\n";
+ yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
sourcetext.clear();
extracomment.clear();
msgid.clear();
@@ -2127,16 +2129,16 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (yyBraceDepth != 0)
yyMsg(yyBraceLineNo)
- << "Unbalanced opening brace in C++ code"
- " (or abuse of the C++ preprocessor)\n";
+ << qPrintable(LU::tr("Unbalanced opening brace in C++ code"
+ " (or abuse of the C++ preprocessor)\n"));
else if (yyParenDepth != 0)
yyMsg(yyParenLineNo)
- << "Unbalanced opening parenthesis in C++ code"
- " (or abuse of the C++ preprocessor)\n";
+ << qPrintable(LU::tr("Unbalanced opening parenthesis in C++ code"
+ " (or abuse of the C++ preprocessor)\n"));
else if (yyBracketDepth != 0)
yyMsg(yyBracketLineNo)
- << "Unbalanced opening bracket in C++ code"
- " (or abuse of the C++ preprocessor)\n";
+ << qPrintable(LU::tr("Unbalanced opening bracket in C++ code"
+ " (or abuse of the C++ preprocessor)\n"));
}
const ParseResults *CppParser::recordResults(bool isHeader)
@@ -2197,8 +2199,7 @@ void loadCPP(Translator &translator, const QStringList &filenames, ConversionDat
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
- cd.appendError(QString::fromLatin1("Cannot open %1: %2")
- .arg(filename, file.errorString()));
+ cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
continue;
}
diff --git a/tools/linguist/lupdate/java.cpp b/tools/linguist/lupdate/java.cpp
index dc66e2b..165b6a3 100644
--- a/tools/linguist/lupdate/java.cpp
+++ b/tools/linguist/lupdate/java.cpp
@@ -50,6 +50,7 @@
#include <QtCore/QStack>
#include <QtCore/QString>
#include <QtCore/QTextCodec>
+#include <QtCore/QCoreApplication>
#include <iostream>
@@ -57,6 +58,10 @@
QT_BEGIN_NAMESPACE
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate)
+};
+
enum { Tok_Eof, Tok_class, Tok_return, Tok_tr,
Tok_translate, Tok_Ident, Tok_Package,
Tok_Comment, Tok_String, Tok_Colon, Tok_Dot,
@@ -196,7 +201,7 @@ static int getToken()
while ( !metAsterSlash ) {
yyCh = getChar();
if ( yyCh == EOF ) {
- yyMsg() << "Unterminated Java comment.\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated Java comment.\n"));
return Tok_Comment;
}
@@ -232,7 +237,7 @@ static int getToken()
else {
int sub(yyCh.toLower().toAscii() - 87);
if( sub > 15 || sub < 10) {
- yyMsg() << "Invalid Unicode value.\n";
+ yyMsg() << qPrintable(LU::tr("Invalid Unicode value.\n"));
break;
}
unicode += sub;
@@ -255,7 +260,7 @@ static int getToken()
}
if ( yyCh != QLatin1Char('"') )
- yyMsg() << "Unterminated string.\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated string.\n"));
yyCh = getChar();
@@ -368,8 +373,9 @@ static bool matchString( QString &s )
if (yyTok == Tok_String)
s += yyString;
else {
- yyMsg() << "String used in translation can contain only literals"
- " concatenated with other literals, not expressions or numbers.\n";
+ yyMsg() << qPrintable(LU::tr(
+ "String used in translation can contain only literals"
+ " concatenated with other literals, not expressions or numbers.\n"));
return false;
}
yyTok = getToken();
@@ -477,7 +483,7 @@ static void parse( Translator *tor )
yyScope.push(new Scope(yyIdent, Scope::Clazz, yyLineNo));
}
else {
- yyMsg() << "'class' must be followed by a class name.\n";
+ yyMsg() << qPrintable(LU::tr("'class' must be followed by a class name.\n"));
break;
}
while (!match(Tok_LeftBrace)) {
@@ -549,7 +555,7 @@ static void parse( Translator *tor )
case Tok_RightBrace:
if ( yyScope.isEmpty() ) {
- yyMsg() << "Excess closing brace.\n";
+ yyMsg() << qPrintable(LU::tr("Excess closing brace.\n"));
}
else
delete (yyScope.pop());
@@ -578,7 +584,7 @@ static void parse( Translator *tor )
yyPackage.append(QLatin1String("."));
break;
default:
- yyMsg() << "'package' must be followed by package name.\n";
+ yyMsg() << qPrintable(LU::tr("'package' must be followed by package name.\n"));
break;
}
yyTok = getToken();
@@ -591,9 +597,9 @@ static void parse( Translator *tor )
}
if ( !yyScope.isEmpty() )
- yyMsg(yyScope.top()->line) << "Unbalanced opening brace.\n";
+ yyMsg(yyScope.top()->line) << qPrintable(LU::tr("Unbalanced opening brace.\n"));
else if ( yyParenDepth != 0 )
- yyMsg(yyParenLineNo) << "Unbalanced opening parenthesis.\n";
+ yyMsg(yyParenLineNo) << qPrintable(LU::tr("Unbalanced opening parenthesis.\n"));
}
@@ -601,8 +607,7 @@ bool loadJava(Translator &translator, const QString &filename, ConversionData &c
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
- cd.appendError(QString::fromLatin1("Cannot open %1: %2")
- .arg(filename, file.errorString()));
+ cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
return false;
}
diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp
index a575192..d96e205 100644
--- a/tools/linguist/lupdate/main.cpp
+++ b/tools/linguist/lupdate/main.cpp
@@ -52,6 +52,8 @@
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QTextCodec>
+#include <QtCore/QTranslator>
+#include <QtCore/QLibraryInfo>
#include <iostream>
@@ -79,7 +81,7 @@ static void recursiveFileInfoList(const QDir &dir,
static void printUsage()
{
- printOut(QObject::tr(
+ printOut(LU::tr(
"Usage:\n"
" lupdate [options] [project-file]...\n"
" lupdate [options] [source-file|path|@lst-file]... -ts ts-files|@lst-file\n\n"
@@ -186,7 +188,7 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
else if (options & AbsoluteLocations)
tor.setLocationsType(Translator::AbsoluteLocations);
if (options & Verbose)
- printOut(QObject::tr("Updating '%1'...\n").arg(fn));
+ printOut(LU::tr("Updating '%1'...\n").arg(fn));
UpdateOptions theseOptions = options;
if (tor.locationsType() == Translator::NoLocations) // Could be set from file
@@ -201,7 +203,7 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
}
if (options & PluralOnly) {
if (options & Verbose)
- printOut(QObject::tr("Stripping non plural forms in '%1'...\n").arg(fn));
+ printOut(LU::tr("Stripping non plural forms in '%1'...\n").arg(fn));
out.stripNonPluralForms();
}
if (options & NoObsolete)
@@ -359,12 +361,12 @@ static void processProjects(
if (visitor.contains(QLatin1String("TRANSLATIONS"))) {
if (parentTor) {
if (topLevel) {
- std::cerr << "lupdate warning: TS files from command line "
- "will override TRANSLATIONS in " << qPrintable(proFile) << ".\n";
+ std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line "
+ "will override TRANSLATIONS in %1.\n").arg(proFile));
goto noTrans;
} else if (nestComplain) {
- std::cerr << "lupdate warning: TS files from command line "
- "prevent recursing into " << qPrintable(proFile) << ".\n";
+ std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line "
+ "prevent recursing into %1.\n").arg(proFile));
continue;
}
}
@@ -395,8 +397,8 @@ static void processProjects(
noTrans:
if (!parentTor) {
if (topLevel)
- std::cerr << "lupdate warning: no TS files specified. Only diagnostics "
- "will be produced for '" << qPrintable(proFile) << "'.\n";
+ std::cerr << qPrintable(LU::tr("lupdate warning: no TS files specified. Only diagnostics "
+ "will be produced for '%1'.\n").arg(proFile));
Translator tor;
processProject(nestComplain, pfi, visitor, options, codecForSource,
targetLanguage, sourceLanguage, &tor, fail);
@@ -410,6 +412,16 @@ static void processProjects(
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
+ QTranslator translator;
+ QTranslator qtTranslator;
+ QString sysLocale = QLocale::system().name();
+ QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
+ if (translator.load(QLatin1String("linguist_") + sysLocale, resourceDir)
+ && qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)) {
+ app.installTranslator(&translator);
+ app.installTranslator(&qtTranslator);
+ }
+
m_defaultExtensions = QLatin1String("java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml");
QStringList args = app.arguments();
@@ -613,7 +625,7 @@ int main(int argc, char **argv)
proFiles << file;
} else if (fi.isDir()) {
if (options & Verbose)
- printOut(QObject::tr("Scanning directory '%1'...\n").arg(file));
+ printOut(LU::tr("Scanning directory '%1'...\n").arg(file));
QDir dir = QDir(fi.filePath());
projectRoots.insert(dir.absolutePath() + QLatin1Char('/'));
if (extensionsNameFilters.isEmpty()) {
diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp
index fffdf9b..87c150c 100644
--- a/tools/linguist/lupdate/merge.cpp
+++ b/tools/linguist/lupdate/merge.cpp
@@ -44,15 +44,19 @@
#include "simtexth.h"
#include "translator.h"
+#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QMap>
#include <QtCore/QStringList>
#include <QtCore/QTextCodec>
#include <QtCore/QVector>
-
QT_BEGIN_NAMESPACE
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate)
+};
+
static bool isDigitFriendly(QChar c)
{
return c.isPunct() || c.isSpace();
@@ -485,24 +489,24 @@ Translator merge(const Translator &tor, const Translator &virginTor,
if (options & Verbose) {
int totalFound = neww + known;
- err += QObject::tr(" Found %n source text(s) (%1 new and %2 already existing)\n", 0, totalFound).arg(neww).arg(known);
+ err += LU::tr(" Found %n source text(s) (%1 new and %2 already existing)\n", 0, totalFound).arg(neww).arg(known);
if (obsoleted) {
if (options & NoObsolete) {
- err += QObject::tr(" Removed %n obsolete entries\n", 0, obsoleted);
+ err += LU::tr(" Removed %n obsolete entries\n", 0, obsoleted);
} else {
- err += QObject::tr(" Kept %n obsolete entries\n", 0, obsoleted);
+ err += LU::tr(" Kept %n obsolete entries\n", 0, obsoleted);
}
}
if (sameNumberHeuristicCount)
- err += QObject::tr(" Number heuristic provided %n translation(s)\n",
+ err += LU::tr(" Number heuristic provided %n translation(s)\n",
0, sameNumberHeuristicCount);
if (sameTextHeuristicCount)
- err += QObject::tr(" Same-text heuristic provided %n translation(s)\n",
+ err += LU::tr(" Same-text heuristic provided %n translation(s)\n",
0, sameTextHeuristicCount);
if (similarTextHeuristicCount)
- err += QObject::tr(" Similar-text heuristic provided %n translation(s)\n",
+ err += LU::tr(" Similar-text heuristic provided %n translation(s)\n",
0, similarTextHeuristicCount);
}
return outTor;
diff --git a/tools/linguist/lupdate/qdeclarative.cpp b/tools/linguist/lupdate/qdeclarative.cpp
index 2377416..01b9a1d 100644
--- a/tools/linguist/lupdate/qdeclarative.cpp
+++ b/tools/linguist/lupdate/qdeclarative.cpp
@@ -65,8 +65,26 @@
QT_BEGIN_NAMESPACE
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate)
+};
+
using namespace QDeclarativeJS;
+class Comment
+{
+public:
+ Comment() : lastLine(-1) {}
+ QString extracomment;
+ QString msgid;
+ TranslatorMessage::ExtraData extra;
+ QString sourcetext;
+ int lastLine;
+
+ bool isValid() const
+ { return !extracomment.isEmpty() || !msgid.isEmpty() || !sourcetext.isEmpty() || !extra.isEmpty(); }
+};
+
class FindTrCalls: protected AST::Visitor
{
public:
@@ -78,6 +96,8 @@ public:
accept(node);
}
+ QList<Comment> comments;
+
protected:
using AST::Visitor::visit;
using AST::Visitor::endVisit;
@@ -114,10 +134,23 @@ protected:
plural = true;
}
+ QString id;
+ QString extracomment;
+ TranslatorMessage::ExtraData extra;
+ Comment scomment = findComment(node->firstSourceLocation().startLine);
+ if (scomment.isValid()) {
+ extracomment = scomment.extracomment;
+ extra = scomment.extra;
+ id = scomment.msgid;
+ }
+
TranslatorMessage msg(m_component, source,
comment, QString(), m_fileName,
node->firstSourceLocation().startLine, QStringList(),
TranslatorMessage::Unfinished, plural);
+ msg.setExtraComment(extracomment.simplified());
+ msg.setId(id);
+ msg.setExtras(extra);
m_translator->extend(msg);
}
} else if (idExpr->name->asString() == QLatin1String("qsTranslate") ||
@@ -140,6 +173,17 @@ protected:
}
if (!literal && m_bSource.isEmpty())
return;
+
+ QString id;
+ QString extracomment;
+ TranslatorMessage::ExtraData extra;
+ Comment scomment = findComment(node->firstSourceLocation().startLine);
+ if (scomment.isValid()) {
+ extracomment = scomment.extracomment;
+ extra = scomment.extra;
+ id = scomment.msgid;
+ }
+
source = literal ? literal->value->asString() : m_bSource;
AST::ArgumentList *commentNode = sourceNode->next;
if (commentNode && AST::cast<AST::StringLiteral *>(commentNode->expression)) {
@@ -155,15 +199,48 @@ protected:
comment, QString(), m_fileName,
node->firstSourceLocation().startLine, QStringList(),
TranslatorMessage::Unfinished, plural);
+ msg.setExtraComment(extracomment.simplified());
+ msg.setId(id);
+ msg.setExtras(extra);
m_translator->extend(msg);
}
+ } else if (idExpr->name->asString() == QLatin1String("qsTrId") ||
+ idExpr->name->asString() == QLatin1String("QT_TRID_NOOP")) {
+ if (!node->arguments)
+ return;
+ AST::StringLiteral *literal = AST::cast<AST::StringLiteral *>(node->arguments->expression);
+ if (literal) {
+
+ QString extracomment;
+ QString sourcetext;
+ TranslatorMessage::ExtraData extra;
+ Comment comment = findComment(node->firstSourceLocation().startLine);
+ if (comment.isValid()) {
+ extracomment = comment.extracomment;
+ sourcetext = comment.sourcetext;
+ extra = comment.extra;
+ }
+
+ const QString id = literal->value->asString();
+ bool plural = node->arguments->next;
+
+ TranslatorMessage msg(QString(), QString(),
+ QString(), QString(), m_fileName,
+ node->firstSourceLocation().startLine, QStringList(),
+ TranslatorMessage::Unfinished, plural);
+ msg.setExtraComment(extracomment.simplified());
+ msg.setId(id);
+ msg.setExtras(extra);
+ m_translator->extend(msg);
+ }
}
}
}
private:
- bool createString(AST::BinaryExpression *b) {
+ bool createString(AST::BinaryExpression *b)
+ {
if (!b || b->op != 0)
return false;
AST::BinaryExpression *l = AST::cast<AST::BinaryExpression *>(b->left);
@@ -187,6 +264,23 @@ private:
return true;
}
+ Comment findComment(int loc)
+ {
+ if (comments.isEmpty())
+ return Comment();
+
+ int i = 0;
+ int commentLoc = comments.at(i).lastLine;
+ while (commentLoc <= loc) {
+ if (commentLoc == loc)
+ return comments.at(i);
+ if (i == comments.count()-1)
+ break;
+ commentLoc = comments.at(++i).lastLine;
+ }
+ return Comment();
+ }
+
Translator *m_translator;
QString m_fileName;
QString m_component;
@@ -236,13 +330,60 @@ QString createErrorString(const QString &filename, const QString &code, Parser &
return errorString;
}
+bool processComment(const QChar *chars, int length, Comment &comment)
+{
+ // Try to match the logic of the QtScript parser.
+ if (!length)
+ return comment.isValid();
+ if (*chars == QLatin1Char(':') && chars[1].isSpace()) {
+ comment.extracomment += QString(chars+1, length-1);
+ } else if (*chars == QLatin1Char('=') && chars[1].isSpace()) {
+ comment.msgid = QString(chars+2, length-2).simplified();
+ } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) {
+ QString text = QString(chars+2, length-2).trimmed();
+ int k = text.indexOf(QLatin1Char(' '));
+ if (k > -1)
+ comment.extra.insert(text.left(k), text.mid(k + 1).trimmed());
+ } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) {
+ comment.sourcetext.reserve(comment.sourcetext.length() + length-2);
+ ushort *ptr = (ushort *)comment.sourcetext.data() + comment.sourcetext.length();
+ int p = 2, c;
+ forever {
+ if (p >= length)
+ break;
+ c = chars[p++].unicode();
+ if (isspace(c))
+ continue;
+ if (c != '"')
+ break;
+ forever {
+ if (p >= length)
+ break;
+ c = chars[p++].unicode();
+ if (c == '"')
+ break;
+ if (c == '\\') {
+ if (p >= length)
+ break;
+ c = chars[p++].unicode();
+ if (c == '\n')
+ break;
+ *ptr++ = '\\';
+ }
+ *ptr++ = c;
+ }
+ }
+ comment.sourcetext.resize(ptr - (ushort *)comment.sourcetext.data());
+ }
+ return comment.isValid();
+}
+
bool loadQml(Translator &translator, const QString &filename, ConversionData &cd)
{
cd.m_sourceFileName = filename;
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
- cd.appendError(QString::fromLatin1("Cannot open %1: %2")
- .arg(filename, file.errorString()));
+ cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
return false;
}
@@ -260,6 +401,25 @@ bool loadQml(Translator &translator, const QString &filename, ConversionData &cd
if (parser.parse()) {
FindTrCalls trCalls;
+
+ // build up a list of comments that contain translation information.
+ for (int i = 0; i < driver.comments().size(); ++i) {
+ AST::SourceLocation loc = driver.comments().at(i);
+ QString commentStr = code.mid(loc.offset, loc.length);
+
+ if (trCalls.comments.isEmpty() || trCalls.comments.last().lastLine != int(loc.startLine)) {
+ Comment comment;
+ comment.lastLine = loc.startLine+1;
+ if (processComment(commentStr.constData(), commentStr.length(), comment))
+ trCalls.comments.append(comment);
+ } else {
+ Comment &lastComment = trCalls.comments.last();
+ lastComment.lastLine += 1;
+ processComment(commentStr.constData(), commentStr.length(), lastComment);
+ }
+ }
+
+ //find all tr calls in the code
trCalls(&translator, filename, parser.ast());
} else {
QString error = createErrorString(filename, code, parser);
diff --git a/tools/linguist/lupdate/qscript.cpp b/tools/linguist/lupdate/qscript.cpp
index 7ca0987..5323022 100644
--- a/tools/linguist/lupdate/qscript.cpp
+++ b/tools/linguist/lupdate/qscript.cpp
@@ -47,6 +47,7 @@
#include <translator.h>
+#include <QtCore/QCoreApplication>
#include <QtCore/qdebug.h>
#include <QtCore/qnumeric.h>
#include <QtCore/qstring.h>
@@ -62,6 +63,10 @@
QT_BEGIN_NAMESPACE
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate)
+};
+
class QScriptGrammar
{
public:
@@ -1486,7 +1491,7 @@ int QScript::Lexer::lex()
else {
setDone(Bad);
err = IllegalCharacter;
- errmsg = QLatin1String("Illegal character");
+ errmsg = LU::tr("Illegal character");
}
}
break;
@@ -1497,7 +1502,7 @@ int QScript::Lexer::lex()
} else if (current == 0 || isLineTerminator()) {
setDone(Bad);
err = UnclosedStringLiteral;
- errmsg = QLatin1String("Unclosed string at end of line");
+ errmsg = LU::tr("Unclosed string at end of line");
} else if (current == '\\') {
state = InEscapeSequence;
} else {
@@ -1523,7 +1528,7 @@ int QScript::Lexer::lex()
} else {
setDone(Bad);
err = IllegalEscapeSequence;
- errmsg = QLatin1String("Illegal escape squence");
+ errmsg = LU::tr("Illegal escape squence");
}
} else if (current == 'x')
state = InHexEscape;
@@ -1562,7 +1567,7 @@ int QScript::Lexer::lex()
} else {
setDone(Bad);
err = IllegalUnicodeEscapeSequence;
- errmsg = QLatin1String("Illegal unicode escape sequence");
+ errmsg = LU::tr("Illegal unicode escape sequence");
}
break;
case InSingleLineComment:
@@ -1590,7 +1595,7 @@ int QScript::Lexer::lex()
if (current == 0) {
setDone(Bad);
err = UnclosedComment;
- errmsg = QLatin1String("Unclosed comment at end of file");
+ errmsg = LU::tr("Unclosed comment at end of file");
} else if (isLineTerminator()) {
shiftWindowsLineBreak();
yylineno++;
@@ -1678,7 +1683,7 @@ int QScript::Lexer::lex()
} else {
setDone(Bad);
err = IllegalExponentIndicator;
- errmsg = QLatin1String("Illegal syntax for exponential number");
+ errmsg = LU::tr("Illegal syntax for exponential number");
}
break;
case InExponent:
@@ -1704,7 +1709,7 @@ int QScript::Lexer::lex()
&& isIdentLetter(current)) {
state = Bad;
err = IllegalIdentifier;
- errmsg = QLatin1String("Identifier cannot start with numeric literal");
+ errmsg = LU::tr("Identifier cannot start with numeric literal");
}
// terminate string
@@ -2023,7 +2028,7 @@ bool QScript::Lexer::scanRegExp(RegExpBodyPrefix prefix)
while (1) {
if (isLineTerminator() || current == 0) {
- errmsg = QLatin1String("Unterminated regular expression literal");
+ errmsg = LU::tr("Unterminated regular expression literal");
return false;
}
else if (current != '/' || lastWasEscape == true)
@@ -2267,14 +2272,14 @@ case 66: {
QString name = sym(1).toString();
if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) {
if (!sourcetext.isEmpty())
- yyMsg(identLineNo) << "//% cannot be used with " << qPrintable(name) << "(). Ignoring\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
QVariantList args = sym(2).toList();
if (args.size() < 2) {
- yyMsg(identLineNo) << qPrintable(name) << "() requires at least two arguments.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least two arguments.\n").arg(name));
} else {
if ((args.at(0).type() != QVariant::String)
|| (args.at(1).type() != QVariant::String)) {
- yyMsg(identLineNo) << qPrintable(name) << "(): both arguments must be literal strings.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1(): both arguments must be literal strings.\n").arg(name));
} else {
QString context = args.at(0).toString();
QString text = args.at(1).toString();
@@ -2290,13 +2295,13 @@ case 66: {
extra.clear();
} else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) {
if (!sourcetext.isEmpty())
- yyMsg(identLineNo) << "//% cannot be used with " << qPrintable(name) << "(). Ignoring\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
QVariantList args = sym(2).toList();
if (args.size() < 1) {
- yyMsg(identLineNo) << qPrintable(name) << "() requires at least one argument.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
} else {
if (args.at(0).type() != QVariant::String) {
- yyMsg(identLineNo) << qPrintable(name) << "(): text to translate must be a literal string.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1(): text to translate must be a literal string.\n").arg(name));
} else {
QString context = QFileInfo(fileName()).baseName();
QString text = args.at(0).toString();
@@ -2312,13 +2317,13 @@ case 66: {
extra.clear();
} else if ((name == QLatin1String("qsTrId")) || (name == QLatin1String("QT_TRID_NOOP"))) {
if (!msgid.isEmpty())
- yyMsg(identLineNo) << "//= cannot be used with " << qPrintable(name) << "(). Ignoring\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("//= cannot be used with %1(). Ignoring\n").arg(name));
QVariantList args = sym(2).toList();
if (args.size() < 1) {
- yyMsg(identLineNo) << qPrintable(name) << "() requires at least one argument.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
} else {
if (args.at(0).type() != QVariant::String) {
- yyMsg(identLineNo) << qPrintable(name) << "(): identifier must be a literal string.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1(): identifier must be a literal string.\n").arg(name));
} else {
msgid = args.at(0).toString();
bool plural = (args.size() > 1);
@@ -2386,7 +2391,7 @@ case 94: {
case 185:
if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
- yyMsg() << "Discarding unconsumed meta data\n";
+ yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
sourcetext.clear();
extracomment.clear();
msgid.clear();
@@ -2448,7 +2453,9 @@ case 94: {
for (int s = 0; s < shifts; ++s)
{
if (first)
- error_message += QLatin1String ("Expected ");
+ //: Beginning of the string that contains
+ //: comma-separated list of expected tokens
+ error_message += LU::tr("Expected ");
else
error_message += QLatin1String (", ");
@@ -2502,13 +2509,13 @@ void QScriptParser::processComment(const QChar *chars, int length)
if (isspace(c))
continue;
if (c != '"') {
- yyMsg() << "Unexpected character in meta string\n";
+ yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n"));
break;
}
forever {
if (p >= length) {
whoops:
- yyMsg() << "Unterminated meta string\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated meta string\n"));
break;
}
c = chars[p++].unicode();
@@ -2534,8 +2541,7 @@ bool loadQScript(Translator &translator, const QString &filename, ConversionData
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
- cd.appendError(QString::fromLatin1("Cannot open %1: %2")
- .arg(filename, file.errorString()));
+ cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
return false;
}
QTextStream ts(&file);
diff --git a/tools/linguist/lupdate/qscript.g b/tools/linguist/lupdate/qscript.g
index e4c2d22..3655f2e 100644
--- a/tools/linguist/lupdate/qscript.g
+++ b/tools/linguist/lupdate/qscript.g
@@ -84,6 +84,7 @@
/.
#include <translator.h>
+#include <QtCore/QCoreApplication>
#include <QtCore/qdebug.h>
#include <QtCore/qnumeric.h>
#include <QtCore/qstring.h>
@@ -99,6 +100,10 @@
QT_BEGIN_NAMESPACE
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate)
+};
+
static void recordMessage(
Translator *tor, const QString &context, const QString &text, const QString &comment,
const QString &extracomment, const QString &msgid, const TranslatorMessage::ExtraData &extra,
@@ -817,7 +822,7 @@ int QScript::Lexer::lex()
else {
setDone(Bad);
err = IllegalCharacter;
- errmsg = QLatin1String("Illegal character");
+ errmsg = LU::tr("Illegal character");
}
}
break;
@@ -828,7 +833,7 @@ int QScript::Lexer::lex()
} else if (current == 0 || isLineTerminator()) {
setDone(Bad);
err = UnclosedStringLiteral;
- errmsg = QLatin1String("Unclosed string at end of line");
+ errmsg = LU::tr("Unclosed string at end of line");
} else if (current == '\\') {
state = InEscapeSequence;
} else {
@@ -854,7 +859,7 @@ int QScript::Lexer::lex()
} else {
setDone(Bad);
err = IllegalEscapeSequence;
- errmsg = QLatin1String("Illegal escape squence");
+ errmsg = LU::tr("Illegal escape squence");
}
} else if (current == 'x')
state = InHexEscape;
@@ -893,7 +898,7 @@ int QScript::Lexer::lex()
} else {
setDone(Bad);
err = IllegalUnicodeEscapeSequence;
- errmsg = QLatin1String("Illegal unicode escape sequence");
+ errmsg = LU::tr("Illegal unicode escape sequence");
}
break;
case InSingleLineComment:
@@ -921,7 +926,7 @@ int QScript::Lexer::lex()
if (current == 0) {
setDone(Bad);
err = UnclosedComment;
- errmsg = QLatin1String("Unclosed comment at end of file");
+ errmsg = LU::tr("Unclosed comment at end of file");
} else if (isLineTerminator()) {
shiftWindowsLineBreak();
yylineno++;
@@ -1009,7 +1014,7 @@ int QScript::Lexer::lex()
} else {
setDone(Bad);
err = IllegalExponentIndicator;
- errmsg = QLatin1String("Illegal syntax for exponential number");
+ errmsg = LU::tr("Illegal syntax for exponential number");
}
break;
case InExponent:
@@ -1035,7 +1040,7 @@ int QScript::Lexer::lex()
&& isIdentLetter(current)) {
state = Bad;
err = IllegalIdentifier;
- errmsg = QLatin1String("Identifier cannot start with numeric literal");
+ errmsg = LU::tr("Identifier cannot start with numeric literal");
}
// terminate string
@@ -1354,7 +1359,7 @@ bool QScript::Lexer::scanRegExp(RegExpBodyPrefix prefix)
while (1) {
if (isLineTerminator() || current == 0) {
- errmsg = QLatin1String("Unterminated regular expression literal");
+ errmsg = LU::tr("Unterminated regular expression literal");
return false;
}
else if (current != '/' || lastWasEscape == true)
@@ -1683,14 +1688,14 @@ case $rule_number: {
QString name = sym(1).toString();
if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) {
if (!sourcetext.isEmpty())
- yyMsg(identLineNo) << "//% cannot be used with " << qPrintable(name) << "(). Ignoring\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
QVariantList args = sym(2).toList();
if (args.size() < 2) {
- yyMsg(identLineNo) << qPrintable(name) << "() requires at least two arguments.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least two arguments.\n").arg(name));
} else {
if ((args.at(0).type() != QVariant::String)
|| (args.at(1).type() != QVariant::String)) {
- yyMsg(identLineNo) << qPrintable(name) << "(): both arguments must be literal strings.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1(): both arguments must be literal strings.\n").arg(name));
} else {
QString context = args.at(0).toString();
QString text = args.at(1).toString();
@@ -1706,13 +1711,13 @@ case $rule_number: {
extra.clear();
} else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) {
if (!sourcetext.isEmpty())
- yyMsg(identLineNo) << "//% cannot be used with " << qPrintable(name) << "(). Ignoring\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
QVariantList args = sym(2).toList();
if (args.size() < 1) {
- yyMsg(identLineNo) << qPrintable(name) << "() requires at least one argument.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
} else {
if (args.at(0).type() != QVariant::String) {
- yyMsg(identLineNo) << qPrintable(name) << "(): text to translate must be a literal string.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1(): text to translate must be a literal string.\n").arg(name));
} else {
QString context = QFileInfo(fileName()).baseName();
QString text = args.at(0).toString();
@@ -1728,13 +1733,13 @@ case $rule_number: {
extra.clear();
} else if ((name == QLatin1String("qsTrId")) || (name == QLatin1String("QT_TRID_NOOP"))) {
if (!msgid.isEmpty())
- yyMsg(identLineNo) << "//= cannot be used with " << qPrintable(name) << "(). Ignoring\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("//= cannot be used with %1(). Ignoring\n").arg(name));
QVariantList args = sym(2).toList();
if (args.size() < 1) {
- yyMsg(identLineNo) << qPrintable(name) << "() requires at least one argument.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
} else {
if (args.at(0).type() != QVariant::String) {
- yyMsg(identLineNo) << qPrintable(name) << "(): identifier must be a literal string.\n";
+ yyMsg(identLineNo) << qPrintable(LU::tr("%1(): identifier must be a literal string.\n").arg(name));
} else {
msgid = args.at(0).toString();
bool plural = (args.size() > 1);
@@ -1950,7 +1955,7 @@ Statement: DebuggerStatement ;
/.
case $rule_number:
if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
- yyMsg() << "Discarding unconsumed meta data\n";
+ yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
sourcetext.clear();
extracomment.clear();
msgid.clear();
@@ -2096,6 +2101,9 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
{
if (first)
error_message += QLatin1String ("Expected ");
+ //: Beginning of the string that contains
+ //: comma-separated list of expected tokens
+ error_message += LU::tr("Expected ");
else
error_message += QLatin1String (", ");
@@ -2149,13 +2157,13 @@ void QScriptParser::processComment(const QChar *chars, int length)
if (isspace(c))
continue;
if (c != '"') {
- yyMsg() << "Unexpected character in meta string\n";
+ yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n"));
break;
}
forever {
if (p >= length) {
whoops:
- yyMsg() << "Unterminated meta string\n";
+ yyMsg() << qPrintable(LU::tr("Unterminated meta string\n"));
break;
}
c = chars[p++].unicode();
@@ -2181,8 +2189,7 @@ bool loadQScript(Translator &translator, const QString &filename, ConversionData
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
- cd.appendError(QString::fromLatin1("Cannot open %1: %2")
- .arg(filename, file.errorString()));
+ cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
return false;
}
QTextStream ts(&file);
diff --git a/tools/linguist/lupdate/ui.cpp b/tools/linguist/lupdate/ui.cpp
index 9e22922..797ab1f 100644
--- a/tools/linguist/lupdate/ui.cpp
+++ b/tools/linguist/lupdate/ui.cpp
@@ -43,6 +43,7 @@
#include <translator.h>
+#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QString>
@@ -55,6 +56,10 @@
QT_BEGIN_NAMESPACE
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate)
+};
+
class UiReader : public QXmlDefaultHandler
{
public:
@@ -152,11 +157,10 @@ bool UiReader::characters(const QString &ch)
bool UiReader::fatalError(const QXmlParseException &exception)
{
- QString msg;
- msg.sprintf("XML error: Parse error at line %d, column %d (%s).",
- exception.lineNumber(), exception.columnNumber(),
- exception.message().toLatin1().data());
- m_cd.appendError(msg);
+ QString msg = LU::tr("XML error: Parse error at line %1, column %2 (%3).")
+ .arg(exception.lineNumber()).arg(exception.columnNumber())
+ .arg(exception.message());
+ m_cd.appendError(msg);
return false;
}
@@ -181,8 +185,7 @@ bool loadUI(Translator &translator, const QString &filename, ConversionData &cd)
cd.m_sourceFileName = filename;
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
- cd.appendError(QString::fromLatin1("Cannot open %1: %2")
- .arg(filename, file.errorString()));
+ cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
return false;
}
QXmlInputSource in(&file);
@@ -196,7 +199,7 @@ bool loadUI(Translator &translator, const QString &filename, ConversionData &cd)
reader.setErrorHandler(&handler);
bool result = reader.parse(in);
if (!result)
- cd.appendError(QLatin1String("Parse error in UI file"));
+ cd.appendError(LU::tr("Parse error in UI file"));
reader.setContentHandler(0);
reader.setErrorHandler(0);
return result;