rewrite support for listing translation files as sources
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>
Fri, 15 Nov 2013 21:02:44 +0000 (22:02 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 23 Nov 2013 22:35:38 +0000 (23:35 +0100)
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 <hjk121@nokiamail.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/linguist/lupdate/main.cpp

index aa06e0b..41eb7fb 100644 (file)
@@ -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