From 9a88c8808f8e084e77ee22f907366250f3a0ad2a Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 4 Nov 2009 12:17:03 +0100 Subject: add -markuntranslated option maemo *really* want it, so pushing it in now ... --- tests/auto/linguist/lrelease/tst_lrelease.cpp | 13 ++++++++++ tools/linguist/lrelease/main.cpp | 9 +++++++ tools/linguist/shared/qm.cpp | 35 +++++++++++++++------------ tools/linguist/shared/translator.h | 1 + 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/tests/auto/linguist/lrelease/tst_lrelease.cpp b/tests/auto/linguist/lrelease/tst_lrelease.cpp index 39de8a1..93cb97c 100644 --- a/tests/auto/linguist/lrelease/tst_lrelease.cpp +++ b/tests/auto/linguist/lrelease/tst_lrelease.cpp @@ -60,6 +60,7 @@ private slots: void mixedcodecs(); void compressed(); void idbased(); + void markuntranslated(); void dupes(); private: @@ -210,6 +211,18 @@ void tst_lrelease::idbased() QCOMPARE(qtTrId("untranslated_id"), QString::fromAscii("This has no translation.")); } +void tst_lrelease::markuntranslated() +{ + QVERIFY(!QProcess::execute(binDir + "/lrelease -markuntranslated # -idbased testdata/idbased.ts")); + + QTranslator translator; + QVERIFY(translator.load("testdata/idbased.qm")); + qApp->installTranslator(&translator); + + QCOMPARE(qtTrId("test_id"), QString::fromAscii("This is a test string.")); + QCOMPARE(qtTrId("untranslated_id"), QString::fromAscii("#This has no translation.")); +} + void tst_lrelease::dupes() { QProcess proc; diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp index b32b133..ecaed27 100644 --- a/tools/linguist/lrelease/main.cpp +++ b/tools/linguist/lrelease/main.cpp @@ -79,6 +79,9 @@ static void printUsage() " -removeidentical\n" " If the translated text is the same as\n" " the source text, do not include the message\n" + " -markuntranslated \n" + " If a message has no real translation, use the source text\n" + " prefixed with the given string instead\n" " -silent\n" " Do not explain what is being done\n" " -version\n" @@ -183,6 +186,12 @@ int main(int argc, char **argv) } else if (args[i] == QLatin1String("-nounfinished")) { cd.m_ignoreUnfinished = true; continue; + } else if (args[i] == QLatin1String("-markuntranslated")) { + if (i == argc - 1) { + printUsage(); + return 1; + } + cd.m_unTrPrefix = args[++i]; } else if (args[i] == QLatin1String("-silent")) { cd.m_verbose = false; continue; diff --git a/tools/linguist/shared/qm.cpp b/tools/linguist/shared/qm.cpp index 317a07e..5965aac 100644 --- a/tools/linguist/shared/qm.cpp +++ b/tools/linguist/shared/qm.cpp @@ -172,8 +172,8 @@ public: bool save(QIODevice *iod); - void insert(const TranslatorMessage &msg, bool forceComment); - void insertIdBased(const TranslatorMessage &message); + void insert(const TranslatorMessage &msg, const QStringList &tlns, bool forceComment); + void insertIdBased(const TranslatorMessage &message, const QStringList &tlns); void squeeze(TranslatorSaveMode mode); @@ -186,7 +186,8 @@ private: // on turn should be the same as passed to the actual tr(...) calls QByteArray originalBytes(const QString &str, bool isUtf8) const; - void insertInternal(const TranslatorMessage &message, bool forceComment, bool isUtf8); + void insertInternal(const TranslatorMessage &message, const QStringList &tlns, + bool forceComment, bool isUtf8); static Prefix commonPrefix(const ByteTranslatorMessage &m1, const ByteTranslatorMessage &m2); @@ -413,12 +414,13 @@ void Releaser::squeeze(TranslatorSaveMode mode) } } -void Releaser::insertInternal(const TranslatorMessage &message, bool forceComment, bool isUtf8) +void Releaser::insertInternal(const TranslatorMessage &message, const QStringList &tlns, + bool forceComment, bool isUtf8) { ByteTranslatorMessage bmsg(originalBytes(message.context(), isUtf8), originalBytes(message.sourceText(), isUtf8), originalBytes(message.comment(), isUtf8), - message.translations()); + tlns); if (!forceComment) { ByteTranslatorMessage bmsg2( bmsg.context(), bmsg.sourceText(), QByteArray(""), bmsg.translations()); @@ -430,20 +432,15 @@ void Releaser::insertInternal(const TranslatorMessage &message, bool forceCommen m_messages.insert(bmsg, 0); } -void Releaser::insert(const TranslatorMessage &message, bool forceComment) +void Releaser::insert(const TranslatorMessage &message, const QStringList &tlns, bool forceComment) { - insertInternal(message, forceComment, message.isUtf8()); + insertInternal(message, tlns, forceComment, message.isUtf8()); if (message.isUtf8() && message.isNonUtf8()) - insertInternal(message, forceComment, false); + insertInternal(message, tlns, forceComment, false); } -void Releaser::insertIdBased(const TranslatorMessage &message) +void Releaser::insertIdBased(const TranslatorMessage &message, const QStringList &tlns) { - QStringList tlns = message.translations(); - if (message.type() == TranslatorMessage::Unfinished) - for (int i = 0; i < tlns.size(); ++i) - if (tlns.at(i).isEmpty()) - tlns[i] = message.sourceText(); ByteTranslatorMessage bmsg("", originalBytes(message.id(), false), "", tlns); m_messages.insert(bmsg, 0); } @@ -725,10 +722,16 @@ static bool saveQM(const Translator &translator, QIODevice &dev, ConversionData } else { ++finished; } + QStringList tlns = msg.translations(); + if (msg.type() == TranslatorMessage::Unfinished + && (cd.m_idBased || !cd.m_unTrPrefix.isEmpty())) + for (int j = 0; j < tlns.size(); ++j) + if (tlns.at(j).isEmpty()) + tlns[j] = cd.m_unTrPrefix + msg.sourceText(); if (cd.m_idBased) { if (!msg.context().isEmpty() || !msg.comment().isEmpty()) ++droppedData; - releaser.insertIdBased(msg); + releaser.insertIdBased(msg, tlns); } else { // Drop the comment in (context, sourceText, comment), // unless the context is empty, @@ -739,7 +742,7 @@ static bool saveQM(const Translator &translator, QIODevice &dev, ConversionData msg.comment().isEmpty() || msg.context().isEmpty() || translator.contains(msg.context(), msg.sourceText(), QString()); - releaser.insert(msg, forceComment); + releaser.insert(msg, tlns, forceComment); } } } diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index 1dd6a59..ef81d2a 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -86,6 +86,7 @@ public: QString m_defaultContext; QByteArray m_codecForSource; // CPP, PO & QM specific QByteArray m_outputCodec; // PO specific + QString m_unTrPrefix; // QM specific QString m_sourceFileName; QString m_targetFileName; QDir m_sourceDir; -- cgit v0.12