1
1
/****************************************************************************
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)
6
7
** This file is part of the Qt Linguist of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
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
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.
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
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.
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.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
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);
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"
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"
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"
112
" Drop line numbers from references to UI files.\n\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"
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())
180
cd.m_codecForSource = args[i].toLatin1();
181
} else if (args[i] == QLatin1String("-output-codec")) {
182
if (++i >= args.size())
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())
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;
219
} else if (args[i] == QLatin1String("-no-ui-lines")) {
188
221
} else if (args[i] == QLatin1String("-verbose")) {
190
223
} else if (args[i].startsWith(QLatin1Char('-'))) {
201
234
return usage(args);
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);
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));
255
if (!targetLanguage.isEmpty())
256
tr.setLanguageCode(targetLanguage);
257
if (!sourceLanguage.isEmpty())
258
tr.setSourceLanguageCode(sourceLanguage);
227
260
tr.stripObsoleteMessages();
229
262
tr.stripFinishedMessages();
230
263
if (dropTranslations)
231
264
tr.dropTranslations();
267
if (locations != Translator::DefaultLocations)
268
tr.setLocationsType(locations);
270
tr.normalizeTranslations(cd);
271
if (!cd.errors().isEmpty()) {
272
qWarning("%s", qPrintable(cd.error()));
233
275
if (!tr.save(outFileName, cd, outFormat)) {
234
276
qWarning("%s", qPrintable(cd.error()));