1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the linguist application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include <metatranslator.h>
30
#include <proparser.h>
34
#include <qfileinfo.h>
36
#include <qstringlist.h>
37
#include <qtextstream.h>
42
// defined in fetchtr.cpp
43
extern void fetchtr_cpp( const char *fileName, MetaTranslator *tor,
44
const char *defaultContext, bool mustExist );
45
extern void fetchtr_ui( const char *fileName, MetaTranslator *tor,
46
const char *defaultContext, bool mustExist );
48
// defined in merge.cpp
49
extern void merge( MetaTranslator *tor, const MetaTranslator *virginTor,
52
typedef QList<MetaTranslatorMessage> TML;
54
static void printUsage()
56
fprintf( stderr, "Usage:\n"
57
" lupdate [options] project-file\n"
58
" lupdate [options] source-files -ts ts-files\n"
60
" -help Display this information and exit\n"
62
" Drop all obsolete strings\n"
64
" Explain what is being done\n"
66
" Display the version of lupdate and exit\n" );
69
static void updateTsFiles( const MetaTranslator& fetchedTor,
70
const QStringList& tsFileNames, const QString& codec,
71
bool noObsolete, bool verbose )
73
QStringList::ConstIterator t = tsFileNames.begin();
74
while ( t != tsFileNames.end() ) {
77
if ( !codec.isEmpty() )
78
tor.setCodec( codec.toLatin1() );
80
fprintf( stderr, "Updating '%s'...\n", (*t).toLatin1().data() );
81
merge( &tor, &fetchedTor, verbose );
83
tor.stripObsoleteMessages();
84
tor.stripEmptyContexts();
86
fprintf( stderr, "lupdate error: Cannot save '%s': %s\n",
87
(*t).toLatin1().constData(), strerror(errno) );
92
int main( int argc, char **argv )
94
QString defaultContext = "@default";
95
MetaTranslator fetchedTor;
97
QStringList tsFileNames;
100
bool noObsolete = false;
101
bool metSomething = false;
103
bool standardSyntax = true;
104
bool metTsFlag = false;
108
for ( i = 1; i < argc; i++ ) {
109
if ( qstrcmp(argv[i], "-ts") == 0 )
110
standardSyntax = false;
113
for ( i = 1; i < argc; i++ ) {
114
if ( qstrcmp(argv[i], "-help") == 0 ) {
117
} else if ( qstrcmp(argv[i], "-noobsolete") == 0 ) {
120
} else if ( qstrcmp(argv[i], "-verbose") == 0 ) {
123
} else if ( qstrcmp(argv[i], "-version") == 0 ) {
124
fprintf( stderr, "lupdate version %s\n", QT_VERSION_STR );
126
} else if ( qstrcmp(argv[i], "-ts") == 0 ) {
137
if ( !f.open(QIODevice::ReadOnly) ) {
138
fprintf( stderr, "lupdate error: Cannot open file '%s': %s\n",
139
argv[i], strerror(errno) );
144
fullText = t.readAll();
148
QString oldDir = QDir::currentPath();
149
QDir::setCurrent( QFileInfo(argv[i]).path() );
151
if ( standardSyntax ) {
152
fetchedTor = MetaTranslator();
156
QMap<QString, QString> tagMap = proFileTagMap( fullText );
157
QMap<QString, QString>::Iterator it;
159
for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
160
QStringList toks = it.value().split(' ');
161
QStringList::Iterator t;
163
for ( t = toks.begin(); t != toks.end(); ++t ) {
164
if ( it.key() == "HEADERS" || it.key() == "SOURCES" ) {
165
fetchtr_cpp( (*t).toAscii(), &fetchedTor, defaultContext.toAscii(), true );
167
} else if ( it.key() == "INTERFACES" ||
168
it.key() == "FORMS" ) {
169
fetchtr_ui( (*t).toAscii(), &fetchedTor, defaultContext.toAscii(), true );
170
fetchtr_cpp( (*t).toAscii() + ".h", &fetchedTor, defaultContext.toAscii(), false );
172
} else if ( it.key() == "TRANSLATIONS" ) {
173
tsFileNames.append( *t );
175
} else if ( it.key() == "CODEC" ||
176
it.key() == "DEFAULTCODEC" ) {
177
codec = (*t).toLatin1();
182
updateTsFiles( fetchedTor, tsFileNames, codec, noObsolete,
185
if ( !metSomething ) {
187
"lupdate warning: File '%s' does not look like a"
190
} else if ( tsFileNames.isEmpty() ) {
192
"lupdate warning: Met no 'TRANSLATIONS' entry in"
193
" project file '%s'\n",
198
if ( QString(argv[i]).toLower().endsWith(".ts") ) {
199
QFileInfo fi( argv[i] );
200
if ( !fi.exists() || fi.isWritable() ) {
201
tsFileNames.append( argv[i] );
204
"lupdate warning: For some reason, I cannot"
210
"lupdate error: File '%s' lacks .ts extension\n",
214
QFileInfo fi(argv[i]);
215
if ( QString(argv[i]).toLower().endsWith(".ui") ) {
216
fetchtr_ui( fi.fileName().toAscii(), &fetchedTor, defaultContext.toAscii(), true );
217
fetchtr_cpp( fi.fileName().toAscii() + ".h", &fetchedTor,
218
defaultContext.toAscii(), false );
220
fetchtr_cpp( fi.fileName().toAscii(), &fetchedTor, defaultContext.toAscii(), true );
224
QDir::setCurrent( oldDir );
227
if ( !standardSyntax )
228
updateTsFiles( fetchedTor, tsFileNames, codec, noObsolete, verbose );
230
if ( numFiles == 0 ) {