Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/linguist/lrelease/main.cpp

    r2 r561  
    22**
    33** 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])
    56**
    67** This file is part of the Qt Linguist of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4141
    4242#include "translator.h"
    43 #include "translatortools.h"
    44 #include "profileevaluator.h"
    45 
     43#include ".h"
     44
     45#ifndef QT_BOOTSTRAPPED
    4646#include <QtCore/QCoreApplication>
     47
     48
    4749#include <QtCore/QDebug>
    4850#include <QtCore/QDir>
     
    5355#include <QtCore/QStringList>
    5456#include <QtCore/QTextStream>
    55 #include <QtCore/QTranslator>
     57
     58QT_USE_NAMESPACE
     59
     60#ifdef QT_BOOTSTRAPPED
     61static void initBinaryDir(
     62#ifndef Q_OS_WIN
     63        const char *argv0
     64#endif
     65        );
     66#endif
    5667
    5768static void printOut(const QString & out)
     
    6879        "    lrelease [options] ts-files [-qm qm-file]\n\n"
    6980        "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' .qm format 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"
    7283        "Options:\n"
    7384        "    -help  Display this information and exit\n"
     85
     86
    7487        "    -compress\n"
    75         "           Compress the .qm files\n"
     88        "           Compress the files\n"
    7689        "    -nounfinished\n"
    7790        "           Do not include unfinished translations\n"
     
    7992        "           If the translated text is the same as\n"
    8093        "           the source text, do not include the message\n"
     94
     95
     96
    8197        "    -silent\n"
    82         "           Don't explain what is being done\n"
     98        "           Dot explain what is being done\n"
    8399        "    -version\n"
    84100        "           Display the version of lrelease and exit\n"
     
    100116
    101117static 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())
    108123        printOut(QCoreApplication::tr( "Updating '%1'...\n").arg(qmFileName));
    109124    if (removeIdentical) {
    110         if ( verbose )
     125        if ()
    111126            printOut(QCoreApplication::tr( "Removing translations equal to source text in '%1'...\n").arg(qmFileName));
    112127        tor.stripIdenticalSourceTranslations();
     
    120135    }
    121136
    122     ConversionData cd;
    123     cd.m_verbose = verbose;
    124     cd.m_ignoreUnfinished = ignoreUnfinished;
    125     cd.m_saveMode = mode;
     137    tor.normalizeTranslations(cd);
    126138    bool ok = tor.release(&file, cd);
    127139    file.close();
     
    137149}
    138150
    139 static bool releaseTsFile(const QString& tsFileName, bool verbose,
    140     bool ignoreUnfinished, bool removeIdentical, TranslatorSaveMode mode)
     151static bool releaseTsFile(const QString& tsFileName,
     152    )
    141153{
    142154    Translator tor;
    143     if (!loadTsFile(tor, tsFileName, verbose))
     155    if (!loadTsFile(tor, tsFileName, ))
    144156        return false;
    145157
     
    153165    qmFileName += QLatin1String(".qm");
    154166
    155     return releaseTranslator(tor, qmFileName, verbose, ignoreUnfinished, removeIdentical, mode);
     167    return releaseTranslator(tor, qmFileName, );
    156168}
    157169
    158170int main(int argc, char **argv)
    159171{
     172
     173
     174
     175
     176
     177
     178
    160179    QCoreApplication app(argc, argv);
    161     QStringList args = app.arguments();
    162180    QTranslator translator;
    163181    if (translator.load(QLatin1String("lrelease_") + QLocale::system().name()))
    164182        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
    170187    bool removeIdentical = false;
    171188    Translator tor;
     189
    172190    QString outputFile;
    173     int numFiles = 0;
    174191
    175192    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")) {
    183203            removeIdentical = true;
    184204            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")) {
    198209            if (i == argc - 1) {
    199210                printUsage();
    200211                return 1;
    201212            }
    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")) {
    205230            printUsage();
    206231            return 0;
    207         } else if (args[i][0] == QLatin1Char('-')) {
     232        } else if (arg) {
    208233            printUsage();
    209234            return 1;
    210235        } else {
    211             numFiles++;
     236            ;
    212237        }
    213238    }
    214239
    215     if (numFiles == 0) {
     240    if () {
    216241        printUsage();
    217242        return 1;
    218243    }
    219244
    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)) {
    226248            QHash<QByteArray, QStringList> varMap;
    227             bool ok = evaluateProFile(args[i], verbose, &varMap );
     249            bool ok = evaluateProFile();
    228250            if (ok) {
    229251                QStringList translations = varMap.value("TRANSLATIONS");
     
    231253                    qWarning("lrelease warning: Met no 'TRANSLATIONS' entry in"
    232254                             " project file '%s'\n",
    233                              qPrintable(args[i]));
     255                             qPrintable());
    234256                } else {
    235257                    foreach (const QString &trans, translations)
    236                         if (!releaseTsFile(trans, verbose, ignoreUnfinished, removeIdentical, mode))
     258                        if (!releaseTsFile(trans, ))
    237259                            return 1;
    238260                }
    239261            } else {
    240262                qWarning("error: lrelease encountered project file functionality that is currently not supported.\n"
    241                     "You might want to consider using .ts files as input instead of a project file.\n"
     263                    "You might want to consider using files as input instead of a project file.\n"
    242264                    "Try the following syntax:\n"
    243265                    "    lrelease [options] ts-files [-qm qm-file]\n");
     
    245267        } else {
    246268            if (outputFile.isEmpty()) {
    247                 if (!releaseTsFile(args[i], verbose, ignoreUnfinished, removeIdentical, mode))
     269                if (!releaseTsFile())
    248270                    return 1;
    249271            } else {
    250                 if (!loadTsFile(tor, args[i], verbose))
     272                if (!loadTsFile(tor, ))
    251273                    return 1;
    252274            }
     
    255277
    256278    if (!outputFile.isEmpty())
    257         return releaseTranslator(tor, outputFile, verbose, ignoreUnfinished,
    258                                  removeIdentical, mode) ? 0 : 1;
     279        return releaseTranslator(tor, outputFile, cd, removeIdentical) ? 0 : 1;
    259280
    260281    return 0;
    261282}
     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.