00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <metatranslator.h>
00023 #include <proparser.h>
00024 #include <opie.h>
00025
00026 #include <qfile.h>
00027 #include <qfileinfo.h>
00028 #include <qstring.h>
00029 #include <qstringlist.h>
00030 #include <qtextstream.h>
00031
00032 #include <errno.h>
00033 #include <string.h>
00034
00035
00036 extern void fetchtr_cpp( const char *fileName, MetaTranslator *tor,
00037 const char *defaultContext, bool mustExist );
00038 extern void fetchtr_ui( const char *fileName, MetaTranslator *tor,
00039 const char *defaultContext, bool mustExist );
00040
00041
00042 extern void merge( MetaTranslator *tor, const MetaTranslator *virginTor,
00043 bool verbose );
00044
00045 typedef QValueList<MetaTranslatorMessage> TML;
00046
00047 static const char* LUPDATE_VERSION = "0.1";
00048
00049 static void printUsage()
00050 {
00051 fprintf( stderr, "Usage:\n"
00052 " opie-lupdate [options] project-file\n"
00053 " opie-lupdate [options] source-files -ts ts-files\n"
00054 "Options:\n"
00055 " -opie The OPIE base dir if not supplied $OPIEDIR will be taken\n"
00056 " -help Display this information and exit\n"
00057 " -noobsolete\n"
00058 " Drop all obsolete strings\n"
00059 " -verbose\n"
00060 " Explain what is being done\n"
00061 " -version\n"
00062 " Display the version of lupdate and exit\n" );
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 static void updateTsFiles( const MetaTranslator& fetchedTor,
00075 const QString& opiedir,
00076 const QStringList& languages,
00077 const QString& basename,
00078 const QString& codec,
00079 bool noObsolete, bool verbose )
00080 {
00081 QStringList::ConstIterator it = languages.begin();
00082 for ( ; it != languages.end(); ++it ) {
00083 QString fileName = opiedir + "/i18n/" + (*it) + "/" + basename;
00084 MetaTranslator tor;
00085 tor.load( fileName );
00086 if ( !codec.isEmpty() )
00087 tor.setCodec( codec );
00088 if ( verbose )
00089 fprintf( stderr, "Updating '%s'...\n", fileName.latin1() );
00090 merge( &tor, &fetchedTor, verbose );
00091 if ( noObsolete )
00092 tor.stripObsoleteMessages();
00093 tor.stripEmptyContexts();
00094 if ( !tor.save(fileName) )
00095 fprintf( stderr, "lupdate error: Cannot save '%s': %s\n",
00096 fileName.latin1(), strerror(errno) );
00097 }
00098 }
00099
00100 int main( int argc, char **argv )
00101 {
00102 QString defaultContext = "@default";
00103 MetaTranslator fetchedTor;
00104 QCString codec;
00105 QStringList tsFileNames;
00106 QString opiedir;
00107 QString translationBase;
00108 QString target;
00109
00110 bool verbose = FALSE;
00111 bool noObsolete = FALSE;
00112 bool metSomething = FALSE;
00113 bool isLib = FALSE;
00114 int numFiles = 0;
00115
00116 int i;
00117
00118 QStringList languageList = OPIE::self()->languageList(opiedir);
00119
00120 for ( i = 1; i < argc; i++ ) {
00121 if ( qstrcmp(argv[i], "-help") == 0 ) {
00122 printUsage();
00123 return 0;
00124 } else if ( qstrcmp(argv[i], "-noobsolete") == 0 ) {
00125 noObsolete = TRUE;
00126 continue;
00127 } else if ( qstrcmp(argv[i], "-verbose") == 0 ) {
00128 verbose = TRUE;
00129 continue;
00130 } else if ( qstrcmp(argv[i], "-version") == 0 ) {
00131 fprintf( stderr, "lupdate version %s\n", LUPDATE_VERSION );
00132 return 0;
00133 } else if ( qstrcmp(argv[i], "-opie") == 0 ) {
00134 if( i+1 < argc ) {
00135 opiedir = argv[i+1];
00136 languageList = OPIE::self()->languageList(opiedir);
00137 }
00138 i++;
00139 continue;
00140 }
00141
00142 numFiles++;
00143
00144 QString fullText;
00145
00146 QFile f( argv[i] );
00147 if ( !f.open(IO_ReadOnly) ) {
00148 fprintf( stderr, "lupdate error: Cannot open file '%s': %s\n",
00149 argv[i], strerror(errno) );
00150 return 1;
00151 }
00152
00153 QTextStream t( &f );
00154 fullText = t.read();
00155 f.close();
00156
00157 fetchedTor = MetaTranslator();
00158 codec.truncate( 0 );
00159 tsFileNames.clear();
00160 isLib = FALSE;
00161
00162 QMap<QString, QString> tagMap = proFileTagMap( fullText, OPIE::self()->opieDir() );
00163 QMap<QString, QString>::Iterator it;
00164
00165 for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
00166 QStringList toks = QStringList::split( ' ', it.data() );
00167 QStringList::Iterator t;
00168
00169 for ( t = toks.begin(); t != toks.end(); ++t ) {
00170 if ( it.key() == "HEADERS" || it.key() == "SOURCES" ) {
00171 fetchtr_cpp( *t, &fetchedTor, defaultContext, TRUE );
00172 metSomething = TRUE;
00173 } else if ( it.key() == "INTERFACES" ||
00174 it.key() == "FORMS" ) {
00175 fetchtr_ui( *t, &fetchedTor, defaultContext, TRUE );
00176 fetchtr_cpp( *t + ".h", &fetchedTor, defaultContext,
00177 FALSE );
00178 metSomething = TRUE;
00179 } else if ( it.key() == "TRANSLATIONS" ) {
00180
00181
00182 metSomething = TRUE;
00183 } else if ( it.key() == "CODEC" ) {
00184 codec = (*t).latin1();
00185 } else if ( it.key() == "TARGET" ) {
00186 target = *t;
00187 metSomething = TRUE;
00188 } else if ( it.key() == "TEMPLATE" ) {
00189 if ( (*t).stripWhiteSpace().lower() == "lib" )
00190 isLib = true;
00191 }
00192 }
00193 }
00201 qWarning("TARGET %s IsLib:%d", target.latin1(), isLib );
00202 qWarning("LANGS %s", languageList.join(";").latin1() );
00203 qWarning("OPIEDIR %s", OPIE::self()->opieDir(opiedir).latin1() );
00204 if (isLib )
00205 target.prepend("lib");
00206 target += ".ts";
00207 updateTsFiles( fetchedTor, OPIE::self()->opieDir(opiedir),
00208 languageList, target, codec, noObsolete, verbose );
00209
00210 if ( !metSomething ) {
00211 fprintf( stderr,
00212 "lupdate warning: File '%s' does not look like a"
00213 " project file\n",
00214 argv[i] );
00215 }
00216
00217 }
00218
00219 if ( numFiles == 0 ) {
00220 printUsage();
00221 return 1;
00222 }
00223 return 0;
00224 }