From a5867a413d14f307c0f20b7080840b15bd8743e4 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Tue, 29 Jun 2010 16:56:18 +0200 Subject: Make lupdate's QtScript frontend recognize qsTrId() / QT_TRID_NOOP() Extracting the translation data is only the first step; a separate commit will make the functions available in the QtScript runtime. Task-number: QTBUG-8454 Reviewed-by: Oswald Buddenhagen --- .../linguist/lupdate/testdata/good/parsejs/main.js | 8 +++++++ .../testdata/good/parsejs/project.ts.result | 27 ++++++++++++++++++++++ tools/linguist/lupdate/qscript.cpp | 20 ++++++++++++++++ tools/linguist/lupdate/qscript.g | 20 ++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js b/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js index edd7529..9f61cea 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js +++ b/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js @@ -81,3 +81,11 @@ qsTr("This string has disambiguation", "Disambiguation"); qsTranslate("BarContext", "This string also has disambiguation", "Another disambiguation"); qsTr("This string contains plurals", "", 10); + +qsTrId("qtn_foo_bar"); + +var more_greeting_strings = [ QT_TRID_NOOP("qtn_needle"), QT_TRID_NOOP("qtn_haystack") ]; + +//: qsTrId() with comment, meta-data and plurals. +//~ well-tested True +qsTrId("qtn_bar_baz", 10); diff --git a/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result index d2016de..d03c713 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result @@ -2,6 +2,33 @@ + + + + + + + + + + + + + + + + + + + + qsTrId() with comment, meta-data and plurals. + + + + True + + + BarContext diff --git a/tools/linguist/lupdate/qscript.cpp b/tools/linguist/lupdate/qscript.cpp index dc885a3..7ca0987 100644 --- a/tools/linguist/lupdate/qscript.cpp +++ b/tools/linguist/lupdate/qscript.cpp @@ -2310,6 +2310,26 @@ case 66: { extracomment.clear(); msgid.clear(); 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"; + QVariantList args = sym(2).toList(); + if (args.size() < 1) { + yyMsg(identLineNo) << qPrintable(name) << "() requires at least one argument.\n"; + } else { + if (args.at(0).type() != QVariant::String) { + yyMsg(identLineNo) << qPrintable(name) << "(): identifier must be a literal string.\n"; + } else { + msgid = args.at(0).toString(); + bool plural = (args.size() > 1); + recordMessage(translator, QString(), sourcetext, QString(), extracomment, + msgid, extra, plural, fileName(), identLineNo); + } + } + sourcetext.clear(); + extracomment.clear(); + msgid.clear(); + extra.clear(); } } break; diff --git a/tools/linguist/lupdate/qscript.g b/tools/linguist/lupdate/qscript.g index 200b641..e4c2d22 100644 --- a/tools/linguist/lupdate/qscript.g +++ b/tools/linguist/lupdate/qscript.g @@ -1726,6 +1726,26 @@ case $rule_number: { extracomment.clear(); msgid.clear(); 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"; + QVariantList args = sym(2).toList(); + if (args.size() < 1) { + yyMsg(identLineNo) << qPrintable(name) << "() requires at least one argument.\n"; + } else { + if (args.at(0).type() != QVariant::String) { + yyMsg(identLineNo) << qPrintable(name) << "(): identifier must be a literal string.\n"; + } else { + msgid = args.at(0).toString(); + bool plural = (args.size() > 1); + recordMessage(translator, QString(), sourcetext, QString(), extracomment, + msgid, extra, plural, fileName(), identLineNo); + } + } + sourcetext.clear(); + extracomment.clear(); + msgid.clear(); + extra.clear(); } } break; ./ -- cgit v0.12