Changeset 561 for trunk/tools/linguist/lupdate
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
- 7 copied
-
. (modified) (1 prop)
-
tools/linguist/lupdate/cpp.cpp (copied) (copied from branches/vendor/nokia/qt/4.6.1/tools/linguist/lupdate/cpp.cpp )
-
tools/linguist/lupdate/java.cpp (copied) (copied from branches/vendor/nokia/qt/4.6.1/tools/linguist/lupdate/java.cpp )
-
tools/linguist/lupdate/lupdate.h (copied) (copied from branches/vendor/nokia/qt/4.6.1/tools/linguist/lupdate/lupdate.h )
-
tools/linguist/lupdate/lupdate.pro (modified) (1 diff)
-
tools/linguist/lupdate/main.cpp (modified) (19 diffs)
-
tools/linguist/lupdate/merge.cpp (copied) (copied from branches/vendor/nokia/qt/4.6.1/tools/linguist/lupdate/merge.cpp )
-
tools/linguist/lupdate/qscript.cpp (copied) (copied from branches/vendor/nokia/qt/4.6.1/tools/linguist/lupdate/qscript.cpp )
-
tools/linguist/lupdate/qscript.g (copied) (copied from branches/vendor/nokia/qt/4.6.1/tools/linguist/lupdate/qscript.g )
-
tools/linguist/lupdate/ui.cpp (copied) (copied from branches/vendor/nokia/qt/4.6.1/tools/linguist/lupdate/ui.cpp )
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/tools/linguist/lupdate/lupdate.pro
r385 r561 15 15 include(../shared/formats.pri) 16 16 include(../shared/proparser.pri) 17 include(../shared/translatortools.pri)18 17 19 SOURCES += main.cpp 18 SOURCES += \ 19 main.cpp \ 20 merge.cpp \ 21 ../shared/simtexth.cpp \ 22 \ 23 cpp.cpp \ 24 java.cpp \ 25 qscript.cpp \ 26 ui.cpp 27 28 HEADERS += \ 29 lupdate.h \ 30 ../shared/simtexth.h 20 31 21 32 DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII -
trunk/tools/linguist/lupdate/main.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the Qt Linguist of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** 40 40 ****************************************************************************/ 41 41 42 #include "translator.h" 43 #include "translatortools.h" 44 #include "profileevaluator.h" 42 #include "lupdate.h" 43 44 #include <translator.h> 45 #include <profileevaluator.h> 46 #include <proreader.h> 45 47 46 48 #include <QtCore/QCoreApplication> … … 53 55 #include <QtCore/QTextCodec> 54 56 57 58 55 59 static QString m_defaultExtensions; 56 60 57 static void print Out(const QString & out)61 static void print(const QString & out) 58 62 { 59 63 qWarning("%s", qPrintable(out)); 60 64 } 61 65 66 67 68 69 70 62 71 static void recursiveFileInfoList(const QDir &dir, 63 const QS tringList &nameFilters, QDir::Filters filter, bool recursive,72 const QS, 64 73 QFileInfoList *fileinfolist) 65 74 { 66 if (recursive) 67 filter |= QDir::AllDirs; 68 QFileInfoList entries = dir.entryInfoList(nameFilters, filter); 69 70 QFileInfoList::iterator it; 71 for (it = entries.begin(); it != entries.end(); ++it) { 72 QString fname = it->fileName(); 73 if (fname != QLatin1String(".") && fname != QLatin1String("..")) { 74 if (it->isDir()) 75 recursiveFileInfoList(QDir(it->absoluteFilePath()), nameFilters, filter, recursive, fileinfolist); 76 else 77 fileinfolist->append(*it); 78 } 79 } 75 foreach (const QFileInfo &fi, dir.entryInfoList(filter)) 76 if (fi.isDir()) 77 recursiveFileInfoList(QDir(fi.absoluteFilePath()), nameFilters, filter, fileinfolist); 78 else if (nameFilters.contains(fi.suffix())) 79 fileinfolist->append(fi); 80 80 } 81 81 … … 84 84 printOut(QObject::tr( 85 85 "Usage:\n" 86 " lupdate [options] [project-file] \n"86 " lupdate [options] [project-file]\n" 87 87 " lupdate [options] [source-file|path]... -ts ts-files\n\n" 88 "lupdate is part of Qt's Linguist tool chain. It can be used as a\n"89 " stand-alone tool to create XML based translations files in the .ts\n"90 " format from translatable messages in C++ and Java source code.\n\n"91 " lupdate can also merge such messages into existing .tsfiles.\n\n"88 "lupdate is part of Qt's Linguist tool chain. It \n" 89 "\n" 90 "\n" 91 " files.\n\n" 92 92 "Options:\n" 93 93 " -help Display this information and exit.\n" … … 103 103 " Do not explain what is being done.\n" 104 104 " -no-sort\n" 105 " Do not sort contexts in .tsfiles.\n"105 " Do not sort contexts in files.\n" 106 106 " -no-recursive\n" 107 107 " Do not recursively scan the following directories.\n" 108 108 " -recursive\n" 109 " Recursively scan the following directories.\n" 109 " Recursively scan the following directories (default).\n" 110 " -I <includepath> or -I<includepath>\n" 111 " Additional location to look for include files.\n" 112 " May be specified multiple times.\n" 110 113 " -locations {absolute|relative|none}\n" 111 " Specify/override how source code references are saved in tsfiles.\n"114 " Specify/override how source code references are saved in files.\n" 112 115 " Default is absolute.\n" 113 116 " -no-ui-lines\n" 114 " Do not record line numbers in references to .uifiles.\n"117 " Do not record line numbers in references to files.\n" 115 118 " -disable-heuristic {sametext|similartext|number}\n" 116 119 " Disable the named merge heuristic. Can be specified multiple times.\n" … … 119 122 " file syntax but different file suffix\n" 120 123 " -source-language <language>[_<region>]\n" 121 " Specify /override the language of the source strings. Defaults to\n"122 " POSIX if not specified and the file does not name it yet.\n"124 " Specify\n" 125 " .\n" 123 126 " -target-language <language>[_<region>]\n" 124 " Specify/override the language of the translation.\n" 125 " The target language is guessed from the file name if this option\n" 126 " is not specified and the file contents name no language yet.\n" 127 " Specify the language of the translations for new files.\n" 128 " Guessed from the file name if not specified.\n" 127 129 " -version\n" 128 130 " Display the version of lupdate and exit.\n" … … 143 145 if (QFile(fileName).exists()) { 144 146 if (!tor.load(fileName, cd, QLatin1String("auto"))) { 145 print Out(cd.error());147 print(cd.error()); 146 148 *fail = true; 147 149 continue; … … 166 168 if (!targetLanguage.isEmpty()) 167 169 tor.setLanguageCode(targetLanguage); 170 171 168 172 if (!sourceLanguage.isEmpty()) 169 173 tor.setSourceLanguageCode(sourceLanguage); … … 179 183 printOut(QObject::tr("Updating '%1'...\n").arg(fn)); 180 184 185 181 186 if (tor.locationsType() == Translator::NoLocations) // Could be set from file 182 options |= NoLocations;183 Translator out = merge(tor, fetchedTor, options, err);187 ptions |= NoLocations; 188 Translator out = merge(tor, fetchedTor, ptions, err); 184 189 if (!codecForTr.isEmpty()) 185 190 out.setCodecName(codecForTr); … … 198 203 out.stripEmptyContexts(); 199 204 205 206 207 208 209 200 210 if (!out.save(fileName, cd, QLatin1String("auto"))) { 201 print Out(cd.error());211 print(cd.error()); 202 212 *fail = true; 203 213 } … … 217 227 QStringList tsFileNames; 218 228 QStringList proFiles; 229 230 219 231 QStringList sourceFiles; 232 220 233 QString targetLanguage; 221 234 QString sourceLanguage; … … 230 243 231 244 QString extensions = m_defaultExtensions; 232 QS tringListextensionsNameFilters;245 QS extensionsNameFilters; 233 246 234 247 for (int i = 1; i < argc; ++i) { … … 343 356 proFiles += args[i]; 344 357 numFiles++; 358 359 360 361 362 363 364 365 366 367 368 369 345 370 continue; 346 371 } else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) { … … 388 413 printOut(QObject::tr("Scanning directory '%1'...").arg(arg)); 389 414 QDir dir = QDir(fi.filePath()); 415 390 416 if (extensionsNameFilters.isEmpty()) { 391 extensions = extensions.trimmed(); 392 // Remove the potential dot in front of each extension 393 if (extensions.startsWith(QLatin1Char('.'))) 394 extensions.remove(0,1); 395 extensions.replace(QLatin1String(",."), QLatin1String(",")); 396 397 extensions.insert(0, QLatin1String("*.")); 398 extensions.replace(QLatin1Char(','), QLatin1String(",*.")); 399 extensionsNameFilters = extensions.split(QLatin1Char(',')); 417 foreach (QString ext, extensions.split(QLatin1Char(','))) { 418 ext = ext.trimmed(); 419 if (ext.startsWith(QLatin1Char('.'))) 420 ext.remove(0, 1); 421 extensionsNameFilters.insert(ext); 422 } 400 423 } 401 424 QDir::Filters filters = QDir::Files | QDir::NoSymLinks; 425 426 402 427 QFileInfoList fileinfolist; 403 recursiveFileInfoList(dir, extensionsNameFilters, filters, 404 recursiveScan, &fileinfolist); 405 QFileInfoList::iterator ii; 406 QString fn; 407 for (ii = fileinfolist.begin(); ii != fileinfolist.end(); ++ii) { 408 // Make sure the path separator is stored with '/' in the ts file 409 sourceFiles << ii->canonicalFilePath().replace(QLatin1Char('\\'), QLatin1Char('/')); 428 recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist); 429 int scanRootLen = dir.absolutePath().length(); 430 foreach (const QFileInfo &fi, fileinfolist) { 431 QString fn = QDir::cleanPath(fi.absoluteFilePath()); 432 sourceFiles << fn; 433 434 if (!fn.endsWith(QLatin1String(".java")) 435 && !fn.endsWith(QLatin1String(".ui")) 436 && !fn.endsWith(QLatin1String(".js")) 437 && !fn.endsWith(QLatin1String(".qs"))) { 438 int offset = 0; 439 int depth = 0; 440 do { 441 offset = fn.lastIndexOf(QLatin1Char('/'), offset - 1); 442 QString ffn = fn.mid(offset + 1); 443 allCSources.insert(ffn, fn); 444 } while (++depth < 3 && offset > scanRootLen); 445 } 410 446 } 411 447 } else { 412 sourceFiles << fi.canonicalFilePath().replace(QLatin1Char('\\'), QLatin1Char('/'));448 sourceFiles << ; 413 449 } 414 450 } 415 451 } // for args 416 452 453 454 417 455 418 456 bool firstPass = true; … … 422 460 cd.m_defaultContext = defaultContext; 423 461 cd.m_noUiLines = options & NoUiLines; 462 463 464 424 465 425 466 QStringList tsFiles = tsFileNames; … … 451 492 } 452 493 453 evaluateProFile(visitor, &variables); 494 cd.m_includePath += visitor.values(QLatin1String("INCLUDEPATH")); 495 496 evaluateProFile(visitor, &variables, pfi.absolutePath()); 454 497 455 498 sourceFiles = variables.value("SOURCES"); … … 459 502 codecForTr = tmp.first().toLatin1(); 460 503 fetchedTor.setCodecName(codecForTr); 504 461 505 } 462 506 tmp = variables.value("CODECFORSRC"); … … 473 517 } 474 518 519 475 520 for (QStringList::iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) { 476 if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive)) { 477 cd.m_sourceFileName = *it; 478 fetchedTor.load(*it, cd, QLatin1String("java")); 479 //fetchtr_java(*it, &fetchedTor, defaultContext, true, codecForSource); 480 } 481 else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive)) { 482 fetchedTor.load(*it, cd, QLatin1String("ui")); 483 //fetchedTor.load(*it + QLatin1String(".h"), cd, QLatin1String("cpp")); 484 //fetchtr_ui(*it, &fetchedTor, defaultContext, true); 485 //fetchtr_cpp(*it + QLatin1String(".h"), &fetchedTor, 486 // defaultContext, false, codecForSource); 487 } 521 if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive)) 522 loadJava(fetchedTor, *it, cd); 523 else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive) 524 || it->endsWith(QLatin1String(".jui"), Qt::CaseInsensitive)) 525 loadUI(fetchedTor, *it, cd); 488 526 else if (it->endsWith(QLatin1String(".js"), Qt::CaseInsensitive) 489 || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) { 490 fetchedTor.load(*it, cd, QLatin1String("js")); 491 } else { 492 fetchedTor.load(*it, cd, QLatin1String("cpp")); 493 //fetchtr_cpp(*it, &fetchedTor, defaultContext, true, codecForSource); 494 } 495 } 527 || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) 528 loadQScript(fetchedTor, *it, cd); 529 else 530 sourceFilesCpp << *it; 531 } 532 loadCPP(fetchedTor, sourceFilesCpp, cd); 496 533 if (!cd.error().isEmpty()) 497 534 printOut(cd.error());
Note:
See TracChangeset
for help on using the changeset viewer.
