From 9ca1e89e0d7e11b9db60d7fcf7399c655bd0e31e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 15 Nov 2013 22:02:44 +0100 Subject: rewrite support for listing translation files as sources ts files listed among the sources now contribute extant source strings with locations, i.e., they are treated like all other sources. this basically makes it possible to use lupdate like gettext's msgmerge. this enables us to write a much more efficient variant of the split-qt-ts.pl script found in qttranslations. the original functionality of adding ts files as providers of additional translations to merge is hidden behind the new -xts flag; it is of course still undocumented. Change-Id: I7a5488d814f39d6b5e9053a414547a6b1461fc14 Reviewed-by: hjk Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll --- src/linguist/lupdate/main.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/linguist/lupdate/main.cpp b/src/linguist/lupdate/main.cpp index aa06e0b33..41eb7fbdf 100644 --- a/src/linguist/lupdate/main.cpp +++ b/src/linguist/lupdate/main.cpp @@ -519,6 +519,25 @@ static void excludeProjects(const ProFileEvaluator &visitor, QStringList *subPro } } +static bool processTs(Translator &fetchedTor, const QString &file, ConversionData &cd) +{ + foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) { + if (file.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) { + Translator tor; + if (tor.load(file, cd, fmt.extension)) { + foreach (TranslatorMessage msg, tor.messages()) { + msg.setType(TranslatorMessage::Unfinished); + msg.setTranslations(QStringList()); + msg.setTranslatorComment(QString()); + fetchedTor.extend(msg, cd); + } + } + return true; + } + } + return false; +} + static void processSources(Translator &fetchedTor, const QStringList &sourceFiles, ConversionData &cd) { @@ -544,7 +563,7 @@ static void processSources(Translator &fetchedTor, || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) requireQmlSupport = true; #endif // QT_NO_QML - else + else if (!processTs(fetchedTor, *it, cd)) sourceFilesCpp << *it; } @@ -747,6 +766,7 @@ int main(int argc, char **argv) int proDebug = 0; int numFiles = 0; bool metTsFlag = false; + bool metXTsFlag = false; bool recursiveScan = true; QString extensions = m_defaultExtensions; @@ -847,6 +867,11 @@ int main(int argc, char **argv) return 0; } else if (arg == QLatin1String("-ts")) { metTsFlag = true; + metXTsFlag = false; + continue; + } else if (arg == QLatin1String("-xts")) { + metTsFlag = false; + metXTsFlag = true; continue; } else if (arg == QLatin1String("-extensions")) { ++i; @@ -948,6 +973,8 @@ int main(int argc, char **argv) } } numFiles++; + } else if (metXTsFlag) { + alienFiles += files; } else { foreach (const QString &file, files) { QFileInfo fi(file); @@ -999,17 +1026,10 @@ int main(int argc, char **argv) } } } else { - foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) { - if (file.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) { - alienFiles << file; - goto gotfile; - } - } sourceFiles << QDir::cleanPath(fi.absoluteFilePath());; projectRoots.insert(fi.absolutePath() + QLatin1Char('/')); } } - gotfile: numFiles++; } } // for args -- cgit v1.2.3