changeset 37 | 758a864f9613 |
parent 33 | 3e2da88830cd |
36:ef0373b55136 | 37:758a864f9613 |
---|---|
50 #include <QtCore/QFile> |
50 #include <QtCore/QFile> |
51 #include <QtCore/QFileInfo> |
51 #include <QtCore/QFileInfo> |
52 #include <QtCore/QString> |
52 #include <QtCore/QString> |
53 #include <QtCore/QStringList> |
53 #include <QtCore/QStringList> |
54 #include <QtCore/QTextCodec> |
54 #include <QtCore/QTextCodec> |
55 #include <QtCore/QTranslator> |
|
56 #include <QtCore/QLibraryInfo> |
|
55 |
57 |
56 #include <iostream> |
58 #include <iostream> |
57 |
59 |
58 static QString m_defaultExtensions; |
60 static QString m_defaultExtensions; |
59 |
61 |
77 fileinfolist->append(fi); |
79 fileinfolist->append(fi); |
78 } |
80 } |
79 |
81 |
80 static void printUsage() |
82 static void printUsage() |
81 { |
83 { |
82 printOut(QObject::tr( |
84 printOut(LU::tr( |
83 "Usage:\n" |
85 "Usage:\n" |
84 " lupdate [options] [project-file]...\n" |
86 " lupdate [options] [project-file]...\n" |
85 " lupdate [options] [source-file|path|@lst-file]... -ts ts-files|@lst-file\n\n" |
87 " lupdate [options] [source-file|path|@lst-file]... -ts ts-files|@lst-file\n\n" |
86 "lupdate is part of Qt's Linguist tool chain. It extracts translatable\n" |
88 "lupdate is part of Qt's Linguist tool chain. It extracts translatable\n" |
87 "messages from Qt UI files, C++, Java and JavaScript/QtScript source code.\n" |
89 "messages from Qt UI files, C++, Java and JavaScript/QtScript source code.\n" |
184 else if (options & RelativeLocations) |
186 else if (options & RelativeLocations) |
185 tor.setLocationsType(Translator::RelativeLocations); |
187 tor.setLocationsType(Translator::RelativeLocations); |
186 else if (options & AbsoluteLocations) |
188 else if (options & AbsoluteLocations) |
187 tor.setLocationsType(Translator::AbsoluteLocations); |
189 tor.setLocationsType(Translator::AbsoluteLocations); |
188 if (options & Verbose) |
190 if (options & Verbose) |
189 printOut(QObject::tr("Updating '%1'...\n").arg(fn)); |
191 printOut(LU::tr("Updating '%1'...\n").arg(fn)); |
190 |
192 |
191 UpdateOptions theseOptions = options; |
193 UpdateOptions theseOptions = options; |
192 if (tor.locationsType() == Translator::NoLocations) // Could be set from file |
194 if (tor.locationsType() == Translator::NoLocations) // Could be set from file |
193 theseOptions |= NoLocations; |
195 theseOptions |= NoLocations; |
194 Translator out = merge(tor, fetchedTor, theseOptions, err); |
196 Translator out = merge(tor, fetchedTor, theseOptions, err); |
199 printOut(err); |
201 printOut(err); |
200 err.clear(); |
202 err.clear(); |
201 } |
203 } |
202 if (options & PluralOnly) { |
204 if (options & PluralOnly) { |
203 if (options & Verbose) |
205 if (options & Verbose) |
204 printOut(QObject::tr("Stripping non plural forms in '%1'...\n").arg(fn)); |
206 printOut(LU::tr("Stripping non plural forms in '%1'...\n").arg(fn)); |
205 out.stripNonPluralForms(); |
207 out.stripNonPluralForms(); |
206 } |
208 } |
207 if (options & NoObsolete) |
209 if (options & NoObsolete) |
208 out.stripObsoleteMessages(); |
210 out.stripObsoleteMessages(); |
209 out.stripEmptyContexts(); |
211 out.stripEmptyContexts(); |
357 } |
359 } |
358 |
360 |
359 if (visitor.contains(QLatin1String("TRANSLATIONS"))) { |
361 if (visitor.contains(QLatin1String("TRANSLATIONS"))) { |
360 if (parentTor) { |
362 if (parentTor) { |
361 if (topLevel) { |
363 if (topLevel) { |
362 std::cerr << "lupdate warning: TS files from command line " |
364 std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line " |
363 "will override TRANSLATIONS in " << qPrintable(proFile) << ".\n"; |
365 "will override TRANSLATIONS in %1.\n").arg(proFile)); |
364 goto noTrans; |
366 goto noTrans; |
365 } else if (nestComplain) { |
367 } else if (nestComplain) { |
366 std::cerr << "lupdate warning: TS files from command line " |
368 std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line " |
367 "prevent recursing into " << qPrintable(proFile) << ".\n"; |
369 "prevent recursing into %1.\n").arg(proFile)); |
368 continue; |
370 continue; |
369 } |
371 } |
370 } |
372 } |
371 QStringList tsFiles; |
373 QStringList tsFiles; |
372 QDir proDir(pfi.absolutePath()); |
374 QDir proDir(pfi.absolutePath()); |
393 continue; |
395 continue; |
394 } |
396 } |
395 noTrans: |
397 noTrans: |
396 if (!parentTor) { |
398 if (!parentTor) { |
397 if (topLevel) |
399 if (topLevel) |
398 std::cerr << "lupdate warning: no TS files specified. Only diagnostics " |
400 std::cerr << qPrintable(LU::tr("lupdate warning: no TS files specified. Only diagnostics " |
399 "will be produced for '" << qPrintable(proFile) << "'.\n"; |
401 "will be produced for '%1'.\n").arg(proFile)); |
400 Translator tor; |
402 Translator tor; |
401 processProject(nestComplain, pfi, visitor, options, codecForSource, |
403 processProject(nestComplain, pfi, visitor, options, codecForSource, |
402 targetLanguage, sourceLanguage, &tor, fail); |
404 targetLanguage, sourceLanguage, &tor, fail); |
403 } else { |
405 } else { |
404 processProject(nestComplain, pfi, visitor, options, codecForSource, |
406 processProject(nestComplain, pfi, visitor, options, codecForSource, |
408 } |
410 } |
409 |
411 |
410 int main(int argc, char **argv) |
412 int main(int argc, char **argv) |
411 { |
413 { |
412 QCoreApplication app(argc, argv); |
414 QCoreApplication app(argc, argv); |
415 QTranslator translator; |
|
416 QTranslator qtTranslator; |
|
417 QString sysLocale = QLocale::system().name(); |
|
418 QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); |
|
419 if (translator.load(QLatin1String("linguist_") + sysLocale, resourceDir) |
|
420 && qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)) { |
|
421 app.installTranslator(&translator); |
|
422 app.installTranslator(&qtTranslator); |
|
423 } |
|
424 |
|
413 m_defaultExtensions = QLatin1String("java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml"); |
425 m_defaultExtensions = QLatin1String("java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml"); |
414 |
426 |
415 QStringList args = app.arguments(); |
427 QStringList args = app.arguments(); |
416 QStringList tsFileNames; |
428 QStringList tsFileNames; |
417 QStringList proFiles; |
429 QStringList proFiles; |
611 if (file.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) |
623 if (file.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) |
612 || file.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { |
624 || file.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { |
613 proFiles << file; |
625 proFiles << file; |
614 } else if (fi.isDir()) { |
626 } else if (fi.isDir()) { |
615 if (options & Verbose) |
627 if (options & Verbose) |
616 printOut(QObject::tr("Scanning directory '%1'...\n").arg(file)); |
628 printOut(LU::tr("Scanning directory '%1'...\n").arg(file)); |
617 QDir dir = QDir(fi.filePath()); |
629 QDir dir = QDir(fi.filePath()); |
618 projectRoots.insert(dir.absolutePath() + QLatin1Char('/')); |
630 projectRoots.insert(dir.absolutePath() + QLatin1Char('/')); |
619 if (extensionsNameFilters.isEmpty()) { |
631 if (extensionsNameFilters.isEmpty()) { |
620 foreach (QString ext, extensions.split(QLatin1Char(','))) { |
632 foreach (QString ext, extensions.split(QLatin1Char(','))) { |
621 ext = ext.trimmed(); |
633 ext = ext.trimmed(); |