Changeset 561 for trunk/tools/linguist/lrelease/main.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
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/lrelease/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 ** … … 41 41 42 42 #include "translator.h" 43 #include " translatortools.h"44 #include "profileevaluator.h" 45 43 #include ".h" 44 45 #ifndef QT_BOOTSTRAPPED 46 46 #include <QtCore/QCoreApplication> 47 48 47 49 #include <QtCore/QDebug> 48 50 #include <QtCore/QDir> … … 53 55 #include <QtCore/QStringList> 54 56 #include <QtCore/QTextStream> 55 #include <QtCore/QTranslator> 57 58 QT_USE_NAMESPACE 59 60 #ifdef QT_BOOTSTRAPPED 61 static void initBinaryDir( 62 #ifndef Q_OS_WIN 63 const char *argv0 64 #endif 65 ); 66 #endif 56 67 57 68 static void printOut(const QString & out) … … 68 79 " lrelease [options] ts-files [-qm qm-file]\n\n" 69 80 "lrelease is part of Qt's Linguist tool chain. It can be used as a\n" 70 "stand-alone tool to convert XML based translations files in the .ts\n"71 "format into the 'compiled' .qmformat used by QTranslator objects.\n\n"81 "stand-alone tool to convert XML\n" 82 "format into the 'compiled' format used by QTranslator objects.\n\n" 72 83 "Options:\n" 73 84 " -help Display this information and exit\n" 85 86 74 87 " -compress\n" 75 " Compress the .qmfiles\n"88 " Compress the files\n" 76 89 " -nounfinished\n" 77 90 " Do not include unfinished translations\n" … … 79 92 " If the translated text is the same as\n" 80 93 " the source text, do not include the message\n" 94 95 96 81 97 " -silent\n" 82 " Do n't explain what is being done\n"98 " Dot explain what is being done\n" 83 99 " -version\n" 84 100 " Display the version of lrelease and exit\n" … … 100 116 101 117 static bool releaseTranslator(Translator &tor, const QString &qmFileName, 102 bool verbose, bool ignoreUnfinished, 103 bool removeIdentical, TranslatorSaveMode mode) 104 { 105 Translator::reportDuplicates(tor.resolveDuplicates(), qmFileName, verbose); 106 107 if (verbose) 118 ConversionData &cd, bool removeIdentical) 119 { 120 tor.reportDuplicates(tor.resolveDuplicates(), qmFileName, cd.isVerbose()); 121 122 if (cd.isVerbose()) 108 123 printOut(QCoreApplication::tr( "Updating '%1'...\n").arg(qmFileName)); 109 124 if (removeIdentical) { 110 if ( verbose)125 if () 111 126 printOut(QCoreApplication::tr( "Removing translations equal to source text in '%1'...\n").arg(qmFileName)); 112 127 tor.stripIdenticalSourceTranslations(); … … 120 135 } 121 136 122 ConversionData cd; 123 cd.m_verbose = verbose; 124 cd.m_ignoreUnfinished = ignoreUnfinished; 125 cd.m_saveMode = mode; 137 tor.normalizeTranslations(cd); 126 138 bool ok = tor.release(&file, cd); 127 139 file.close(); … … 137 149 } 138 150 139 static bool releaseTsFile(const QString& tsFileName, bool verbose,140 bool ignoreUnfinished, bool removeIdentical, TranslatorSaveMode mode)151 static bool releaseTsFile(const QString& tsFileName, 152 ) 141 153 { 142 154 Translator tor; 143 if (!loadTsFile(tor, tsFileName, verbose))155 if (!loadTsFile(tor, tsFileName, )) 144 156 return false; 145 157 … … 153 165 qmFileName += QLatin1String(".qm"); 154 166 155 return releaseTranslator(tor, qmFileName, verbose, ignoreUnfinished, removeIdentical, mode);167 return releaseTranslator(tor, qmFileName, ); 156 168 } 157 169 158 170 int main(int argc, char **argv) 159 171 { 172 173 174 175 176 177 178 160 179 QCoreApplication app(argc, argv); 161 QStringList args = app.arguments();162 180 QTranslator translator; 163 181 if (translator.load(QLatin1String("lrelease_") + QLocale::system().name())) 164 182 app.installTranslator(&translator); 165 166 bool verbose = true; // the default is true starting with Qt 4.2 167 bool ignoreUnfinished = false; 168 // the default mode is SaveEverything starting with Qt 4.2 169 TranslatorSaveMode mode = SaveEverything; 183 #endif 184 185 ConversionData cd; 186 cd.m_verbose = true; // the default is true starting with Qt 4.2 170 187 bool removeIdentical = false; 171 188 Translator tor; 189 172 190 QString outputFile; 173 int numFiles = 0;174 191 175 192 for (int i = 1; i < argc; ++i) { 176 if (args[i] == QLatin1String("-compress")) { 177 mode = SaveStripped; 178 continue; 179 } else if (args[i] == QLatin1String("-nocompress")) { 180 mode = SaveEverything; 181 continue; 182 } else if (args[i] == QLatin1String("-removeidentical")) { 193 if (!strcmp(argv[i], "-compress")) { 194 cd.m_saveMode = SaveStripped; 195 continue; 196 } else if (!strcmp(argv[i], "-idbased")) { 197 cd.m_idBased = true; 198 continue; 199 } else if (!strcmp(argv[i], "-nocompress")) { 200 cd.m_saveMode = SaveEverything; 201 continue; 202 } else if (!strcmp(argv[i], "-removeidentical")) { 183 203 removeIdentical = true; 184 204 continue; 185 } else if (args[i] == QLatin1String("-nounfinished")) { 186 ignoreUnfinished = true; 187 continue; 188 } else if (args[i] == QLatin1String("-silent")) { 189 verbose = false; 190 continue; 191 } else if (args[i] == QLatin1String("-verbose")) { 192 verbose = true; 193 continue; 194 } else if (args[i] == QLatin1String("-version")) { 195 printOut(QCoreApplication::tr( "lrelease version %1\n").arg(QLatin1String(QT_VERSION_STR)) ); 196 return 0; 197 } else if (args[i] == QLatin1String("-qm")) { 205 } else if (!strcmp(argv[i], "-nounfinished")) { 206 cd.m_ignoreUnfinished = true; 207 continue; 208 } else if (!strcmp(argv[i], "-markuntranslated")) { 198 209 if (i == argc - 1) { 199 210 printUsage(); 200 211 return 1; 201 212 } 202 i++; 203 outputFile = args[i]; 204 } else if (args[i] == QLatin1String("-help")) { 213 cd.m_unTrPrefix = QString::fromLocal8Bit(argv[++i]); 214 } else if (!strcmp(argv[i], "-silent")) { 215 cd.m_verbose = false; 216 continue; 217 } else if (!strcmp(argv[i], "-verbose")) { 218 cd.m_verbose = true; 219 continue; 220 } else if (!strcmp(argv[i], "-version")) { 221 printOut(QCoreApplication::tr( "lrelease version %1\n").arg(QLatin1String(QT_VERSION_STR)) ); 222 return 0; 223 } else if (!strcmp(argv[i], "-qm")) { 224 if (i == argc - 1) { 225 printUsage(); 226 return 1; 227 } 228 outputFile = QString::fromLocal8Bit(argv[++i]); 229 } else if (!strcmp(argv[i], "-help")) { 205 230 printUsage(); 206 231 return 0; 207 } else if (arg s[i][0] == QLatin1Char('-')) {232 } else if (arg) { 208 233 printUsage(); 209 234 return 1; 210 235 } else { 211 numFiles++;236 ; 212 237 } 213 238 } 214 239 215 if ( numFiles == 0) {240 if () { 216 241 printUsage(); 217 242 return 1; 218 243 } 219 244 220 for (int i = 1; i < argc; ++i) { 221 if (args[i][0] == QLatin1Char('-') || args[i] == outputFile) 222 continue; 223 224 if (args[i].endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) 225 || args[i].endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { 245 foreach (const QString &inputFile, inputFiles) { 246 if (inputFile.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) 247 || inputFile.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { 226 248 QHash<QByteArray, QStringList> varMap; 227 bool ok = evaluateProFile( args[i], verbose, &varMap);249 bool ok = evaluateProFile(); 228 250 if (ok) { 229 251 QStringList translations = varMap.value("TRANSLATIONS"); … … 231 253 qWarning("lrelease warning: Met no 'TRANSLATIONS' entry in" 232 254 " project file '%s'\n", 233 qPrintable( args[i]));255 qPrintable()); 234 256 } else { 235 257 foreach (const QString &trans, translations) 236 if (!releaseTsFile(trans, verbose, ignoreUnfinished, removeIdentical, mode))258 if (!releaseTsFile(trans, )) 237 259 return 1; 238 260 } 239 261 } else { 240 262 qWarning("error: lrelease encountered project file functionality that is currently not supported.\n" 241 "You might want to consider using .tsfiles as input instead of a project file.\n"263 "You might want to consider using files as input instead of a project file.\n" 242 264 "Try the following syntax:\n" 243 265 " lrelease [options] ts-files [-qm qm-file]\n"); … … 245 267 } else { 246 268 if (outputFile.isEmpty()) { 247 if (!releaseTsFile( args[i], verbose, ignoreUnfinished, removeIdentical, mode))269 if (!releaseTsFile()) 248 270 return 1; 249 271 } else { 250 if (!loadTsFile(tor, args[i], verbose))272 if (!loadTsFile(tor, )) 251 273 return 1; 252 274 } … … 255 277 256 278 if (!outputFile.isEmpty()) 257 return releaseTranslator(tor, outputFile, verbose, ignoreUnfinished, 258 removeIdentical, mode) ? 0 : 1; 279 return releaseTranslator(tor, outputFile, cd, removeIdentical) ? 0 : 1; 259 280 260 281 return 0; 261 282 } 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
Note:
See TracChangeset
for help on using the changeset viewer.