-rw-r--r-- | development/translation/opie-lupdate/fetchtr.cpp | 55 | ||||
-rw-r--r-- | development/translation/opie-lupdate/main.cpp | 11 | ||||
-rw-r--r-- | development/translation/opie-lupdate/merge.cpp | 6 | ||||
-rw-r--r-- | development/translation/opie-lupdate/numberh.cpp | 28 | ||||
-rw-r--r-- | development/translation/opie-lupdate/sametexth.cpp | 6 | ||||
-rw-r--r-- | development/translation/shared/metatranslator.cpp | 34 | ||||
-rw-r--r-- | development/translation/shared/metatranslator.h | 16 | ||||
-rw-r--r-- | development/translation/shared/opie.h | 2 | ||||
-rw-r--r-- | development/translation/shared/proparser.cpp | 111 | ||||
-rw-r--r-- | development/translation/shared/proparser.h | 8 |
10 files changed, 228 insertions, 49 deletions
diff --git a/development/translation/opie-lupdate/fetchtr.cpp b/development/translation/opie-lupdate/fetchtr.cpp index d1f5881..a137628 100644 --- a/development/translation/opie-lupdate/fetchtr.cpp +++ b/development/translation/opie-lupdate/fetchtr.cpp @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** @@ -82,2 +88,3 @@ static size_t yyStringLen; static QValueStack<int> yySavedBraceDepth; +static QValueStack<int> yySavedParenDepth; static int yyBraceDepth; @@ -86,2 +93,4 @@ static int yyLineNo; static int yyCurLineNo; +static int yyBraceLineNo; +static int yyParenLineNo; @@ -121,2 +130,3 @@ static void startTokenizer( const char *fileName, int (*getCharFunc)() ) yySavedBraceDepth.clear(); + yySavedParenDepth.clear(); yyBraceDepth = 0; @@ -124,2 +134,4 @@ static void startTokenizer( const char *fileName, int (*getCharFunc)() ) yyCurLineNo = 1; + yyBraceLineNo = 1; + yyParenLineNo = 1; } @@ -166,2 +178,15 @@ static int getToken() break; + case 'f': + /* + QTranslator::findMessage() has the same parameters as + QApplication::translate(). + */ + if ( strcmp(yyIdent + 1, "indMessage") == 0 ) + return Tok_translate; + break; + case 'i': + /* FOR KDE APPS */ + if ( strcmp( yyIdent + 1, "8n") == 0 ) + return Tok_translate; + break; case 'n': @@ -178,5 +203,2 @@ static int getToken() break; - case 'i': - if( strcmp(yyIdent + 1, "18n") == 0 ) - return Tok_tr; case 't': @@ -224,2 +246,3 @@ static int getToken() yySavedBraceDepth.push( yyBraceDepth ); + yySavedParenDepth.push( yyParenDepth ); } @@ -230,8 +253,12 @@ static int getToken() // elif, else - if ( !yySavedBraceDepth.isEmpty() ) + if ( !yySavedBraceDepth.isEmpty() ) { yyBraceDepth = yySavedBraceDepth.top(); + yyParenDepth = yySavedParenDepth.top(); + } } else if ( yyCh == 'n' ) { // endif - if ( !yySavedBraceDepth.isEmpty() ) + if ( !yySavedBraceDepth.isEmpty() ) { yySavedBraceDepth.pop(); + yySavedParenDepth.pop(); + } } @@ -358,2 +385,4 @@ static int getToken() case '{': + if (yyBraceDepth == 0) + yyBraceLineNo = yyCurLineNo; yyBraceDepth++; @@ -362,2 +391,4 @@ static int getToken() case '}': + if (yyBraceDepth == 0) + yyBraceLineNo = yyCurLineNo; yyBraceDepth--; @@ -366,2 +397,4 @@ static int getToken() case '(': + if (yyParenDepth == 0) + yyParenLineNo = yyCurLineNo; yyParenDepth++; @@ -370,2 +403,4 @@ static int getToken() case ')': + if (yyParenDepth == 0) + yyParenLineNo = yyCurLineNo; yyParenDepth--; @@ -623,10 +658,10 @@ static void parse( MetaTranslator *tor, const char *initialContext, fprintf( stderr, - "%s: Unbalanced braces in C++ code (or abuse of the C++" + "%s:%d: Unbalanced braces in C++ code (or abuse of the C++" " preprocessor)\n", - (const char *) yyFileName ); - if ( yyParenDepth != 0 ) + (const char *)yyFileName, yyBraceLineNo ); + else if ( yyParenDepth != 0 ) fprintf( stderr, - "%s: Unbalanced parentheses in C++ code (or abuse of the C++" + "%s:%d: Unbalanced parentheses in C++ code (or abuse of the C++" " preprocessor)\n", - (const char *) yyFileName ); + (const char *)yyFileName, yyParenLineNo ); } diff --git a/development/translation/opie-lupdate/main.cpp b/development/translation/opie-lupdate/main.cpp index ce65e7a..bf16fd7 100644 --- a/development/translation/opie-lupdate/main.cpp +++ b/development/translation/opie-lupdate/main.cpp @@ -64,2 +64,11 @@ static void printUsage() +/*static QString opie_escape( const QString& str ) { + QString ret = str.stripWhiteSpace(); + qWarning(ret); + if ( ret.startsWith("$$(OPIEDIR)") ) + ret = ret.replace("$$(OPIEDIR)", OPIE::self()->opieDir() ); + qWarning(ret); + return ret; + }*/ + static void updateTsFiles( const MetaTranslator& fetchedTor, @@ -152,3 +161,3 @@ int main( int argc, char **argv ) - QMap<QString, QString> tagMap = proFileTagMap( fullText ); + QMap<QString, QString> tagMap = proFileTagMap( fullText, OPIE::self()->opieDir() ); QMap<QString, QString>::Iterator it; diff --git a/development/translation/opie-lupdate/merge.cpp b/development/translation/opie-lupdate/merge.cpp index a96104e..3001d4b 100644 --- a/development/translation/opie-lupdate/merge.cpp +++ b/development/translation/opie-lupdate/merge.cpp @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** diff --git a/development/translation/opie-lupdate/numberh.cpp b/development/translation/opie-lupdate/numberh.cpp index f7b7bf8..2f12c3d 100644 --- a/development/translation/opie-lupdate/numberh.cpp +++ b/development/translation/opie-lupdate/numberh.cpp @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** @@ -34,3 +40,3 @@ static bool isDigitFriendly( int c ) { - return ispunct( c ) || isspace( c ); + return ispunct((uchar)c) || isspace((uchar)c); } @@ -41,9 +47,9 @@ static int numberLength( const char *s ) - if ( isdigit(s[0]) ) { + if ( isdigit((uchar)s[0]) ) { do { i++; - } while ( isdigit(s[i]) || - (isDigitFriendly(s[i]) && - (isdigit(s[i + 1]) || - (isDigitFriendly(s[i + 1]) && isdigit(s[i + 2])))) ); + } while (isdigit((uchar)s[i]) || + (isDigitFriendly(s[i]) && + (isdigit((uchar)s[i + 1]) || + (isDigitFriendly(s[i + 1]) && isdigit((uchar)s[i + 2]))))); } @@ -213,3 +219,4 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) if ( (*it).translation().isEmpty() ) - untranslated.insert( zeroKey((*it).sourceText()), *it ); + untranslated.insert(QCString((*it).context()) + "\n" + (*it).sourceText() + "\n" + + (*it).comment(), *it); } else if ( !(*it).translation().isEmpty() ) { @@ -220,3 +227,3 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) for ( u = untranslated.begin(); u != untranslated.end(); ++u ) { - t = translated.find( u.key() ); + t = translated.find( zeroKey((*u).sourceText()) ); if ( t != translated.end() && !t.key().isEmpty() && @@ -224,5 +231,4 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) MetaTranslatorMessage m( *u ); - m.setTranslation( translationAttempt((*t).translation(), - (*t).sourceText(), - (*u).sourceText()) ); + m.setTranslation(translationAttempt((*t).translation(), (*t).sourceText(), + (*u).sourceText())); tor->insert( m ); diff --git a/development/translation/opie-lupdate/sametexth.cpp b/development/translation/opie-lupdate/sametexth.cpp index 574cfd5..80909b3 100644 --- a/development/translation/opie-lupdate/sametexth.cpp +++ b/development/translation/opie-lupdate/sametexth.cpp @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** diff --git a/development/translation/shared/metatranslator.cpp b/development/translation/shared/metatranslator.cpp index a01e1eb..51270c5 100644 --- a/development/translation/shared/metatranslator.cpp +++ b/development/translation/shared/metatranslator.cpp @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** @@ -140,3 +146,4 @@ bool TsHandler::endElement( const QString& /* namespaceURI */, if ( contextIsUtf8 ) - tor->insert( MetaTranslatorMessage(context.utf8(), "", + tor->insert( MetaTranslatorMessage(context.utf8(), + ContextComment, accum.utf8(), QString::null, TRUE, @@ -144,3 +151,4 @@ bool TsHandler::endElement( const QString& /* namespaceURI */, else - tor->insert( MetaTranslatorMessage(context.ascii(), "", + tor->insert( MetaTranslatorMessage(context.ascii(), + ContextComment, accum.ascii(), QString::null, FALSE, @@ -317,4 +325,4 @@ bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const MetaTranslator::MetaTranslator() - : codecName( "ISO-8859-1" ), codec( 0 ) { + clear(); } @@ -324,3 +332,2 @@ MetaTranslator::MetaTranslator( const MetaTranslator& tor ) { - } @@ -335,6 +342,11 @@ MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) -bool MetaTranslator::load( const QString& filename ) +void MetaTranslator::clear() { mm.clear(); + codecName = "ISO-8859-1"; + codec = 0; +} +bool MetaTranslator::load( const QString& filename ) +{ QFile f( filename ); @@ -346,3 +358,2 @@ bool MetaTranslator::load( const QString& filename ) QXmlSimpleReader reader; - // don't click on these! reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); @@ -360,4 +371,2 @@ bool MetaTranslator::load( const QString& filename ) f.close(); - if ( !ok ) - mm.clear(); return ok; @@ -386,3 +395,3 @@ bool MetaTranslator::save( const QString& filename ) const do { - if ( QCString(m.key().sourceText()).isEmpty() ) { + if ( QCString(m.key().sourceText()) == ContextComment ) { if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { @@ -439,3 +448,4 @@ bool MetaTranslator::save( const QString& filename ) const -bool MetaTranslator::release( const QString& filename, bool verbose ) const +bool MetaTranslator::release( const QString& filename, bool verbose, + QTranslator::SaveMode mode ) const { @@ -481,3 +491,3 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const - bool saved = tor.save( filename, QTranslator::Stripped ); + bool saved = tor.save( filename, mode ); if ( saved && verbose ) @@ -525,3 +535,3 @@ void MetaTranslator::stripEmptyContexts() while ( m != mm.end() ) { - if ( QCString(m.key().sourceText()).isEmpty() ) { + if ( QCString(m.key().sourceText()) == ContextComment ) { TMM::Iterator n = m; diff --git a/development/translation/shared/metatranslator.h b/development/translation/shared/metatranslator.h index d35b202..a13f462 100644 --- a/development/translation/shared/metatranslator.h +++ b/development/translation/shared/metatranslator.h @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** @@ -72,5 +78,7 @@ public: + void clear(); bool load( const QString& filename ); bool save( const QString& filename ) const; - bool release( const QString& filename, bool verbose = FALSE ) const; + bool release( const QString& filename, bool verbose = FALSE, + QTranslator::SaveMode mode = QTranslator::Stripped ) const; @@ -98,2 +106,8 @@ private: +/* + This is a quick hack. The proper way to handle this would be + to extend MetaTranslator's interface. +*/ +#define ContextComment "QT_LINGUIST_INTERNAL_CONTEXT_COMMENT" + #endif diff --git a/development/translation/shared/opie.h b/development/translation/shared/opie.h index 4646bb0..28b2a61 100644 --- a/development/translation/shared/opie.h +++ b/development/translation/shared/opie.h @@ -11,3 +11,3 @@ public: QStringList languageList(const QString& opiedir = QString::null)const; - QString opieDir(const QString& opieDir)const; + QString opieDir(const QString& opieDir = QString::null)const; diff --git a/development/translation/shared/proparser.cpp b/development/translation/shared/proparser.cpp index 21d2f86..f616c5a 100644 --- a/development/translation/shared/proparser.cpp +++ b/development/translation/shared/proparser.cpp @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** @@ -22,6 +28,32 @@ +#include <qfile.h> #include <qregexp.h> #include <qstringlist.h> +#include <qtextstream.h> + +#ifdef Q_OS_UNIX +#include <unistd.h> +#endif + +#ifdef Q_OS_WIN32 +#define QT_POPEN _popen +#else +#define QT_POPEN popen +#endif + +QString loadFile( const QString &fileName ) +{ + QFile file( fileName ); + if ( !file.open(IO_ReadOnly) ) { + fprintf( stderr, "error: Cannot load '%s': %s\n", + file.name().latin1(), + file.errorString().latin1() ); + return QString(); + } + + QTextStream in( &file ); + return in.read(); +} -QMap<QString, QString> proFileTagMap( const QString& text ) +QMap<QString, QString> proFileTagMap( const QString& text, const QString& opieDir ) { @@ -30,2 +62,13 @@ QMap<QString, QString> proFileTagMap( const QString& text ) /* + Process include() commands. + */ + QRegExp callToInclude("include\\s*\\(\\s*([^()\\s]+)\\s*\\)"); + int i = 0; + while ( (i = callToInclude.search(t, i)) != -1 ) { + QString after = loadFile( callToInclude.cap(1) ); + t.replace( i, callToInclude.matchedLength(), after ); + i += after.length(); + } + + /* Strip comments, merge lines ending with backslash, add @@ -34,4 +77,4 @@ QMap<QString, QString> proFileTagMap( const QString& text ) */ - t.replace( QRegExp(QString("#[^\n]$")), QString(" ") ); - t.replace( QRegExp(QString("\\\\\\s*\n")), QString(" ") ); + t.replace( QRegExp(QString("#[^\n]*\n")), QString(" ") ); + t.replace( QRegExp(QString("\\\\[^\n\\S]*\n")), QString(" ") ); t.replace( "=", QString(" = ") ); @@ -41,4 +84,6 @@ QMap<QString, QString> proFileTagMap( const QString& text ) + /* + Populate tagMap with 'key = value' entries. + */ QMap<QString, QString> tagMap; - QStringList lines = QStringList::split( QChar(';'), t ); @@ -48,3 +93,3 @@ QMap<QString, QString> proFileTagMap( const QString& text ) - if ( toks.count() >= 3 && + if ( toks.count() >= 3 && (toks[1] == QString("=") || toks[1] == QString("+=")) ) { @@ -70,3 +115,7 @@ QMap<QString, QString> proFileTagMap( const QString& text ) - QRegExp var( "\\$\\$[a-zA-Z0-9_]+" ); + /* + Expand $$variables within the 'value' part of a 'key = value' + pair. + */ + QRegExp var( "\\$\\$[({]?([a-zA-Z0-9_]+)[)}]?" ); QMap<QString, QString>::Iterator it; @@ -74,10 +123,47 @@ QMap<QString, QString> proFileTagMap( const QString& text ) int i = 0; - - while ( (i = var.search(it.data(), i)) != -1 ) { + while ( (i = var.search((*it), i)) != -1 ) { int len = var.matchedLength(); - QString invocation = (*it).mid( i + 2, len - 2 ); + QString invocation = var.cap(1); QString after; - if ( tagMap.contains(invocation) ) - after = tagMap[invocation]; - (*it).replace( i, len, after ); + + if ( invocation == "system" ) { + // skip system(); it will be handled in the next pass + ++i; + } else if ( invocation == "OPIEDIR") { + (*it).replace( i, len, opieDir ); + }else { + if ( tagMap.contains(invocation) ) + after = tagMap[invocation]; + (*it).replace( i, len, after ); + } + } + } + + /* + Execute system() calls. + */ + QRegExp callToSystem( "\\$\\$system\\s*\\(([^()]*)\\)" ); + for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { + int i = 0; + while ( (i = callToSystem.search((*it), i)) != -1 ) { + /* + This code is stolen from qmake's project.cpp file. + Ideally we would use the same parser, so we wouldn't + have this code duplication. + */ + QString after; + char buff[256]; + FILE *proc = QT_POPEN( callToSystem.cap(1).latin1(), "r" ); + while ( proc && !feof(proc) ) { + int read_in = fread( buff, 1, 255, proc ); + if ( !read_in ) + break; + for ( int i = 0; i < read_in; i++ ) { + if ( buff[i] == '\n' || buff[i] == '\t' ) + buff[i] = ' '; + } + buff[read_in] = '\0'; + after += buff; + } + (*it).replace( i, callToSystem.matchedLength(), after ); i += after.length(); @@ -85,2 +171,3 @@ QMap<QString, QString> proFileTagMap( const QString& text ) } + return tagMap; diff --git a/development/translation/shared/proparser.h b/development/translation/shared/proparser.h index 6a61d90..e5678d6 100644 --- a/development/translation/shared/proparser.h +++ b/development/translation/shared/proparser.h @@ -10,2 +10,6 @@ ** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE @@ -14,2 +18,4 @@ ** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. ** @@ -26,3 +32,3 @@ -QMap<QString, QString> proFileTagMap( const QString& text ); +QMap<QString, QString> proFileTagMap( const QString& text, const QString& = QString::null ); |