author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
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
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
#include <iostream> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
|
0 | 58 |
static QString m_defaultExtensions; |
59 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
static void printErr(const QString & out) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
qWarning("%s", qPrintable(out)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
|
0 | 65 |
static void printOut(const QString & out) |
66 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
120 |
" Name of a .pro file. Useful for files with .pro file syntax but\n" |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
128 |
" -ts <ts-file>...\n" |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
129 |
" Specify the output file(s). This will override the TRANSLATIONS\n" |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
130 |
" and nullify the CODECFORTR from possibly specified project files.\n" |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
131 |
" -codecfortr <codec>\n" |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
printErr(cd.error()); |
0 | 152 |
*fail = true; |
153 |
continue; |
|
154 |
} |
|
155 |
tor.resolveDuplicates(); |
|
156 |
cd.clearErrors(); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
170 |
if (setCodec) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
193 |
if (setCodec) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
printErr(cd.error()); |
0 | 212 |
cd.clearErrors(); |
213 |
} |
|
214 |
if (!out.save(fileName, cd, QLatin1String("auto"))) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
printErr(cd.error()); |
0 | 216 |
*fail = true; |
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
221 |
static QStringList getSources(const char *var, const char *vvar, const QStringList &baseVPaths, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
222 |
const QString &projectDir, const ProFileEvaluator &visitor) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
223 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
224 |
QStringList vPaths = visitor.absolutePathValues(QLatin1String(vvar), projectDir); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
225 |
vPaths += baseVPaths; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
226 |
vPaths.removeDuplicates(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
227 |
return visitor.absoluteFileValues(QLatin1String(var), projectDir, vPaths, 0); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
228 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
229 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
230 |
static QStringList getSources(const ProFileEvaluator &visitor, const QString &projectDir) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
231 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
232 |
QStringList baseVPaths; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
233 |
baseVPaths += visitor.absolutePathValues(QLatin1String("VPATH"), projectDir); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
234 |
baseVPaths << projectDir; // QMAKE_ABSOLUTE_SOURCE_PATH |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
235 |
baseVPaths += visitor.absolutePathValues(QLatin1String("DEPENDPATH"), projectDir); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
236 |
baseVPaths.removeDuplicates(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
237 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
238 |
QStringList sourceFiles; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
239 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
240 |
// app/lib template |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
241 |
sourceFiles += getSources("SOURCES", "VPATH_SOURCES", baseVPaths, projectDir, visitor); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
242 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
243 |
sourceFiles += getSources("FORMS", "VPATH_FORMS", baseVPaths, projectDir, visitor); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
244 |
sourceFiles += getSources("FORMS3", "VPATH_FORMS3", baseVPaths, projectDir, visitor); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
245 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
246 |
QStringList vPathsInc = baseVPaths; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
247 |
vPathsInc += visitor.absolutePathValues(QLatin1String("INCLUDEPATH"), projectDir); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
248 |
vPathsInc.removeDuplicates(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
249 |
sourceFiles += visitor.absoluteFileValues(QLatin1String("HEADERS"), projectDir, vPathsInc, 0); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
250 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
251 |
sourceFiles.removeDuplicates(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
252 |
sourceFiles.sort(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
253 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
254 |
return sourceFiles; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
255 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
256 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
257 |
static void processSources(Translator &fetchedTor, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
258 |
const QStringList &sourceFiles, ConversionData &cd) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
259 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
260 |
QStringList sourceFilesCpp; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
261 |
for (QStringList::const_iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
262 |
if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
263 |
loadJava(fetchedTor, *it, cd); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
264 |
else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
265 |
|| it->endsWith(QLatin1String(".jui"), Qt::CaseInsensitive)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
266 |
loadUI(fetchedTor, *it, cd); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
267 |
else if (it->endsWith(QLatin1String(".js"), Qt::CaseInsensitive) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
268 |
|| it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
269 |
loadQScript(fetchedTor, *it, cd); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
270 |
else |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
271 |
sourceFilesCpp << *it; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
272 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
273 |
loadCPP(fetchedTor, sourceFilesCpp, cd); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
274 |
if (!cd.error().isEmpty()) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
275 |
printOut(cd.error()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
276 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
277 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
278 |
static void processProjects( |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
279 |
bool topLevel, bool nestComplain, const QStringList &proFiles, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
280 |
UpdateOptions options, const QByteArray &codecForSource, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
281 |
const QString &targetLanguage, const QString &sourceLanguage, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
282 |
Translator *parentTor, bool *fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
283 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
284 |
static void processProject( |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
285 |
bool nestComplain, const QFileInfo &pfi, ProFileEvaluator &visitor, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
286 |
UpdateOptions options, const QByteArray &_codecForSource, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
287 |
const QString &targetLanguage, const QString &sourceLanguage, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
288 |
Translator *fetchedTor, bool *fail) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
289 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
290 |
QByteArray codecForSource = _codecForSource; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
291 |
QStringList tmp = visitor.values(QLatin1String("CODECFORSRC")); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
292 |
if (!tmp.isEmpty()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
293 |
codecForSource = tmp.last().toLatin1(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
294 |
if (!QTextCodec::codecForName(codecForSource)) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
295 |
qWarning("lupdate warning: Codec for source '%s' is invalid. " |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
296 |
"Falling back to codec for tr().", codecForSource.constData()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
297 |
codecForSource.clear(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
298 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
299 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
300 |
if (visitor.templateType() == ProFileEvaluator::TT_Subdirs) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
301 |
QStringList subProFiles; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
302 |
QDir proDir(pfi.absoluteDir()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
303 |
foreach (const QString &subdir, visitor.values(QLatin1String("SUBDIRS"))) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
304 |
QString subPro = QDir::cleanPath(proDir.absoluteFilePath(subdir)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
305 |
QFileInfo subInfo(subPro); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
306 |
if (subInfo.isDir()) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
307 |
subProFiles << (subPro + QLatin1Char('/') |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
308 |
+ subInfo.fileName() + QLatin1String(".pro")); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
309 |
else |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
310 |
subProFiles << subPro; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
311 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
312 |
processProjects(false, nestComplain, subProFiles, options, codecForSource, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
313 |
targetLanguage, sourceLanguage, fetchedTor, fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
314 |
} else { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
315 |
ConversionData cd; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
316 |
cd.m_noUiLines = options & NoUiLines; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
317 |
cd.m_codecForSource = codecForSource; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
318 |
cd.m_includePath = visitor.values(QLatin1String("INCLUDEPATH")); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
319 |
QStringList sourceFiles = getSources(visitor, pfi.absolutePath()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
320 |
QSet<QString> sourceDirs; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
321 |
sourceDirs.insert(QDir::cleanPath(pfi.absolutePath()) + QLatin1Char('/')); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
322 |
foreach (const QString &sf, sourceFiles) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
323 |
sourceDirs.insert(sf.left(sf.lastIndexOf(QLatin1Char('/')) + 1)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
324 |
QStringList rootList = sourceDirs.toList(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
325 |
rootList.sort(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
326 |
for (int prev = 0, curr = 1; curr < rootList.length(); ) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
327 |
if (rootList.at(curr).startsWith(rootList.at(prev))) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
328 |
rootList.removeAt(curr); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
329 |
else |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
330 |
prev = curr++; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
331 |
cd.m_projectRoots = QSet<QString>::fromList(rootList); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
332 |
processSources(*fetchedTor, sourceFiles, cd); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
333 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
334 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
335 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
336 |
static void processProjects( |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
337 |
bool topLevel, bool nestComplain, const QStringList &proFiles, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
338 |
UpdateOptions options, const QByteArray &codecForSource, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
339 |
const QString &targetLanguage, const QString &sourceLanguage, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
340 |
Translator *parentTor, bool *fail) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
341 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
342 |
foreach (const QString &proFile, proFiles) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
343 |
ProFileEvaluator visitor; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
344 |
visitor.setVerbose(options & Verbose); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
345 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
346 |
QFileInfo pfi(proFile); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
347 |
ProFile pro(pfi.absoluteFilePath()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
348 |
if (!visitor.queryProFile(&pro) || !visitor.accept(&pro)) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
349 |
if (topLevel) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
350 |
*fail = true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
351 |
continue; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
352 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
353 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
354 |
if (visitor.contains(QLatin1String("TRANSLATIONS"))) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
355 |
if (parentTor) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
356 |
if (topLevel) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
357 |
std::cerr << "lupdate warning: TS files from command line " |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
358 |
"will override TRANSLATIONS in " << qPrintable(proFile) << ".\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
359 |
goto noTrans; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
360 |
} else if (nestComplain) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
361 |
std::cerr << "lupdate warning: TS files from command line " |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
362 |
"prevent recursing into " << qPrintable(proFile) << ".\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
363 |
continue; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
364 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
365 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
366 |
QStringList tsFiles; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
367 |
QDir proDir(pfi.absolutePath()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
368 |
foreach (const QString &tsFile, visitor.values(QLatin1String("TRANSLATIONS"))) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
369 |
tsFiles << QFileInfo(proDir, tsFile).filePath(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
370 |
if (tsFiles.isEmpty()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
371 |
// This might mean either a buggy PRO file or an intentional detach - |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
372 |
// we can't know without seeing the actual RHS of the assignment ... |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
373 |
// Just assume correctness and be silent. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
374 |
continue; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
375 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
376 |
Translator tor; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
377 |
bool setCodec = false; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
378 |
QStringList tmp = visitor.values(QLatin1String("CODEC")) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
379 |
+ visitor.values(QLatin1String("DEFAULTCODEC")) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
380 |
+ visitor.values(QLatin1String("CODECFORTR")); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
381 |
if (!tmp.isEmpty()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
382 |
tor.setCodecName(tmp.last().toLatin1()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
383 |
setCodec = true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
384 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
385 |
processProject(false, pfi, visitor, options, codecForSource, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
386 |
targetLanguage, sourceLanguage, &tor, fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
387 |
updateTsFiles(tor, tsFiles, setCodec, sourceLanguage, targetLanguage, options, fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
388 |
continue; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
389 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
390 |
noTrans: |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
391 |
if (!parentTor) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
392 |
if (topLevel) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
393 |
std::cerr << "lupdate warning: no TS files specified. Only diagnostics " |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
394 |
"will be produced for '" << qPrintable(proFile) << "'.\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
395 |
Translator tor; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
396 |
processProject(nestComplain, pfi, visitor, options, codecForSource, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
397 |
targetLanguage, sourceLanguage, &tor, fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
398 |
} else { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
399 |
processProject(nestComplain, pfi, visitor, options, codecForSource, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
400 |
targetLanguage, sourceLanguage, parentTor, fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
401 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
402 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
403 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
518 |
} else if (arg == QLatin1String("-codecfortr")) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
519 |
++i; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
520 |
if (i == argc) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
521 |
qWarning("The -codecfortr option should be followed by a codec name."); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
522 |
return 1; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
523 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
524 |
codecForTr = args[i].toLatin1(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
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
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
631 |
numFiles++; |
0 | 632 |
} |
633 |
} // for args |
|
634 |
||
635 |
if (numFiles == 0) { |
|
636 |
printUsage(); |
|
637 |
return 1; |
|
638 |
} |
|
639 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
640 |
if (!targetLanguage.isEmpty() && tsFileNames.count() != 1) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
641 |
std::cerr << "lupdate warning: -target-language usually only " |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
642 |
"makes sense with exactly one TS file.\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
643 |
if (!codecForTr.isEmpty() && tsFileNames.isEmpty()) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
644 |
std::cerr << "lupdate warning: -codecfortr has no effect without -ts.\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
645 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
646 |
bool fail = false; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
647 |
if (proFiles.isEmpty()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
648 |
if (tsFileNames.isEmpty()) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
649 |
std::cerr << "lupdate warning: no TS files specified. " |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
650 |
"Only diagnostics will be produced.\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
651 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
652 |
Translator fetchedTor; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
653 |
ConversionData cd; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
654 |
cd.m_noUiLines = options & NoUiLines; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
655 |
cd.m_projectRoots = projectRoots; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
656 |
cd.m_includePath = includePath; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
657 |
cd.m_allCSources = allCSources; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
658 |
fetchedTor.setCodecName(codecForTr); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
659 |
processSources(fetchedTor, sourceFiles, cd); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
660 |
updateTsFiles(fetchedTor, tsFileNames, !codecForTr.isEmpty(), |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
661 |
sourceLanguage, targetLanguage, options, &fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
662 |
} else { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
663 |
if (!sourceFiles.isEmpty() || !includePath.isEmpty()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
664 |
qWarning("lupdate error: Both project and source files / include paths specified.\n"); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
665 |
return 1; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
666 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
667 |
if (!tsFileNames.isEmpty()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
668 |
Translator fetchedTor; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
669 |
fetchedTor.setCodecName(codecForTr); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
670 |
processProjects(true, true, proFiles, options, QByteArray(), |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
671 |
targetLanguage, sourceLanguage, &fetchedTor, &fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
672 |
updateTsFiles(fetchedTor, tsFileNames, !codecForTr.isEmpty(), |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
673 |
sourceLanguage, targetLanguage, options, &fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
674 |
} else { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
675 |
processProjects(true, false, proFiles, options, QByteArray(), |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
676 |
targetLanguage, sourceLanguage, 0, &fail); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
677 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
678 |
} |
0 | 679 |
return fail ? 1 : 0; |
680 |
} |