0
|
1 |
/****************************************************************************
|
|
2 |
**
|
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
4 |
** All rights reserved.
|
|
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 |
** 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.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
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 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "lupdate.h"
|
|
43 |
|
|
44 |
#include <translator.h>
|
|
45 |
#include <profileevaluator.h>
|
|
46 |
|
|
47 |
#include <QtCore/QCoreApplication>
|
|
48 |
#include <QtCore/QDebug>
|
|
49 |
#include <QtCore/QDir>
|
|
50 |
#include <QtCore/QFile>
|
|
51 |
#include <QtCore/QFileInfo>
|
|
52 |
#include <QtCore/QString>
|
|
53 |
#include <QtCore/QStringList>
|
|
54 |
#include <QtCore/QTextCodec>
|
|
55 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
56 |
#include <iostream>
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
57 |
|
0
|
58 |
static QString m_defaultExtensions;
|
|
59 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
60 |
static void printErr(const QString & out)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
61 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
62 |
qWarning("%s", qPrintable(out));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
63 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
64 |
|
0
|
65 |
static void printOut(const QString & out)
|
|
66 |
{
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
67 |
std::cerr << qPrintable(out);
|
0
|
68 |
}
|
|
69 |
|
|
70 |
static void recursiveFileInfoList(const QDir &dir,
|
|
71 |
const QSet<QString> &nameFilters, QDir::Filters filter,
|
|
72 |
QFileInfoList *fileinfolist)
|
|
73 |
{
|
|
74 |
foreach (const QFileInfo &fi, dir.entryInfoList(filter))
|
|
75 |
if (fi.isDir())
|
|
76 |
recursiveFileInfoList(QDir(fi.absoluteFilePath()), nameFilters, filter, fileinfolist);
|
|
77 |
else if (nameFilters.contains(fi.suffix()))
|
|
78 |
fileinfolist->append(fi);
|
|
79 |
}
|
|
80 |
|
|
81 |
static void printUsage()
|
|
82 |
{
|
|
83 |
printOut(QObject::tr(
|
|
84 |
"Usage:\n"
|
|
85 |
" lupdate [options] [project-file]...\n"
|
|
86 |
" lupdate [options] [source-file|path]... -ts ts-files\n\n"
|
|
87 |
"lupdate is part of Qt's Linguist tool chain. It extracts translatable\n"
|
|
88 |
"messages from Qt UI files, C++, Java and JavaScript/QtScript source code.\n"
|
|
89 |
"Extracted messages are stored in textual translation source files (typically\n"
|
|
90 |
"Qt TS XML). New and modified messages can be merged into existing TS files.\n\n"
|
|
91 |
"Options:\n"
|
|
92 |
" -help Display this information and exit.\n"
|
|
93 |
" -no-obsolete\n"
|
|
94 |
" Drop all obsolete strings.\n"
|
|
95 |
" -extensions <ext>[,<ext>]...\n"
|
|
96 |
" Process files with the given extensions only.\n"
|
|
97 |
" The extension list must be separated with commas, not with whitespace.\n"
|
|
98 |
" Default: '%1'.\n"
|
|
99 |
" -pluralonly\n"
|
|
100 |
" Only include plural form messages.\n"
|
|
101 |
" -silent\n"
|
|
102 |
" Do not explain what is being done.\n"
|
|
103 |
" -no-sort\n"
|
|
104 |
" Do not sort contexts in TS files.\n"
|
|
105 |
" -no-recursive\n"
|
|
106 |
" Do not recursively scan the following directories.\n"
|
|
107 |
" -recursive\n"
|
|
108 |
" Recursively scan the following directories (default).\n"
|
|
109 |
" -I <includepath> or -I<includepath>\n"
|
|
110 |
" Additional location to look for include files.\n"
|
|
111 |
" May be specified multiple times.\n"
|
|
112 |
" -locations {absolute|relative|none}\n"
|
|
113 |
" Specify/override how source code references are saved in TS files.\n"
|
|
114 |
" Default is absolute.\n"
|
|
115 |
" -no-ui-lines\n"
|
|
116 |
" Do not record line numbers in references to UI files.\n"
|
|
117 |
" -disable-heuristic {sametext|similartext|number}\n"
|
|
118 |
" Disable the named merge heuristic. Can be specified multiple times.\n"
|
|
119 |
" -pro <filename>\n"
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
120 |
" Name of a .pro file. Useful for files with .pro file syntax but\n"
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
121 |
" different file suffix. Projects are recursed into and merged.\n"
|
0
|
122 |
" -source-language <language>[_<region>]\n"
|
|
123 |
" Specify the language of the source strings for new files.\n"
|
|
124 |
" Defaults to POSIX if not specified.\n"
|
|
125 |
" -target-language <language>[_<region>]\n"
|
|
126 |
" Specify the language of the translations for new files.\n"
|
|
127 |
" Guessed from the file name if not specified.\n"
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
128 |
" -ts <ts-file>...\n"
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
129 |
" Specify the output file(s). This will override the TRANSLATIONS\n"
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
130 |
" and nullify the CODECFORTR from possibly specified project files.\n"
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
131 |
" -codecfortr <codec>\n"
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
132 |
" Specify the codec assumed for tr() calls. Effective only with -ts.\n"
|
0
|
133 |
" -version\n"
|
|
134 |
" Display the version of lupdate and exit.\n"
|
|
135 |
).arg(m_defaultExtensions));
|
|
136 |
}
|
|
137 |
|
|
138 |
static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFileNames,
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
139 |
bool setCodec, const QString &sourceLanguage, const QString &targetLanguage,
|
0
|
140 |
UpdateOptions options, bool *fail)
|
|
141 |
{
|
|
142 |
QDir dir;
|
|
143 |
QString err;
|
|
144 |
foreach (const QString &fileName, tsFileNames) {
|
|
145 |
QString fn = dir.relativeFilePath(fileName);
|
|
146 |
ConversionData cd;
|
|
147 |
Translator tor;
|
|
148 |
cd.m_sortContexts = !(options & NoSort);
|
|
149 |
if (QFile(fileName).exists()) {
|
|
150 |
if (!tor.load(fileName, cd, QLatin1String("auto"))) {
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
151 |
printErr(cd.error());
|
0
|
152 |
*fail = true;
|
|
153 |
continue;
|
|
154 |
}
|
|
155 |
tor.resolveDuplicates();
|
|
156 |
cd.clearErrors();
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
157 |
if (setCodec && fetchedTor.codec() != tor.codec())
|
0
|
158 |
qWarning("lupdate warning: Codec for tr() '%s' disagrees with "
|
|
159 |
"existing file's codec '%s'. Expect trouble.",
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
160 |
fetchedTor.codecName().constData(), tor.codecName().constData());
|
0
|
161 |
if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode())
|
|
162 |
qWarning("lupdate warning: Specified target language '%s' disagrees with "
|
|
163 |
"existing file's language '%s'. Ignoring.",
|
|
164 |
qPrintable(targetLanguage), qPrintable(tor.languageCode()));
|
|
165 |
if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode())
|
|
166 |
qWarning("lupdate warning: Specified source language '%s' disagrees with "
|
|
167 |
"existing file's language '%s'. Ignoring.",
|
|
168 |
qPrintable(sourceLanguage), qPrintable(tor.sourceLanguageCode()));
|
|
169 |
} else {
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
170 |
if (setCodec)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
171 |
tor.setCodec(fetchedTor.codec());
|
0
|
172 |
if (!targetLanguage.isEmpty())
|
|
173 |
tor.setLanguageCode(targetLanguage);
|
|
174 |
else
|
|
175 |
tor.setLanguageCode(Translator::guessLanguageCodeFromFileName(fileName));
|
|
176 |
if (!sourceLanguage.isEmpty())
|
|
177 |
tor.setSourceLanguageCode(sourceLanguage);
|
|
178 |
}
|
|
179 |
tor.makeFileNamesAbsolute(QFileInfo(fileName).absoluteDir());
|
|
180 |
if (options & NoLocations)
|
|
181 |
tor.setLocationsType(Translator::NoLocations);
|
|
182 |
else if (options & RelativeLocations)
|
|
183 |
tor.setLocationsType(Translator::RelativeLocations);
|
|
184 |
else if (options & AbsoluteLocations)
|
|
185 |
tor.setLocationsType(Translator::AbsoluteLocations);
|
|
186 |
if (options & Verbose)
|
|
187 |
printOut(QObject::tr("Updating '%1'...\n").arg(fn));
|
|
188 |
|
|
189 |
UpdateOptions theseOptions = options;
|
|
190 |
if (tor.locationsType() == Translator::NoLocations) // Could be set from file
|
|
191 |
theseOptions |= NoLocations;
|
|
192 |
Translator out = merge(tor, fetchedTor, theseOptions, err);
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
193 |
if (setCodec)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
194 |
out.setCodec(fetchedTor.codec());
|
0
|
195 |
|
|
196 |
if ((options & Verbose) && !err.isEmpty()) {
|
|
197 |
printOut(err);
|
|
198 |
err.clear();
|
|
199 |
}
|
|
200 |
if (options & PluralOnly) {
|
|
201 |
if (options & Verbose)
|
|
202 |
printOut(QObject::tr("Stripping non plural forms in '%1'...\n").arg(fn));
|
|
203 |
out.stripNonPluralForms();
|
|
204 |
}
|
|
205 |
if (options & NoObsolete)
|
|
206 |
out.stripObsoleteMessages();
|
|
207 |
out.stripEmptyContexts();
|
|
208 |
|
|
209 |
out.normalizeTranslations(cd);
|
|
210 |
if (!cd.errors().isEmpty()) {
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
211 |
printErr(cd.error());
|
0
|
212 |
cd.clearErrors();
|
|
213 |
}
|
|
214 |
if (!out.save(fileName, cd, QLatin1String("auto"))) {
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
215 |
printErr(cd.error());
|
0
|
216 |
*fail = true;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
221 |
static QStringList getSources(const char *var, const char *vvar, const QStringList &baseVPaths,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
222 |
const QString &projectDir, const ProFileEvaluator &visitor)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
223 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
224 |
QStringList vPaths = visitor.absolutePathValues(QLatin1String(vvar), projectDir);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
225 |
vPaths += baseVPaths;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
226 |
vPaths.removeDuplicates();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
227 |
return visitor.absoluteFileValues(QLatin1String(var), projectDir, vPaths, 0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
228 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
229 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
230 |
static QStringList getSources(const ProFileEvaluator &visitor, const QString &projectDir)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
231 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
232 |
QStringList baseVPaths;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
233 |
baseVPaths += visitor.absolutePathValues(QLatin1String("VPATH"), projectDir);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
234 |
baseVPaths << projectDir; // QMAKE_ABSOLUTE_SOURCE_PATH
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
235 |
baseVPaths += visitor.absolutePathValues(QLatin1String("DEPENDPATH"), projectDir);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
236 |
baseVPaths.removeDuplicates();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
237 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
238 |
QStringList sourceFiles;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
239 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
240 |
// app/lib template
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
241 |
sourceFiles += getSources("SOURCES", "VPATH_SOURCES", baseVPaths, projectDir, visitor);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
242 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
243 |
sourceFiles += getSources("FORMS", "VPATH_FORMS", baseVPaths, projectDir, visitor);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
244 |
sourceFiles += getSources("FORMS3", "VPATH_FORMS3", baseVPaths, projectDir, visitor);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
245 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
246 |
QStringList vPathsInc = baseVPaths;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
247 |
vPathsInc += visitor.absolutePathValues(QLatin1String("INCLUDEPATH"), projectDir);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
248 |
vPathsInc.removeDuplicates();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
249 |
sourceFiles += visitor.absoluteFileValues(QLatin1String("HEADERS"), projectDir, vPathsInc, 0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
250 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
251 |
sourceFiles.removeDuplicates();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
252 |
sourceFiles.sort();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
253 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
254 |
return sourceFiles;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
255 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
256 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
257 |
static void processSources(Translator &fetchedTor,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
258 |
const QStringList &sourceFiles, ConversionData &cd)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
259 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
260 |
QStringList sourceFilesCpp;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
261 |
for (QStringList::const_iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
262 |
if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
263 |
loadJava(fetchedTor, *it, cd);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
264 |
else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
265 |
|| it->endsWith(QLatin1String(".jui"), Qt::CaseInsensitive))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
266 |
loadUI(fetchedTor, *it, cd);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
267 |
else if (it->endsWith(QLatin1String(".js"), Qt::CaseInsensitive)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
268 |
|| it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
269 |
loadQScript(fetchedTor, *it, cd);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
270 |
else
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
271 |
sourceFilesCpp << *it;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
272 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
273 |
loadCPP(fetchedTor, sourceFilesCpp, cd);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
274 |
if (!cd.error().isEmpty())
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
275 |
printOut(cd.error());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
276 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
277 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
278 |
static void processProjects(
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
279 |
bool topLevel, bool nestComplain, const QStringList &proFiles,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
280 |
UpdateOptions options, const QByteArray &codecForSource,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
281 |
const QString &targetLanguage, const QString &sourceLanguage,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
282 |
Translator *parentTor, bool *fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
283 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
284 |
static void processProject(
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
285 |
bool nestComplain, const QFileInfo &pfi, ProFileEvaluator &visitor,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
286 |
UpdateOptions options, const QByteArray &_codecForSource,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
287 |
const QString &targetLanguage, const QString &sourceLanguage,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
288 |
Translator *fetchedTor, bool *fail)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
289 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
290 |
QByteArray codecForSource = _codecForSource;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
291 |
QStringList tmp = visitor.values(QLatin1String("CODECFORSRC"));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
292 |
if (!tmp.isEmpty()) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
293 |
codecForSource = tmp.last().toLatin1();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
294 |
if (!QTextCodec::codecForName(codecForSource)) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
295 |
qWarning("lupdate warning: Codec for source '%s' is invalid. "
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
296 |
"Falling back to codec for tr().", codecForSource.constData());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
297 |
codecForSource.clear();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
298 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
299 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
300 |
if (visitor.templateType() == ProFileEvaluator::TT_Subdirs) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
301 |
QStringList subProFiles;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
302 |
QDir proDir(pfi.absoluteDir());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
303 |
foreach (const QString &subdir, visitor.values(QLatin1String("SUBDIRS"))) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
304 |
QString subPro = QDir::cleanPath(proDir.absoluteFilePath(subdir));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
305 |
QFileInfo subInfo(subPro);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
306 |
if (subInfo.isDir())
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
307 |
subProFiles << (subPro + QLatin1Char('/')
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
308 |
+ subInfo.fileName() + QLatin1String(".pro"));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
309 |
else
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
310 |
subProFiles << subPro;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
311 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
312 |
processProjects(false, nestComplain, subProFiles, options, codecForSource,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
313 |
targetLanguage, sourceLanguage, fetchedTor, fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
314 |
} else {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
315 |
ConversionData cd;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
316 |
cd.m_noUiLines = options & NoUiLines;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
317 |
cd.m_codecForSource = codecForSource;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
318 |
cd.m_includePath = visitor.values(QLatin1String("INCLUDEPATH"));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
319 |
QStringList sourceFiles = getSources(visitor, pfi.absolutePath());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
320 |
QSet<QString> sourceDirs;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
321 |
sourceDirs.insert(QDir::cleanPath(pfi.absolutePath()) + QLatin1Char('/'));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
322 |
foreach (const QString &sf, sourceFiles)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
323 |
sourceDirs.insert(sf.left(sf.lastIndexOf(QLatin1Char('/')) + 1));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
324 |
QStringList rootList = sourceDirs.toList();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
325 |
rootList.sort();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
326 |
for (int prev = 0, curr = 1; curr < rootList.length(); )
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
327 |
if (rootList.at(curr).startsWith(rootList.at(prev)))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
328 |
rootList.removeAt(curr);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
329 |
else
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
330 |
prev = curr++;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
331 |
cd.m_projectRoots = QSet<QString>::fromList(rootList);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
332 |
processSources(*fetchedTor, sourceFiles, cd);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
333 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
334 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
335 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
336 |
static void processProjects(
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
337 |
bool topLevel, bool nestComplain, const QStringList &proFiles,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
338 |
UpdateOptions options, const QByteArray &codecForSource,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
339 |
const QString &targetLanguage, const QString &sourceLanguage,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
340 |
Translator *parentTor, bool *fail)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
341 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
342 |
foreach (const QString &proFile, proFiles) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
343 |
ProFileEvaluator visitor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
344 |
visitor.setVerbose(options & Verbose);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
345 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
346 |
QFileInfo pfi(proFile);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
347 |
ProFile pro(pfi.absoluteFilePath());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
348 |
if (!visitor.queryProFile(&pro) || !visitor.accept(&pro)) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
349 |
if (topLevel)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
350 |
*fail = true;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
351 |
continue;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
352 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
353 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
354 |
if (visitor.contains(QLatin1String("TRANSLATIONS"))) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
355 |
if (parentTor) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
356 |
if (topLevel) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
357 |
std::cerr << "lupdate warning: TS files from command line "
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
358 |
"will override TRANSLATIONS in " << qPrintable(proFile) << ".\n";
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
359 |
goto noTrans;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
360 |
} else if (nestComplain) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
361 |
std::cerr << "lupdate warning: TS files from command line "
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
362 |
"prevent recursing into " << qPrintable(proFile) << ".\n";
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
363 |
continue;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
364 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
365 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
366 |
QStringList tsFiles;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
367 |
QDir proDir(pfi.absolutePath());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
368 |
foreach (const QString &tsFile, visitor.values(QLatin1String("TRANSLATIONS")))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
369 |
tsFiles << QFileInfo(proDir, tsFile).filePath();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
370 |
if (tsFiles.isEmpty()) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
371 |
// This might mean either a buggy PRO file or an intentional detach -
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
372 |
// we can't know without seeing the actual RHS of the assignment ...
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
373 |
// Just assume correctness and be silent.
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
374 |
continue;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
375 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
376 |
Translator tor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
377 |
bool setCodec = false;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
378 |
QStringList tmp = visitor.values(QLatin1String("CODEC"))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
379 |
+ visitor.values(QLatin1String("DEFAULTCODEC"))
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
380 |
+ visitor.values(QLatin1String("CODECFORTR"));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
381 |
if (!tmp.isEmpty()) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
382 |
tor.setCodecName(tmp.last().toLatin1());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
383 |
setCodec = true;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
384 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
385 |
processProject(false, pfi, visitor, options, codecForSource,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
386 |
targetLanguage, sourceLanguage, &tor, fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
387 |
updateTsFiles(tor, tsFiles, setCodec, sourceLanguage, targetLanguage, options, fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
388 |
continue;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
389 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
390 |
noTrans:
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
391 |
if (!parentTor) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
392 |
if (topLevel)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
393 |
std::cerr << "lupdate warning: no TS files specified. Only diagnostics "
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
394 |
"will be produced for '" << qPrintable(proFile) << "'.\n";
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
395 |
Translator tor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
396 |
processProject(nestComplain, pfi, visitor, options, codecForSource,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
397 |
targetLanguage, sourceLanguage, &tor, fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
398 |
} else {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
399 |
processProject(nestComplain, pfi, visitor, options, codecForSource,
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
400 |
targetLanguage, sourceLanguage, parentTor, fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
401 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
402 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
403 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
404 |
|
0
|
405 |
int main(int argc, char **argv)
|
|
406 |
{
|
|
407 |
QCoreApplication app(argc, argv);
|
|
408 |
m_defaultExtensions = QLatin1String("ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx");
|
|
409 |
|
|
410 |
QStringList args = app.arguments();
|
|
411 |
QStringList tsFileNames;
|
|
412 |
QStringList proFiles;
|
|
413 |
QMultiHash<QString, QString> allCSources;
|
|
414 |
QSet<QString> projectRoots;
|
|
415 |
QStringList sourceFiles;
|
|
416 |
QStringList includePath;
|
|
417 |
QString targetLanguage;
|
|
418 |
QString sourceLanguage;
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
419 |
QByteArray codecForTr;
|
0
|
420 |
|
|
421 |
UpdateOptions options =
|
|
422 |
Verbose | // verbose is on by default starting with Qt 4.2
|
|
423 |
HeuristicSameText | HeuristicSimilarText | HeuristicNumber;
|
|
424 |
int numFiles = 0;
|
|
425 |
bool metTsFlag = false;
|
|
426 |
bool recursiveScan = true;
|
|
427 |
|
|
428 |
QString extensions = m_defaultExtensions;
|
|
429 |
QSet<QString> extensionsNameFilters;
|
|
430 |
|
|
431 |
for (int i = 1; i < argc; ++i) {
|
|
432 |
QString arg = args.at(i);
|
|
433 |
if (arg == QLatin1String("-help")
|
|
434 |
|| arg == QLatin1String("--help")
|
|
435 |
|| arg == QLatin1String("-h")) {
|
|
436 |
printUsage();
|
|
437 |
return 0;
|
|
438 |
} else if (arg == QLatin1String("-pluralonly")) {
|
|
439 |
options |= PluralOnly;
|
|
440 |
continue;
|
|
441 |
} else if (arg == QLatin1String("-noobsolete")
|
|
442 |
|| arg == QLatin1String("-no-obsolete")) {
|
|
443 |
options |= NoObsolete;
|
|
444 |
continue;
|
|
445 |
} else if (arg == QLatin1String("-silent")) {
|
|
446 |
options &= ~Verbose;
|
|
447 |
continue;
|
|
448 |
} else if (arg == QLatin1String("-target-language")) {
|
|
449 |
++i;
|
|
450 |
if (i == argc) {
|
|
451 |
qWarning("The option -target-language requires a parameter.");
|
|
452 |
return 1;
|
|
453 |
}
|
|
454 |
targetLanguage = args[i];
|
|
455 |
continue;
|
|
456 |
} else if (arg == QLatin1String("-source-language")) {
|
|
457 |
++i;
|
|
458 |
if (i == argc) {
|
|
459 |
qWarning("The option -source-language requires a parameter.");
|
|
460 |
return 1;
|
|
461 |
}
|
|
462 |
sourceLanguage = args[i];
|
|
463 |
continue;
|
|
464 |
} else if (arg == QLatin1String("-disable-heuristic")) {
|
|
465 |
++i;
|
|
466 |
if (i == argc) {
|
|
467 |
qWarning("The option -disable-heuristic requires a parameter.");
|
|
468 |
return 1;
|
|
469 |
}
|
|
470 |
arg = args[i];
|
|
471 |
if (arg == QLatin1String("sametext")) {
|
|
472 |
options &= ~HeuristicSameText;
|
|
473 |
} else if (arg == QLatin1String("similartext")) {
|
|
474 |
options &= ~HeuristicSimilarText;
|
|
475 |
} else if (arg == QLatin1String("number")) {
|
|
476 |
options &= ~HeuristicNumber;
|
|
477 |
} else {
|
|
478 |
qWarning("Invalid heuristic name passed to -disable-heuristic.");
|
|
479 |
return 1;
|
|
480 |
}
|
|
481 |
continue;
|
|
482 |
} else if (arg == QLatin1String("-locations")) {
|
|
483 |
++i;
|
|
484 |
if (i == argc) {
|
|
485 |
qWarning("The option -locations requires a parameter.");
|
|
486 |
return 1;
|
|
487 |
}
|
|
488 |
if (args[i] == QLatin1String("none")) {
|
|
489 |
options |= NoLocations;
|
|
490 |
} else if (args[i] == QLatin1String("relative")) {
|
|
491 |
options |= RelativeLocations;
|
|
492 |
} else if (args[i] == QLatin1String("absolute")) {
|
|
493 |
options |= AbsoluteLocations;
|
|
494 |
} else {
|
|
495 |
qWarning("Invalid parameter passed to -locations.");
|
|
496 |
return 1;
|
|
497 |
}
|
|
498 |
continue;
|
|
499 |
} else if (arg == QLatin1String("-no-ui-lines")) {
|
|
500 |
options |= NoUiLines;
|
|
501 |
continue;
|
|
502 |
} else if (arg == QLatin1String("-verbose")) {
|
|
503 |
options |= Verbose;
|
|
504 |
continue;
|
|
505 |
} else if (arg == QLatin1String("-no-recursive")) {
|
|
506 |
recursiveScan = false;
|
|
507 |
continue;
|
|
508 |
} else if (arg == QLatin1String("-recursive")) {
|
|
509 |
recursiveScan = true;
|
|
510 |
continue;
|
|
511 |
} else if (arg == QLatin1String("-no-sort")
|
|
512 |
|| arg == QLatin1String("-nosort")) {
|
|
513 |
options |= NoSort;
|
|
514 |
continue;
|
|
515 |
} else if (arg == QLatin1String("-version")) {
|
|
516 |
printOut(QObject::tr("lupdate version %1\n").arg(QLatin1String(QT_VERSION_STR)));
|
|
517 |
return 0;
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
518 |
} else if (arg == QLatin1String("-codecfortr")) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
519 |
++i;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
520 |
if (i == argc) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
521 |
qWarning("The -codecfortr option should be followed by a codec name.");
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
522 |
return 1;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
523 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
524 |
codecForTr = args[i].toLatin1();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
525 |
continue;
|
0
|
526 |
} else if (arg == QLatin1String("-ts")) {
|
|
527 |
metTsFlag = true;
|
|
528 |
continue;
|
|
529 |
} else if (arg == QLatin1String("-extensions")) {
|
|
530 |
++i;
|
|
531 |
if (i == argc) {
|
|
532 |
qWarning("The -extensions option should be followed by an extension list.");
|
|
533 |
return 1;
|
|
534 |
}
|
|
535 |
extensions = args[i];
|
|
536 |
continue;
|
|
537 |
} else if (arg == QLatin1String("-pro")) {
|
|
538 |
++i;
|
|
539 |
if (i == argc) {
|
|
540 |
qWarning("The -pro option should be followed by a filename of .pro file.");
|
|
541 |
return 1;
|
|
542 |
}
|
|
543 |
proFiles += args[i];
|
|
544 |
numFiles++;
|
|
545 |
continue;
|
|
546 |
} else if (arg.startsWith(QLatin1String("-I"))) {
|
|
547 |
if (arg.length() == 2) {
|
|
548 |
++i;
|
|
549 |
if (i == argc) {
|
|
550 |
qWarning("The -I option should be followed by a path.");
|
|
551 |
return 1;
|
|
552 |
}
|
|
553 |
includePath += args[i];
|
|
554 |
} else {
|
|
555 |
includePath += args[i].mid(2);
|
|
556 |
}
|
|
557 |
continue;
|
|
558 |
} else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) {
|
|
559 |
qWarning("Unrecognized option '%s'", qPrintable(arg));
|
|
560 |
return 1;
|
|
561 |
}
|
|
562 |
|
|
563 |
if (metTsFlag) {
|
|
564 |
bool found = false;
|
|
565 |
foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) {
|
|
566 |
if (arg.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) {
|
|
567 |
QFileInfo fi(arg);
|
|
568 |
if (!fi.exists() || fi.isWritable()) {
|
|
569 |
tsFileNames.append(QFileInfo(arg).absoluteFilePath());
|
|
570 |
} else {
|
|
571 |
qWarning("lupdate warning: For some reason, '%s' is not writable.\n",
|
|
572 |
qPrintable(arg));
|
|
573 |
}
|
|
574 |
found = true;
|
|
575 |
break;
|
|
576 |
}
|
|
577 |
}
|
|
578 |
if (!found) {
|
|
579 |
qWarning("lupdate error: File '%s' has no recognized extension\n",
|
|
580 |
qPrintable(arg));
|
|
581 |
return 1;
|
|
582 |
}
|
|
583 |
} else if (arg.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive)
|
|
584 |
|| arg.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) {
|
|
585 |
proFiles << arg;
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
586 |
numFiles++;
|
0
|
587 |
} else {
|
|
588 |
QFileInfo fi(arg);
|
|
589 |
if (!fi.exists()) {
|
|
590 |
qWarning("lupdate error: File '%s' does not exists\n", qPrintable(arg));
|
|
591 |
return 1;
|
|
592 |
} else if (fi.isDir()) {
|
|
593 |
if (options & Verbose)
|
|
594 |
printOut(QObject::tr("Scanning directory '%1'...").arg(arg));
|
|
595 |
QDir dir = QDir(fi.filePath());
|
|
596 |
projectRoots.insert(dir.absolutePath() + QLatin1Char('/'));
|
|
597 |
if (extensionsNameFilters.isEmpty()) {
|
|
598 |
foreach (QString ext, extensions.split(QLatin1Char(','))) {
|
|
599 |
ext = ext.trimmed();
|
|
600 |
if (ext.startsWith(QLatin1Char('.')))
|
|
601 |
ext.remove(0, 1);
|
|
602 |
extensionsNameFilters.insert(ext);
|
|
603 |
}
|
|
604 |
}
|
|
605 |
QDir::Filters filters = QDir::Files | QDir::NoSymLinks;
|
|
606 |
if (recursiveScan)
|
|
607 |
filters |= QDir::AllDirs | QDir::NoDotAndDotDot;
|
|
608 |
QFileInfoList fileinfolist;
|
|
609 |
recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist);
|
|
610 |
int scanRootLen = dir.absolutePath().length();
|
|
611 |
foreach (const QFileInfo &fi, fileinfolist) {
|
|
612 |
QString fn = QDir::cleanPath(fi.absoluteFilePath());
|
|
613 |
sourceFiles << fn;
|
|
614 |
|
|
615 |
if (!fn.endsWith(QLatin1String(".java"))
|
|
616 |
&& !fn.endsWith(QLatin1String(".ui"))
|
|
617 |
&& !fn.endsWith(QLatin1String(".js"))
|
|
618 |
&& !fn.endsWith(QLatin1String(".qs"))) {
|
|
619 |
int offset = 0;
|
|
620 |
int depth = 0;
|
|
621 |
do {
|
|
622 |
offset = fn.lastIndexOf(QLatin1Char('/'), offset - 1);
|
|
623 |
QString ffn = fn.mid(offset + 1);
|
|
624 |
allCSources.insert(ffn, fn);
|
|
625 |
} while (++depth < 3 && offset > scanRootLen);
|
|
626 |
}
|
|
627 |
}
|
|
628 |
} else {
|
|
629 |
sourceFiles << QDir::cleanPath(fi.absoluteFilePath());;
|
|
630 |
}
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
631 |
numFiles++;
|
0
|
632 |
}
|
|
633 |
} // for args
|
|
634 |
|
|
635 |
if (numFiles == 0) {
|
|
636 |
printUsage();
|
|
637 |
return 1;
|
|
638 |
}
|
|
639 |
|
5
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
640 |
if (!targetLanguage.isEmpty() && tsFileNames.count() != 1)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
641 |
std::cerr << "lupdate warning: -target-language usually only "
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
642 |
"makes sense with exactly one TS file.\n";
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
643 |
if (!codecForTr.isEmpty() && tsFileNames.isEmpty())
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
644 |
std::cerr << "lupdate warning: -codecfortr has no effect without -ts.\n";
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
645 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
646 |
bool fail = false;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
647 |
if (proFiles.isEmpty()) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
648 |
if (tsFileNames.isEmpty())
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
649 |
std::cerr << "lupdate warning: no TS files specified. "
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
650 |
"Only diagnostics will be produced.\n";
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
651 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
652 |
Translator fetchedTor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
653 |
ConversionData cd;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
654 |
cd.m_noUiLines = options & NoUiLines;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
655 |
cd.m_projectRoots = projectRoots;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
656 |
cd.m_includePath = includePath;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
657 |
cd.m_allCSources = allCSources;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
658 |
fetchedTor.setCodecName(codecForTr);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
659 |
processSources(fetchedTor, sourceFiles, cd);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
660 |
updateTsFiles(fetchedTor, tsFileNames, !codecForTr.isEmpty(),
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
661 |
sourceLanguage, targetLanguage, options, &fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
662 |
} else {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
663 |
if (!sourceFiles.isEmpty() || !includePath.isEmpty()) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
664 |
qWarning("lupdate error: Both project and source files / include paths specified.\n");
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
665 |
return 1;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
666 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
667 |
if (!tsFileNames.isEmpty()) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
668 |
Translator fetchedTor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
669 |
fetchedTor.setCodecName(codecForTr);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
670 |
processProjects(true, true, proFiles, options, QByteArray(),
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
671 |
targetLanguage, sourceLanguage, &fetchedTor, &fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
672 |
updateTsFiles(fetchedTor, tsFileNames, !codecForTr.isEmpty(),
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
673 |
sourceLanguage, targetLanguage, options, &fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
674 |
} else {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
675 |
processProjects(true, false, proFiles, options, QByteArray(),
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
676 |
targetLanguage, sourceLanguage, 0, &fail);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
677 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
678 |
}
|
0
|
679 |
return fail ? 1 : 0;
|
|
680 |
}
|