1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the Qt Linguist of the Qt Toolkit. |
7 ** This file is part of the Qt Linguist of the Qt Toolkit. |
8 ** |
8 ** |
38 ** $QT_END_LICENSE$ |
38 ** $QT_END_LICENSE$ |
39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include "translator.h" |
42 #include "translator.h" |
43 #include "proreader.h" |
43 #include "profileevaluator.h" |
44 |
44 |
45 #ifndef QT_BOOTSTRAPPED |
45 #ifndef QT_BOOTSTRAPPED |
46 #include <QtCore/QCoreApplication> |
46 #include <QtCore/QCoreApplication> |
47 #include <QtCore/QTranslator> |
47 #include <QtCore/QTranslator> |
48 #endif |
48 #endif |
109 qWarning("lrelease error: %s\n", qPrintable(cd.error())); |
109 qWarning("lrelease error: %s\n", qPrintable(cd.error())); |
110 } else { |
110 } else { |
111 if (!cd.errors().isEmpty()) |
111 if (!cd.errors().isEmpty()) |
112 printOut(cd.error()); |
112 printOut(cd.error()); |
113 } |
113 } |
|
114 cd.clearErrors(); |
114 return ok; |
115 return ok; |
115 } |
116 } |
116 |
117 |
117 static bool releaseTranslator(Translator &tor, const QString &qmFileName, |
118 static bool releaseTranslator(Translator &tor, const QString &qmFileName, |
118 ConversionData &cd, bool removeIdentical) |
119 ConversionData &cd, bool removeIdentical) |
139 file.close(); |
140 file.close(); |
140 |
141 |
141 if (!ok) { |
142 if (!ok) { |
142 qWarning("lrelease error: cannot save '%s': %s\n", |
143 qWarning("lrelease error: cannot save '%s': %s\n", |
143 qPrintable(qmFileName), qPrintable(cd.error())); |
144 qPrintable(qmFileName), qPrintable(cd.error())); |
144 return false; |
|
145 } else if (!cd.errors().isEmpty()) { |
145 } else if (!cd.errors().isEmpty()) { |
146 printOut(cd.error()); |
146 printOut(cd.error()); |
147 } |
147 } |
148 return true; |
148 cd.clearErrors(); |
|
149 return ok; |
149 } |
150 } |
150 |
151 |
151 static bool releaseTsFile(const QString& tsFileName, |
152 static bool releaseTsFile(const QString& tsFileName, |
152 ConversionData &cd, bool removeIdentical) |
153 ConversionData &cd, bool removeIdentical) |
153 { |
154 { |
243 } |
244 } |
244 |
245 |
245 foreach (const QString &inputFile, inputFiles) { |
246 foreach (const QString &inputFile, inputFiles) { |
246 if (inputFile.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) |
247 if (inputFile.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) |
247 || inputFile.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { |
248 || inputFile.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { |
248 QHash<QByteArray, QStringList> varMap; |
249 QFileInfo fi(inputFile); |
249 bool ok = evaluateProFile(inputFile, cd.isVerbose(), &varMap); |
250 ProFile pro(fi.absoluteFilePath()); |
250 if (ok) { |
251 |
251 QStringList translations = varMap.value("TRANSLATIONS"); |
252 ProFileEvaluator visitor; |
252 if (translations.isEmpty()) { |
253 visitor.setVerbose(cd.isVerbose()); |
253 qWarning("lrelease warning: Met no 'TRANSLATIONS' entry in" |
254 |
254 " project file '%s'\n", |
255 if (!visitor.queryProFile(&pro)) { |
255 qPrintable(inputFile)); |
256 qWarning("lrelease error: cannot read project file '%s'.", qPrintable(inputFile)); |
256 } else { |
257 continue; |
257 foreach (const QString &trans, translations) |
258 } |
258 if (!releaseTsFile(trans, cd, removeIdentical)) |
259 if (!visitor.accept(&pro)) { |
259 return 1; |
260 qWarning("lrelease error: cannot process project file '%s'.", qPrintable(inputFile)); |
260 } |
261 continue; |
|
262 } |
|
263 |
|
264 QStringList translations = visitor.values(QLatin1String("TRANSLATIONS")); |
|
265 if (translations.isEmpty()) { |
|
266 qWarning("lrelease warning: Met no 'TRANSLATIONS' entry in" |
|
267 " project file '%s'\n", |
|
268 qPrintable(inputFile)); |
261 } else { |
269 } else { |
262 qWarning("error: lrelease encountered project file functionality that is currently not supported.\n" |
270 QDir proDir(fi.absolutePath()); |
263 "You might want to consider using TS files as input instead of a project file.\n" |
271 foreach (const QString &trans, translations) |
264 "Try the following syntax:\n" |
272 if (!releaseTsFile(QFileInfo(proDir, trans).filePath(), cd, removeIdentical)) |
265 " lrelease [options] ts-files [-qm qm-file]\n"); |
273 return 1; |
266 } |
274 } |
267 } else { |
275 } else { |
268 if (outputFile.isEmpty()) { |
276 if (outputFile.isEmpty()) { |
269 if (!releaseTsFile(inputFile, cd, removeIdentical)) |
277 if (!releaseTsFile(inputFile, cd, removeIdentical)) |
270 return 1; |
278 return 1; |