summaryrefslogtreecommitdiff
path: root/development/translation/shared
Unidiff
Diffstat (limited to 'development/translation/shared') (more/less context) (show whitespace changes)
-rw-r--r--development/translation/shared/metatranslator.cpp34
-rw-r--r--development/translation/shared/metatranslator.h16
-rw-r--r--development/translation/shared/opie.h2
-rw-r--r--development/translation/shared/proparser.cpp103
-rw-r--r--development/translation/shared/proparser.h8
5 files changed, 140 insertions, 23 deletions
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
@@ -8,10 +8,16 @@
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 17**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
15** 21**
16** Contact info@trolltech.com if any conditions of this licensing are 22** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 23** not clear to you.
@@ -138,11 +144,13 @@ bool TsHandler::endElement( const QString& /* namespaceURI */,
138 comment = accum; 144 comment = accum;
139 } else { 145 } else {
140 if ( contextIsUtf8 ) 146 if ( contextIsUtf8 )
141 tor->insert( MetaTranslatorMessage(context.utf8(), "", 147 tor->insert( MetaTranslatorMessage(context.utf8(),
148 ContextComment,
142 accum.utf8(), QString::null, TRUE, 149 accum.utf8(), QString::null, TRUE,
143 MetaTranslatorMessage::Unfinished) ); 150 MetaTranslatorMessage::Unfinished) );
144 else 151 else
145 tor->insert( MetaTranslatorMessage(context.ascii(), "", 152 tor->insert( MetaTranslatorMessage(context.ascii(),
153 ContextComment,
146 accum.ascii(), QString::null, FALSE, 154 accum.ascii(), QString::null, FALSE,
147 MetaTranslatorMessage::Unfinished) ); 155 MetaTranslatorMessage::Unfinished) );
148 } 156 }
@@ -315,14 +323,13 @@ bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const
315} 323}
316 324
317MetaTranslator::MetaTranslator() 325MetaTranslator::MetaTranslator()
318 : codecName( "ISO-8859-1" ), codec( 0 )
319{ 326{
327 clear();
320} 328}
321 329
322MetaTranslator::MetaTranslator( const MetaTranslator& tor ) 330MetaTranslator::MetaTranslator( const MetaTranslator& tor )
323 : mm( tor.mm ), codecName( tor.codecName ), codec( tor.codec ) 331 : mm( tor.mm ), codecName( tor.codecName ), codec( tor.codec )
324{ 332{
325
326} 333}
327 334
328MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) 335MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor )
@@ -333,10 +340,15 @@ MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor )
333 return *this; 340 return *this;
334} 341}
335 342
336bool MetaTranslator::load( const QString& filename ) 343void MetaTranslator::clear()
337{ 344{
338 mm.clear(); 345 mm.clear();
346 codecName = "ISO-8859-1";
347 codec = 0;
348}
339 349
350bool MetaTranslator::load( const QString& filename )
351{
340 QFile f( filename ); 352 QFile f( filename );
341 if ( !f.open(IO_ReadOnly) ) 353 if ( !f.open(IO_ReadOnly) )
342 return FALSE; 354 return FALSE;
@@ -344,7 +356,6 @@ bool MetaTranslator::load( const QString& filename )
344 QTextStream t( &f ); 356 QTextStream t( &f );
345 QXmlInputSource in( t ); 357 QXmlInputSource in( t );
346 QXmlSimpleReader reader; 358 QXmlSimpleReader reader;
347 // don't click on these!
348 reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); 359 reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
349 reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); 360 reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
350 reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" 361 reader.setFeature( "http://trolltech.com/xml/features/report-whitespace"
@@ -358,8 +369,6 @@ bool MetaTranslator::load( const QString& filename )
358 reader.setErrorHandler( 0 ); 369 reader.setErrorHandler( 0 );
359 delete hand; 370 delete hand;
360 f.close(); 371 f.close();
361 if ( !ok )
362 mm.clear();
363 return ok; 372 return ok;
364} 373}
365 374
@@ -384,7 +393,7 @@ bool MetaTranslator::save( const QString& filename ) const
384 QCString comment = ""; 393 QCString comment = "";
385 394
386 do { 395 do {
387 if ( QCString(m.key().sourceText()).isEmpty() ) { 396 if ( QCString(m.key().sourceText()) == ContextComment ) {
388 if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { 397 if ( m.key().type() != MetaTranslatorMessage::Obsolete ) {
389 contextIsUtf8 = m.key().utf8(); 398 contextIsUtf8 = m.key().utf8();
390 comment = QCString( m.key().comment() ); 399 comment = QCString( m.key().comment() );
@@ -437,7 +446,8 @@ bool MetaTranslator::save( const QString& filename ) const
437 return TRUE; 446 return TRUE;
438} 447}
439 448
440bool MetaTranslator::release( const QString& filename, bool verbose ) const 449bool MetaTranslator::release( const QString& filename, bool verbose,
450 QTranslator::SaveMode mode ) const
441{ 451{
442 QTranslator tor( 0 ); 452 QTranslator tor( 0 );
443 int finished = 0; 453 int finished = 0;
@@ -479,7 +489,7 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const
479 } 489 }
480 } 490 }
481 491
482 bool saved = tor.save( filename, QTranslator::Stripped ); 492 bool saved = tor.save( filename, mode );
483 if ( saved && verbose ) 493 if ( saved && verbose )
484 fprintf( stderr, 494 fprintf( stderr,
485 " %d finished, %d unfinished and %d untranslated messages\n", 495 " %d finished, %d unfinished and %d untranslated messages\n",
@@ -523,7 +533,7 @@ void MetaTranslator::stripEmptyContexts()
523 533
524 TMM::Iterator m = mm.begin(); 534 TMM::Iterator m = mm.begin();
525 while ( m != mm.end() ) { 535 while ( m != mm.end() ) {
526 if ( QCString(m.key().sourceText()).isEmpty() ) { 536 if ( QCString(m.key().sourceText()) == ContextComment ) {
527 TMM::Iterator n = m; 537 TMM::Iterator n = m;
528 ++n; 538 ++n;
529 // the context comment is followed by other messages 539 // the context comment is followed by other messages
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
@@ -8,10 +8,16 @@
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 17**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
15** 21**
16** Contact info@trolltech.com if any conditions of this licensing are 22** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 23** not clear to you.
@@ -70,9 +76,11 @@ public:
70 76
71 MetaTranslator& operator=( const MetaTranslator& tor ); 77 MetaTranslator& operator=( const MetaTranslator& tor );
72 78
79 void clear();
73 bool load( const QString& filename ); 80 bool load( const QString& filename );
74 bool save( const QString& filename ) const; 81 bool save( const QString& filename ) const;
75 bool release( const QString& filename, bool verbose = FALSE ) const; 82 bool release( const QString& filename, bool verbose = FALSE,
83 QTranslator::SaveMode mode = QTranslator::Stripped ) const;
76 84
77 bool contains( const char *context, const char *sourceText, 85 bool contains( const char *context, const char *sourceText,
78 const char *comment ) const; 86 const char *comment ) const;
@@ -96,4 +104,10 @@ private:
96 QTextCodec *codec; 104 QTextCodec *codec;
97}; 105};
98 106
107/*
108 This is a quick hack. The proper way to handle this would be
109 to extend MetaTranslator's interface.
110*/
111#define ContextComment "QT_LINGUIST_INTERNAL_CONTEXT_COMMENT"
112
99#endif 113#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
@@ -9,7 +9,7 @@ public:
9 static OPIE* self(); 9 static OPIE* self();
10 /** get the list of languages */ 10 /** get the list of languages */
11 QStringList languageList(const QString& opiedir = QString::null)const; 11 QStringList languageList(const QString& opiedir = QString::null)const;
12 QString opieDir(const QString& opieDir)const; 12 QString opieDir(const QString& opieDir = QString::null)const;
13 13
14private: 14private:
15 OPIE(); 15 OPIE();
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
@@ -8,10 +8,16 @@
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 17**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
15** 21**
16** Contact info@trolltech.com if any conditions of this licensing are 22** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 23** not clear to you.
@@ -20,27 +26,66 @@
20 26
21#include "proparser.h" 27#include "proparser.h"
22 28
29#include <qfile.h>
23#include <qregexp.h> 30#include <qregexp.h>
24#include <qstringlist.h> 31#include <qstringlist.h>
32#include <qtextstream.h>
33
34#ifdef Q_OS_UNIX
35#include <unistd.h>
36#endif
37
38#ifdef Q_OS_WIN32
39#define QT_POPEN _popen
40#else
41#define QT_POPEN popen
42#endif
25 43
26QMap<QString, QString> proFileTagMap( const QString& text ) 44QString loadFile( const QString &fileName )
45{
46 QFile file( fileName );
47 if ( !file.open(IO_ReadOnly) ) {
48 fprintf( stderr, "error: Cannot load '%s': %s\n",
49 file.name().latin1(),
50 file.errorString().latin1() );
51 return QString();
52 }
53
54 QTextStream in( &file );
55 return in.read();
56}
57
58QMap<QString, QString> proFileTagMap( const QString& text, const QString& opieDir )
27{ 59{
28 QString t = text; 60 QString t = text;
29 61
30 /* 62 /*
63 Process include() commands.
64 */
65 QRegExp callToInclude("include\\s*\\(\\s*([^()\\s]+)\\s*\\)");
66 int i = 0;
67 while ( (i = callToInclude.search(t, i)) != -1 ) {
68 QString after = loadFile( callToInclude.cap(1) );
69 t.replace( i, callToInclude.matchedLength(), after );
70 i += after.length();
71 }
72
73 /*
31 Strip comments, merge lines ending with backslash, add 74 Strip comments, merge lines ending with backslash, add
32 spaces around '=' and '+=', replace '\n' with ';', and 75 spaces around '=' and '+=', replace '\n' with ';', and
33 simplify white spaces. 76 simplify white spaces.
34 */ 77 */
35 t.replace( QRegExp(QString("#[^\n]$")), QString(" ") ); 78 t.replace( QRegExp(QString("#[^\n]*\n")), QString(" ") );
36 t.replace( QRegExp(QString("\\\\\\s*\n")), QString(" ") ); 79 t.replace( QRegExp(QString("\\\\[^\n\\S]*\n")), QString(" ") );
37 t.replace( "=", QString(" = ") ); 80 t.replace( "=", QString(" = ") );
38 t.replace( "+ =", QString(" += ") ); 81 t.replace( "+ =", QString(" += ") );
39 t.replace( "\n", QString(";") ); 82 t.replace( "\n", QString(";") );
40 t = t.simplifyWhiteSpace(); 83 t = t.simplifyWhiteSpace();
41 84
85 /*
86 Populate tagMap with 'key = value' entries.
87 */
42 QMap<QString, QString> tagMap; 88 QMap<QString, QString> tagMap;
43
44 QStringList lines = QStringList::split( QChar(';'), t ); 89 QStringList lines = QStringList::split( QChar(';'), t );
45 QStringList::Iterator line; 90 QStringList::Iterator line;
46 for ( line = lines.begin(); line != lines.end(); ++line ) { 91 for ( line = lines.begin(); line != lines.end(); ++line ) {
@@ -68,20 +113,62 @@ QMap<QString, QString> proFileTagMap( const QString& text )
68 } 113 }
69 } 114 }
70 115
71 QRegExp var( "\\$\\$[a-zA-Z0-9_]+" ); 116 /*
117 Expand $$variables within the 'value' part of a 'key = value'
118 pair.
119 */
120 QRegExp var( "\\$\\$[({]?([a-zA-Z0-9_]+)[)}]?" );
72 QMap<QString, QString>::Iterator it; 121 QMap<QString, QString>::Iterator it;
73 for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { 122 for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
74 int i = 0; 123 int i = 0;
75 124 while ( (i = var.search((*it), i)) != -1 ) {
76 while ( (i = var.search(it.data(), i)) != -1 ) {
77 int len = var.matchedLength(); 125 int len = var.matchedLength();
78 QString invocation = (*it).mid( i + 2, len - 2 ); 126 QString invocation = var.cap(1);
79 QString after; 127 QString after;
128
129 if ( invocation == "system" ) {
130 // skip system(); it will be handled in the next pass
131 ++i;
132 } else if ( invocation == "OPIEDIR") {
133 (*it).replace( i, len, opieDir );
134 }else {
80 if ( tagMap.contains(invocation) ) 135 if ( tagMap.contains(invocation) )
81 after = tagMap[invocation]; 136 after = tagMap[invocation];
82 (*it).replace( i, len, after ); 137 (*it).replace( i, len, after );
138 }
139 }
140 }
141
142 /*
143 Execute system() calls.
144 */
145 QRegExp callToSystem( "\\$\\$system\\s*\\(([^()]*)\\)" );
146 for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
147 int i = 0;
148 while ( (i = callToSystem.search((*it), i)) != -1 ) {
149 /*
150 This code is stolen from qmake's project.cpp file.
151 Ideally we would use the same parser, so we wouldn't
152 have this code duplication.
153 */
154 QString after;
155 char buff[256];
156 FILE *proc = QT_POPEN( callToSystem.cap(1).latin1(), "r" );
157 while ( proc && !feof(proc) ) {
158 int read_in = fread( buff, 1, 255, proc );
159 if ( !read_in )
160 break;
161 for ( int i = 0; i < read_in; i++ ) {
162 if ( buff[i] == '\n' || buff[i] == '\t' )
163 buff[i] = ' ';
164 }
165 buff[read_in] = '\0';
166 after += buff;
167 }
168 (*it).replace( i, callToSystem.matchedLength(), after );
83 i += after.length(); 169 i += after.length();
84 } 170 }
85 } 171 }
172
86 return tagMap; 173 return tagMap;
87} 174}
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
@@ -8,10 +8,16 @@
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 17**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
15** 21**
16** Contact info@trolltech.com if any conditions of this licensing are 22** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 23** not clear to you.
@@ -24,6 +30,6 @@
24#include <qmap.h> 30#include <qmap.h>
25#include <qstring.h> 31#include <qstring.h>
26 32
27QMap<QString, QString> proFileTagMap( const QString& text ); 33QMap<QString, QString> proFileTagMap( const QString& text, const QString& = QString::null );
28 34
29#endif 35#endif