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/lconvert/main.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    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 have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4747#include <QtCore/QStringList>
    4848
     49#include <iostream>
     50
    4951static int usage(const QStringList &args)
    5052{
     
    5254
    5355    QString loaders;
    54     QString savers;
    55     QString line = QString(QLatin1String("    %1 - %2\n"));
    56     foreach (Translator::FileFormat format, Translator::registeredFileFormats()) {
     56    QString line(QLatin1String("    %1 - %2\n"));
     57    foreach (Translator::FileFormat format, Translator::registeredFileFormats())
    5758        loaders += line.arg(format.extension, -5).arg(format.description);
    58         if (format.fileType != Translator::FileFormat::SourceCode)
    59             savers += line.arg(format.extension, -5).arg(format.description);
    60     }
    61 
    62     qWarning("%s", qPrintable(QString(QLatin1String("\nUsage:\n"
     59
     60    std::cerr << qPrintable(QString(QLatin1String("\nUsage:\n"
    6361        "    lconvert [options] <infile> [<infile>...]\n\n"
    6462        "lconvert is part of Qt's Linguist tool chain. It can be used as a\n"
    65         "stand-alone tool to convert translation data files from one of the\n"
    66         "following input formats\n\n%1\n"
    67         "to one of the following output formats\n\n%2\n"
    68         "If multiple input files are specified the translations are merged with\n"
     63        "stand-alone tool to convert and filter translation data files.\n"
     64        "The following file formats are supported:\n\n%1\n"
     65        "If multiple input files are specified, they are merged with\n"
    6966        "translations from later files taking precedence.\n\n"
    7067        "Options:\n"
     
    8683        "    --output-format <outformat>\n"
    8784        "           Specify output format. See -if.\n\n"
     85        "    --input-codec <codec>\n"
     86        "           Specify encoding for QM and PO input files. Default is 'Latin1'\n"
     87        "           for QM and 'UTF-8' for PO files. UTF-8 is always tried as well for\n"
     88        "           QM, corresponding to the possible use of the trUtf8() function.\n\n"
     89        "    --output-codec <codec>\n"
     90        "           Specify encoding for PO output files. Default is 'UTF-8'.\n\n"
    8891        "    --drop-tags <regexp>\n"
    89         "           Drop named extra tags when writing 'ts' or 'xlf' files.\n"
     92        "           Drop named extra tags when writing TS or XLIFF files.\n"
    9093        "           May be specified repeatedly.\n\n"
    9194        "    --drop-translations\n"
     
    9497        "    --source-language <language>[_<region>]\n"
    9598        "           Specify/override the language of the source strings. Defaults to\n"
    96         "           POSIX if not specified and the file does not name it yet.\n"
     99        "           POSIX if not specified and the file does not name it yet.\n\n"
    97100        "    --target-language <language>[_<region>]\n"
    98101        "           Specify/override the language of the translation.\n"
     
    103106        "    --no-finished\n"
    104107        "           Drop finished messages.\n\n"
     108        "    --sort-contexts\n"
     109        "           Sort contexts in output TS file alphabetically.\n\n"
     110        "    --locations {absolute|relative|none}\n"
     111        "           Override how source code references are saved in TS files.\n"
     112        "           Default is absolute.\n\n"
     113        "    --no-ui-lines\n"
     114        "           Drop line numbers from references to UI files.\n\n"
    105115        "    --verbose\n"
    106116        "           be a bit more verbose\n\n"
     
    110120        "    1 on command line parse failures\n"
    111121        "    2 on read failures\n"
    112         "    3 on write failures\n")).arg(loaders).arg(savers)));
     122        "    3 on write failures\n")).arg(loaders));
    113123    return 1;
    114124}
     
    135145    bool noFinished = false;
    136146    bool verbose = false;
     147    bool noUiLines = false;
     148    Translator::LocationsType locations = Translator::DefaultLocations;
    137149
    138150    ConversionData cd;
     
    165177                return usage(args);
    166178            inFormat = args[i];
     179        } else if (args[i] == QLatin1String("-input-codec")) {
     180            if (++i >= args.size())
     181                return usage(args);
     182            cd.m_codecForSource = args[i].toLatin1();
     183        } else if (args[i] == QLatin1String("-output-codec")) {
     184            if (++i >= args.size())
     185                return usage(args);
     186            cd.m_outputCodec = args[i].toLatin1();
    167187        } else if (args[i] == QLatin1String("-drop-tag")) {
    168188            if (++i >= args.size())
     
    186206        } else if (args[i] == QLatin1String("-no-finished")) {
    187207            noFinished = true;
     208        } else if (args[i] == QLatin1String("-sort-contexts")) {
     209            cd.m_sortContexts = true;
     210        } else if (args[i] == QLatin1String("-locations")) {
     211            if (++i >= args.size())
     212                return usage(args);
     213            if (args[i] == QLatin1String("none"))
     214                locations = Translator::NoLocations;
     215            else if (args[i] == QLatin1String("relative"))
     216                locations = Translator::RelativeLocations;
     217            else if (args[i] == QLatin1String("absolute"))
     218                locations = Translator::AbsoluteLocations;
     219            else
     220                return usage(args);
     221        } else if (args[i] == QLatin1String("-no-ui-lines")) {
     222            noUiLines = true;
    188223        } else if (args[i] == QLatin1String("-verbose")) {
    189224            verbose = true;
     
    202237
    203238    tr.setLanguageCode(Translator::guessLanguageCodeFromFileName(inFiles[0].name));
    204     if (!targetLanguage.isEmpty())
    205         tr.setLanguageCode(targetLanguage);
    206     if (!sourceLanguage.isEmpty())
    207         tr.setSourceLanguageCode(sourceLanguage);
    208239
    209240    if (!tr.load(inFiles[0].name, cd, inFiles[0].format)) {
     
    211242        return 2;
    212243    }
    213     Translator::reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose);
     244    tr.reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose);
    214245
    215246    for (int i = 1; i < inFiles.size(); ++i) {
     
    219250            return 2;
    220251        }
    221         Translator::reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose);
     252        tr2.reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose);
    222253        for (int j = 0; j < tr2.messageCount(); ++j)
    223254            tr.replaceSorted(tr2.message(j));
    224255    }
    225256
     257    if (!targetLanguage.isEmpty())
     258        tr.setLanguageCode(targetLanguage);
     259    if (!sourceLanguage.isEmpty())
     260        tr.setSourceLanguageCode(sourceLanguage);
    226261    if (noObsolete)
    227262        tr.stripObsoleteMessages();
     
    230265    if (dropTranslations)
    231266        tr.dropTranslations();
    232 
     267    if (noUiLines)
     268        tr.dropUiLines();
     269    if (locations != Translator::DefaultLocations)
     270        tr.setLocationsType(locations);
     271
     272    tr.normalizeTranslations(cd);
     273    if (!cd.errors().isEmpty()) {
     274        qWarning("%s", qPrintable(cd.error()));
     275        cd.clearErrors();
     276    }
    233277    if (!tr.save(outFileName, cd, outFormat)) {
    234278        qWarning("%s", qPrintable(cd.error()));
Note: See TracChangeset for help on using the changeset viewer.