author | zecke <zecke> | 2003-04-20 17:24:50 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-04-20 17:24:50 (UTC) |
commit | 92c687d281f69085436a77efb8cd1d4d2d9333f8 (patch) (unidiff) | |
tree | 7bbfac3ea310ed140e78cb3c17f8219294cb61d0 /development/translation/opie-lupdate/main.cpp | |
parent | f1f4e6794507d9b8dafb46ce05968a0647a41777 (diff) | |
download | opie-92c687d281f69085436a77efb8cd1d4d2d9333f8.zip opie-92c687d281f69085436a77efb8cd1d4d2d9333f8.tar.gz opie-92c687d281f69085436a77efb8cd1d4d2d9333f8.tar.bz2 |
Initial revision
Diffstat (limited to 'development/translation/opie-lupdate/main.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | development/translation/opie-lupdate/main.cpp | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/development/translation/opie-lupdate/main.cpp b/development/translation/opie-lupdate/main.cpp new file mode 100644 index 0000000..ce65e7a --- a/dev/null +++ b/development/translation/opie-lupdate/main.cpp | |||
@@ -0,0 +1,215 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** Copyright (C) 2003 zecke | ||
4 | ** | ||
5 | ** This file is part of Qt Linguist. | ||
6 | ** | ||
7 | ** This file may be distributed and/or modified under the terms of the | ||
8 | ** GNU General Public License version 2 as published by the Free Software | ||
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
10 | ** packaging of this file. | ||
11 | ** | ||
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
14 | ** | ||
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
16 | ** | ||
17 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
18 | ** not clear to you. | ||
19 | ** | ||
20 | **********************************************************************/ | ||
21 | |||
22 | #include <metatranslator.h> | ||
23 | #include <proparser.h> | ||
24 | #include <opie.h> | ||
25 | |||
26 | #include <qfile.h> | ||
27 | #include <qfileinfo.h> | ||
28 | #include <qstring.h> | ||
29 | #include <qstringlist.h> | ||
30 | #include <qtextstream.h> | ||
31 | |||
32 | #include <errno.h> | ||
33 | #include <string.h> | ||
34 | |||
35 | // defined in fetchtr.cpp | ||
36 | extern void fetchtr_cpp( const char *fileName, MetaTranslator *tor, | ||
37 | const char *defaultContext, bool mustExist ); | ||
38 | extern void fetchtr_ui( const char *fileName, MetaTranslator *tor, | ||
39 | const char *defaultContext, bool mustExist ); | ||
40 | |||
41 | // defined in merge.cpp | ||
42 | extern void merge( MetaTranslator *tor, const MetaTranslator *virginTor, | ||
43 | bool verbose ); | ||
44 | |||
45 | typedef QValueList<MetaTranslatorMessage> TML; | ||
46 | |||
47 | static const char* LUPDATE_VERSION = "0.1"; | ||
48 | |||
49 | static void printUsage() | ||
50 | { | ||
51 | fprintf( stderr, "Usage:\n" | ||
52 | " opie-lupdate [options] project-file\n" | ||
53 | " opie-lupdate [options] source-files -ts ts-files\n" | ||
54 | "Options:\n" | ||
55 | " -opie The OPIE base dir if not supplied $OPIEDIR will be taken\n" | ||
56 | " -help Display this information and exit\n" | ||
57 | " -noobsolete\n" | ||
58 | " Drop all obsolete strings\n" | ||
59 | " -verbose\n" | ||
60 | " Explain what is being done\n" | ||
61 | " -version\n" | ||
62 | " Display the version of lupdate and exit\n" ); | ||
63 | } | ||
64 | |||
65 | static void updateTsFiles( const MetaTranslator& fetchedTor, | ||
66 | const QString& opiedir, | ||
67 | const QStringList& languages, | ||
68 | const QString& basename, | ||
69 | const QString& codec, | ||
70 | bool noObsolete, bool verbose ) | ||
71 | { | ||
72 | QStringList::ConstIterator it = languages.begin(); | ||
73 | for ( ; it != languages.end(); ++it ) { | ||
74 | QString fileName = opiedir + "/i18n/" + (*it) + "/" + basename; | ||
75 | MetaTranslator tor; | ||
76 | tor.load( fileName ); | ||
77 | if ( !codec.isEmpty() ) | ||
78 | tor.setCodec( codec ); | ||
79 | if ( verbose ) | ||
80 | fprintf( stderr, "Updating '%s'...\n", fileName.latin1() ); | ||
81 | merge( &tor, &fetchedTor, verbose ); | ||
82 | if ( noObsolete ) | ||
83 | tor.stripObsoleteMessages(); | ||
84 | tor.stripEmptyContexts(); | ||
85 | if ( !tor.save(fileName) ) | ||
86 | fprintf( stderr, "lupdate error: Cannot save '%s': %s\n", | ||
87 | fileName.latin1(), strerror(errno) ); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | int main( int argc, char **argv ) | ||
92 | { | ||
93 | QString defaultContext = "@default"; | ||
94 | MetaTranslator fetchedTor; | ||
95 | QCString codec; | ||
96 | QStringList tsFileNames; | ||
97 | QString opiedir; | ||
98 | QString translationBase; | ||
99 | QString target; | ||
100 | |||
101 | bool verbose = FALSE; | ||
102 | bool noObsolete = FALSE; | ||
103 | bool metSomething = FALSE; | ||
104 | bool isLib = FALSE; | ||
105 | int numFiles = 0; | ||
106 | |||
107 | int i; | ||
108 | |||
109 | QStringList languageList = OPIE::self()->languageList(opiedir); | ||
110 | |||
111 | for ( i = 1; i < argc; i++ ) { | ||
112 | if ( qstrcmp(argv[i], "-help") == 0 ) { | ||
113 | printUsage(); | ||
114 | return 0; | ||
115 | } else if ( qstrcmp(argv[i], "-noobsolete") == 0 ) { | ||
116 | noObsolete = TRUE; | ||
117 | continue; | ||
118 | } else if ( qstrcmp(argv[i], "-verbose") == 0 ) { | ||
119 | verbose = TRUE; | ||
120 | continue; | ||
121 | } else if ( qstrcmp(argv[i], "-version") == 0 ) { | ||
122 | fprintf( stderr, "lupdate version %s\n", LUPDATE_VERSION ); | ||
123 | return 0; | ||
124 | } else if ( qstrcmp(argv[i], "-opie") == 0 ) { | ||
125 | if( i+1 < argc ) { | ||
126 | opiedir = argv[i+1]; | ||
127 | languageList = OPIE::self()->languageList(opiedir); | ||
128 | } | ||
129 | i++; // UGLY but we want to skip the next argument | ||
130 | continue; | ||
131 | } | ||
132 | |||
133 | numFiles++; | ||
134 | |||
135 | QString fullText; | ||
136 | |||
137 | QFile f( argv[i] ); | ||
138 | if ( !f.open(IO_ReadOnly) ) { | ||
139 | fprintf( stderr, "lupdate error: Cannot open file '%s': %s\n", | ||
140 | argv[i], strerror(errno) ); | ||
141 | return 1; | ||
142 | } | ||
143 | |||
144 | QTextStream t( &f ); | ||
145 | fullText = t.read(); | ||
146 | f.close(); | ||
147 | |||
148 | fetchedTor = MetaTranslator(); | ||
149 | codec.truncate( 0 ); | ||
150 | tsFileNames.clear(); | ||
151 | isLib = FALSE; | ||
152 | |||
153 | QMap<QString, QString> tagMap = proFileTagMap( fullText ); | ||
154 | QMap<QString, QString>::Iterator it; | ||
155 | |||
156 | for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { | ||
157 | QStringList toks = QStringList::split( ' ', it.data() ); | ||
158 | QStringList::Iterator t; | ||
159 | |||
160 | for ( t = toks.begin(); t != toks.end(); ++t ) { | ||
161 | if ( it.key() == "HEADERS" || it.key() == "SOURCES" ) { | ||
162 | fetchtr_cpp( *t, &fetchedTor, defaultContext, TRUE ); | ||
163 | metSomething = TRUE; | ||
164 | } else if ( it.key() == "INTERFACES" || | ||
165 | it.key() == "FORMS" ) { | ||
166 | fetchtr_ui( *t, &fetchedTor, defaultContext, TRUE ); | ||
167 | fetchtr_cpp( *t + ".h", &fetchedTor, defaultContext, | ||
168 | FALSE ); | ||
169 | metSomething = TRUE; | ||
170 | } else if ( it.key() == "TRANSLATIONS" ) { | ||
171 | // we do not care for that attribute anymore | ||
172 | //tsFileNames.append( *t ); | ||
173 | metSomething = TRUE; | ||
174 | } else if ( it.key() == "CODEC" ) { | ||
175 | codec = (*t).latin1(); | ||
176 | } else if ( it.key() == "TARGET" ) { | ||
177 | target = *t; | ||
178 | metSomething = TRUE; | ||
179 | } else if ( it.key() == "TEMPLATE" ) { | ||
180 | if ( (*t).stripWhiteSpace().lower() == "lib" ) | ||
181 | isLib = true; | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | /** | ||
186 | * We know the $OPIEDIR or have opiedir | ||
187 | * we've a list of languages (de,en,gb,foo,bar) | ||
188 | * we've got the TARGET and we no it's the lib | ||
189 | * so let's do that | ||
190 | * $OPIEDIR/language[i]/ifLibAppendLib$TARGET.ts | ||
191 | */ | ||
192 | qWarning("TARGET %s IsLib:%d", target.latin1(), isLib ); | ||
193 | qWarning("LANGS %s", languageList.join(";").latin1() ); | ||
194 | qWarning("OPIEDIR %s", OPIE::self()->opieDir(opiedir).latin1() ); | ||
195 | if (isLib ) | ||
196 | target.prepend("lib"); | ||
197 | target += ".ts"; | ||
198 | updateTsFiles( fetchedTor, OPIE::self()->opieDir(opiedir), | ||
199 | languageList, target, codec, noObsolete, verbose ); | ||
200 | |||
201 | if ( !metSomething ) { | ||
202 | fprintf( stderr, | ||
203 | "lupdate warning: File '%s' does not look like a" | ||
204 | " project file\n", | ||
205 | argv[i] ); | ||
206 | } | ||
207 | |||
208 | } | ||
209 | |||
210 | if ( numFiles == 0 ) { | ||
211 | printUsage(); | ||
212 | return 1; | ||
213 | } | ||
214 | return 0; | ||
215 | } | ||