~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/linguist/lconvert/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the Qt Linguist of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
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.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
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
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
51
51
    Q_UNUSED(args);
52
52
 
53
53
    QString loaders;
54
 
    QString savers;
55
 
    QString line = QString(QLatin1String("    %1 - %2\n"));
56
 
    foreach (Translator::FileFormat format, Translator::registeredFileFormats()) {
 
54
    QString line(QLatin1String("    %1 - %2\n"));
 
55
    foreach (Translator::FileFormat format, Translator::registeredFileFormats())
57
56
        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
57
 
62
58
    qWarning("%s", qPrintable(QString(QLatin1String("\nUsage:\n"
63
59
        "    lconvert [options] <infile> [<infile>...]\n\n"
64
60
        "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"
 
61
        "stand-alone tool to convert and filter translation data files.\n"
 
62
        "The following file formats are supported:\n\n%1\n"
 
63
        "If multiple input files are specified, they are merged with\n"
69
64
        "translations from later files taking precedence.\n\n"
70
65
        "Options:\n"
71
66
        "    -h\n"
85
80
        "    -of <outformat>\n"
86
81
        "    --output-format <outformat>\n"
87
82
        "           Specify output format. See -if.\n\n"
 
83
        "    --input-codec <codec>\n"
 
84
        "           Specify encoding for QM and PO input files. Default is 'Latin1'\n"
 
85
        "           for QM and 'UTF-8' for PO files. UTF-8 is always tried as well for\n"
 
86
        "           QM, corresponding to the possible use of the trUtf8() function.\n\n"
 
87
        "    --output-codec <codec>\n"
 
88
        "           Specify encoding for PO output files. Default is 'UTF-8'.\n\n"
88
89
        "    --drop-tags <regexp>\n"
89
 
        "           Drop named extra tags when writing 'ts' or 'xlf' files.\n"
 
90
        "           Drop named extra tags when writing TS or XLIFF files.\n"
90
91
        "           May be specified repeatedly.\n\n"
91
92
        "    --drop-translations\n"
92
93
        "           Drop existing translations and reset the status to 'unfinished'.\n"
93
94
        "           Note: this implies --no-obsolete.\n\n"
94
95
        "    --source-language <language>[_<region>]\n"
95
96
        "           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"
 
97
        "           POSIX if not specified and the file does not name it yet.\n\n"
97
98
        "    --target-language <language>[_<region>]\n"
98
99
        "           Specify/override the language of the translation.\n"
99
100
        "           The target language is guessed from the file name if this option\n"
102
103
        "           Drop obsolete messages.\n\n"
103
104
        "    --no-finished\n"
104
105
        "           Drop finished messages.\n\n"
 
106
        "    --sort-contexts\n"
 
107
        "           Sort contexts in output TS file alphabetically.\n\n"
 
108
        "    --locations {absolute|relative|none}\n"
 
109
        "           Override how source code references are saved in TS files.\n"
 
110
        "           Default is absolute.\n\n"
 
111
        "    --no-ui-lines\n"
 
112
        "           Drop line numbers from references to UI files.\n\n"
105
113
        "    --verbose\n"
106
114
        "           be a bit more verbose\n\n"
107
115
        "Long options can be specified with only one leading dash, too.\n\n"
109
117
        "    0 on success\n"
110
118
        "    1 on command line parse failures\n"
111
119
        "    2 on read failures\n"
112
 
        "    3 on write failures\n")).arg(loaders).arg(savers)));
 
120
        "    3 on write failures\n")).arg(loaders)));
113
121
    return 1;
114
122
}
115
123
 
134
142
    bool noObsolete = false;
135
143
    bool noFinished = false;
136
144
    bool verbose = false;
 
145
    bool noUiLines = false;
 
146
    Translator::LocationsType locations = Translator::DefaultLocations;
137
147
 
138
148
    ConversionData cd;
139
149
    Translator tr;
164
174
            if (++i >= args.size())
165
175
                return usage(args);
166
176
            inFormat = args[i];
 
177
        } else if (args[i] == QLatin1String("-input-codec")) {
 
178
            if (++i >= args.size())
 
179
                return usage(args);
 
180
            cd.m_codecForSource = args[i].toLatin1();
 
181
        } else if (args[i] == QLatin1String("-output-codec")) {
 
182
            if (++i >= args.size())
 
183
                return usage(args);
 
184
            cd.m_outputCodec = args[i].toLatin1();
167
185
        } else if (args[i] == QLatin1String("-drop-tag")) {
168
186
            if (++i >= args.size())
169
187
                return usage(args);
185
203
            noObsolete = true;
186
204
        } else if (args[i] == QLatin1String("-no-finished")) {
187
205
            noFinished = true;
 
206
        } else if (args[i] == QLatin1String("-sort-contexts")) {
 
207
            cd.m_sortContexts = true;
 
208
        } else if (args[i] == QLatin1String("-locations")) {
 
209
            if (++i >= args.size())
 
210
                return usage(args);
 
211
            if (args[i] == QLatin1String("none"))
 
212
                locations = Translator::NoLocations;
 
213
            else if (args[i] == QLatin1String("relative"))
 
214
                locations = Translator::RelativeLocations;
 
215
            else if (args[i] == QLatin1String("absolute"))
 
216
                locations = Translator::AbsoluteLocations;
 
217
            else
 
218
                return usage(args);
 
219
        } else if (args[i] == QLatin1String("-no-ui-lines")) {
 
220
            noUiLines = true;
188
221
        } else if (args[i] == QLatin1String("-verbose")) {
189
222
            verbose = true;
190
223
        } else if (args[i].startsWith(QLatin1Char('-'))) {
201
234
        return usage(args);
202
235
 
203
236
    tr.setLanguageCode(Translator::guessLanguageCodeFromFileName(inFiles[0].name));
204
 
    if (!targetLanguage.isEmpty())
205
 
        tr.setLanguageCode(targetLanguage);
206
 
    if (!sourceLanguage.isEmpty())
207
 
        tr.setSourceLanguageCode(sourceLanguage);
208
237
 
209
238
    if (!tr.load(inFiles[0].name, cd, inFiles[0].format)) {
210
239
        qWarning() << qPrintable(cd.error());
223
252
            tr.replaceSorted(tr2.message(j));
224
253
    }
225
254
 
 
255
    if (!targetLanguage.isEmpty())
 
256
        tr.setLanguageCode(targetLanguage);
 
257
    if (!sourceLanguage.isEmpty())
 
258
        tr.setSourceLanguageCode(sourceLanguage);
226
259
    if (noObsolete)
227
260
        tr.stripObsoleteMessages();
228
261
    if (noFinished)
229
262
        tr.stripFinishedMessages();
230
263
    if (dropTranslations)
231
264
        tr.dropTranslations();
 
265
    if (noUiLines)
 
266
        tr.dropUiLines();
 
267
    if (locations != Translator::DefaultLocations)
 
268
        tr.setLocationsType(locations);
232
269
 
 
270
    tr.normalizeTranslations(cd);
 
271
    if (!cd.errors().isEmpty()) {
 
272
        qWarning("%s", qPrintable(cd.error()));
 
273
        cd.clearErrors();
 
274
    }
233
275
    if (!tr.save(outFileName, cd, outFormat)) {
234
276
        qWarning("%s", qPrintable(cd.error()));
235
277
        return 3;