summaryrefslogtreecommitdiff
path: root/development/translation/shared
authorzecke <zecke>2003-04-20 17:24:50 (UTC)
committer zecke <zecke>2003-04-20 17:24:50 (UTC)
commit92c687d281f69085436a77efb8cd1d4d2d9333f8 (patch) (unidiff)
tree7bbfac3ea310ed140e78cb3c17f8219294cb61d0 /development/translation/shared
parentf1f4e6794507d9b8dafb46ce05968a0647a41777 (diff)
downloadopie-92c687d281f69085436a77efb8cd1d4d2d9333f8.zip
opie-92c687d281f69085436a77efb8cd1d4d2d9333f8.tar.gz
opie-92c687d281f69085436a77efb8cd1d4d2d9333f8.tar.bz2
Initial revision
Diffstat (limited to 'development/translation/shared') (more/less context) (show whitespace changes)
-rw-r--r--development/translation/shared/metatranslator.cpp586
-rw-r--r--development/translation/shared/metatranslator.h99
-rw-r--r--development/translation/shared/opie.cpp40
-rw-r--r--development/translation/shared/opie.h21
-rw-r--r--development/translation/shared/proparser.cpp87
-rw-r--r--development/translation/shared/proparser.h29
6 files changed, 862 insertions, 0 deletions
diff --git a/development/translation/shared/metatranslator.cpp b/development/translation/shared/metatranslator.cpp
new file mode 100644
index 0000000..a01e1eb
--- a/dev/null
+++ b/development/translation/shared/metatranslator.cpp
@@ -0,0 +1,586 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Linguist.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** 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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "metatranslator.h"
22
23#include <qapplication.h>
24#include <qcstring.h>
25#include <qfile.h>
26#include <qmessagebox.h>
27#include <qtextcodec.h>
28#include <qtextstream.h>
29#include <qxml.h>
30
31static bool encodingIsUtf8( const QXmlAttributes& atts )
32{
33 for ( int i = 0; i < atts.length(); i++ ) {
34 // utf8="true" is a pre-3.0 syntax
35 if ( atts.qName(i) == QString("utf8") ) {
36 return ( atts.value(i) == QString("true") );
37 } else if ( atts.qName(i) == QString("encoding") ) {
38 return ( atts.value(i) == QString("UTF-8") );
39 }
40 }
41 return FALSE;
42}
43
44class TsHandler : public QXmlDefaultHandler
45{
46public:
47 TsHandler( MetaTranslator *translator )
48 : tor( translator ), type( MetaTranslatorMessage::Finished ),
49 inMessage( FALSE ), ferrorCount( 0 ), contextIsUtf8( FALSE ),
50 messageIsUtf8( FALSE ) { }
51
52 virtual bool startElement( const QString& namespaceURI,
53 const QString& localName, const QString& qName,
54 const QXmlAttributes& atts );
55 virtual bool endElement( const QString& namespaceURI,
56 const QString& localName, const QString& qName );
57 virtual bool characters( const QString& ch );
58 virtual bool fatalError( const QXmlParseException& exception );
59
60private:
61 MetaTranslator *tor;
62 MetaTranslatorMessage::Type type;
63 bool inMessage;
64 QString context;
65 QString source;
66 QString comment;
67 QString translation;
68
69 QString accum;
70 int ferrorCount;
71 bool contextIsUtf8;
72 bool messageIsUtf8;
73};
74
75bool TsHandler::startElement( const QString& /* namespaceURI */,
76 const QString& /* localName */,
77 const QString& qName,
78 const QXmlAttributes& atts )
79{
80 if ( qName == QString("byte") ) {
81 for ( int i = 0; i < atts.length(); i++ ) {
82 if ( atts.qName(i) == QString("value") ) {
83 QString value = atts.value( i );
84 int base = 10;
85 if ( value.startsWith("x") ) {
86 base = 16;
87 value = value.mid( 1 );
88 }
89 int n = value.toUInt( 0, base );
90 if ( n != 0 )
91 accum += QChar( n );
92 }
93 }
94 } else {
95 if ( qName == QString("context") ) {
96 context.truncate( 0 );
97 source.truncate( 0 );
98 comment.truncate( 0 );
99 translation.truncate( 0 );
100 contextIsUtf8 = encodingIsUtf8( atts );
101 } else if ( qName == QString("message") ) {
102 inMessage = TRUE;
103 type = MetaTranslatorMessage::Finished;
104 source.truncate( 0 );
105 comment.truncate( 0 );
106 translation.truncate( 0 );
107 messageIsUtf8 = encodingIsUtf8( atts );
108 } else if ( qName == QString("translation") ) {
109 for ( int i = 0; i < atts.length(); i++ ) {
110 if ( atts.qName(i) == QString("type") ) {
111 if ( atts.value(i) == QString("unfinished") )
112 type = MetaTranslatorMessage::Unfinished;
113 else if ( atts.value(i) == QString("obsolete") )
114 type = MetaTranslatorMessage::Obsolete;
115 else
116 type = MetaTranslatorMessage::Finished;
117 }
118 }
119 }
120 accum.truncate( 0 );
121 }
122 return TRUE;
123}
124
125bool TsHandler::endElement( const QString& /* namespaceURI */,
126 const QString& /* localName */,
127 const QString& qName )
128{
129 if ( qName == QString("codec") || qName == QString("defaultcodec") ) {
130 // "codec" is a pre-3.0 syntax
131 tor->setCodec( accum );
132 } else if ( qName == QString("name") ) {
133 context = accum;
134 } else if ( qName == QString("source") ) {
135 source = accum;
136 } else if ( qName == QString("comment") ) {
137 if ( inMessage ) {
138 comment = accum;
139 } else {
140 if ( contextIsUtf8 )
141 tor->insert( MetaTranslatorMessage(context.utf8(), "",
142 accum.utf8(), QString::null, TRUE,
143 MetaTranslatorMessage::Unfinished) );
144 else
145 tor->insert( MetaTranslatorMessage(context.ascii(), "",
146 accum.ascii(), QString::null, FALSE,
147 MetaTranslatorMessage::Unfinished) );
148 }
149 } else if ( qName == QString("translation") ) {
150 translation = accum;
151 } else if ( qName == QString("message") ) {
152 if ( messageIsUtf8 )
153 tor->insert( MetaTranslatorMessage(context.utf8(), source.utf8(),
154 comment.utf8(), translation,
155 TRUE, type) );
156 else
157 tor->insert( MetaTranslatorMessage(context.ascii(), source.ascii(),
158 comment.ascii(), translation,
159 FALSE, type) );
160 inMessage = FALSE;
161 }
162 return TRUE;
163}
164
165bool TsHandler::characters( const QString& ch )
166{
167 QString t = ch;
168 t.replace( "\r", "" );
169 accum += t;
170 return TRUE;
171}
172
173bool TsHandler::fatalError( const QXmlParseException& exception )
174{
175 if ( ferrorCount++ == 0 ) {
176 QString msg;
177 msg.sprintf( "Parse error at line %d, column %d (%s).",
178 exception.lineNumber(), exception.columnNumber(),
179 exception.message().latin1() );
180 if ( qApp == 0 )
181 fprintf( stderr, "XML error: %s\n", msg.latin1() );
182 else
183 QMessageBox::information( qApp->mainWidget(),
184 QObject::tr("Qt Linguist"), msg );
185 }
186 return FALSE;
187}
188
189static QString numericEntity( int ch )
190{
191 return QString( ch <= 0x20 ? "<byte value=\"x%1\"/>" : "&#x%1;" )
192 .arg( ch, 0, 16 );
193}
194
195static QString protect( const QCString& str )
196{
197 QString result;
198 int len = (int) str.length();
199 for ( int k = 0; k < len; k++ ) {
200 switch( str[k] ) {
201 case '\"':
202 result += QString( "&quot;" );
203 break;
204 case '&':
205 result += QString( "&amp;" );
206 break;
207 case '>':
208 result += QString( "&gt;" );
209 break;
210 case '<':
211 result += QString( "&lt;" );
212 break;
213 case '\'':
214 result += QString( "&apos;" );
215 break;
216 default:
217 if ( (uchar) str[k] < 0x20 && str[k] != '\n' )
218 result += numericEntity( (uchar) str[k] );
219 else
220 result += str[k];
221 }
222 }
223 return result;
224}
225
226static QString evilBytes( const QCString& str, bool utf8 )
227{
228 if ( utf8 ) {
229 return protect( str );
230 } else {
231 QString result;
232 QCString t = protect( str ).latin1();
233 int len = (int) t.length();
234 for ( int k = 0; k < len; k++ ) {
235 if ( (uchar) t[k] >= 0x7f )
236 result += numericEntity( (uchar) t[k] );
237 else
238 result += QChar( t[k] );
239 }
240 return result;
241 }
242}
243
244MetaTranslatorMessage::MetaTranslatorMessage()
245 : utfeight( FALSE ), ty( Unfinished )
246{
247}
248
249MetaTranslatorMessage::MetaTranslatorMessage( const char *context,
250 const char *sourceText,
251 const char *comment,
252 const QString& translation,
253 bool utf8, Type type )
254 : QTranslatorMessage( context, sourceText, comment, translation ),
255 utfeight( FALSE ), ty( type )
256{
257 /*
258 Don't use UTF-8 if it makes no difference. UTF-8 should be
259 reserved for the real problematic case: non-ASCII (possibly
260 non-Latin-1) characters in .ui files.
261 */
262 if ( utf8 ) {
263 if ( sourceText != 0 ) {
264 int i = 0;
265 while ( sourceText[i] != '\0' ) {
266 if ( (uchar) sourceText[i] >= 0x80 ) {
267 utfeight = TRUE;
268 break;
269 }
270 i++;
271 }
272 }
273 if ( !utfeight && comment != 0 ) {
274 int i = 0;
275 while ( comment[i] != '\0' ) {
276 if ( (uchar) comment[i] >= 0x80 ) {
277 utfeight = TRUE;
278 break;
279 }
280 i++;
281 }
282 }
283 }
284}
285
286MetaTranslatorMessage::MetaTranslatorMessage( const MetaTranslatorMessage& m )
287 : QTranslatorMessage( m ), utfeight( m.utfeight ), ty( m.ty )
288{
289}
290
291MetaTranslatorMessage& MetaTranslatorMessage::operator=(
292 const MetaTranslatorMessage& m )
293{
294 QTranslatorMessage::operator=( m );
295 utfeight = m.utfeight;
296 ty = m.ty;
297 return *this;
298}
299
300bool MetaTranslatorMessage::operator==( const MetaTranslatorMessage& m ) const
301{
302 return qstrcmp( context(), m.context() ) == 0 &&
303 qstrcmp( sourceText(), m.sourceText() ) == 0 &&
304 qstrcmp( comment(), m.comment() ) == 0;
305}
306
307bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const
308{
309 int delta = qstrcmp( context(), m.context() );
310 if ( delta == 0 )
311 delta = qstrcmp( sourceText(), m.sourceText() );
312 if ( delta == 0 )
313 delta = qstrcmp( comment(), m.comment() );
314 return delta < 0;
315}
316
317MetaTranslator::MetaTranslator()
318 : codecName( "ISO-8859-1" ), codec( 0 )
319{
320}
321
322MetaTranslator::MetaTranslator( const MetaTranslator& tor )
323 : mm( tor.mm ), codecName( tor.codecName ), codec( tor.codec )
324{
325
326}
327
328MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor )
329{
330 mm = tor.mm;
331 codecName = tor.codecName;
332 codec = tor.codec;
333 return *this;
334}
335
336bool MetaTranslator::load( const QString& filename )
337{
338 mm.clear();
339
340 QFile f( filename );
341 if ( !f.open(IO_ReadOnly) )
342 return FALSE;
343
344 QTextStream t( &f );
345 QXmlInputSource in( t );
346 QXmlSimpleReader reader;
347 // don't click on these!
348 reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
349 reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
350 reader.setFeature( "http://trolltech.com/xml/features/report-whitespace"
351 "-only-CharData", FALSE );
352 QXmlDefaultHandler *hand = new TsHandler( this );
353 reader.setContentHandler( hand );
354 reader.setErrorHandler( hand );
355
356 bool ok = reader.parse( in );
357 reader.setContentHandler( 0 );
358 reader.setErrorHandler( 0 );
359 delete hand;
360 f.close();
361 if ( !ok )
362 mm.clear();
363 return ok;
364}
365
366bool MetaTranslator::save( const QString& filename ) const
367{
368 QFile f( filename );
369 if ( !f.open(IO_WriteOnly) )
370 return FALSE;
371
372 QTextStream t( &f );
373 t.setCodec( QTextCodec::codecForName("ISO-8859-1") );
374
375 t << "<!DOCTYPE TS><TS>\n";
376 if ( codecName != "ISO-8859-1" )
377 t << "<defaultcodec>" << codecName << "</defaultcodec>\n";
378 TMM::ConstIterator m = mm.begin();
379 while ( m != mm.end() ) {
380 TMMInv inv;
381 TMMInv::Iterator i;
382 bool contextIsUtf8 = m.key().utf8();
383 QCString context = m.key().context();
384 QCString comment = "";
385
386 do {
387 if ( QCString(m.key().sourceText()).isEmpty() ) {
388 if ( m.key().type() != MetaTranslatorMessage::Obsolete ) {
389 contextIsUtf8 = m.key().utf8();
390 comment = QCString( m.key().comment() );
391 }
392 } else {
393 inv.insert( *m, m.key() );
394 }
395 } while ( ++m != mm.end() && QCString(m.key().context()) == context );
396
397 t << "<context";
398 if ( contextIsUtf8 )
399 t << " encoding=\"UTF-8\"";
400 t << ">\n";
401 t << " <name>" << evilBytes( context, contextIsUtf8 )
402 << "</name>\n";
403 if ( !comment.isEmpty() )
404 t << " <comment>" << evilBytes( comment, contextIsUtf8 )
405 << "</comment>\n";
406
407 for ( i = inv.begin(); i != inv.end(); ++i ) {
408 // no need for such noise
409 if ( (*i).type() == MetaTranslatorMessage::Obsolete &&
410 (*i).translation().isEmpty() )
411 continue;
412
413 t << " <message";
414 if ( (*i).utf8() )
415 t << " encoding=\"UTF-8\"";
416 t << ">\n"
417 << " <source>" << evilBytes( (*i).sourceText(),
418 (*i).utf8() )
419 << "</source>\n";
420 if ( !QCString((*i).comment()).isEmpty() )
421 t << " <comment>" << evilBytes( (*i).comment(),
422 (*i).utf8() )
423 << "</comment>\n";
424 t << " <translation";
425 if ( (*i).type() == MetaTranslatorMessage::Unfinished )
426 t << " type=\"unfinished\"";
427 else if ( (*i).type() == MetaTranslatorMessage::Obsolete )
428 t << " type=\"obsolete\"";
429 t << ">" << protect( (*i).translation().utf8() )
430 << "</translation>\n";
431 t << " </message>\n";
432 }
433 t << "</context>\n";
434 }
435 t << "</TS>\n";
436 f.close();
437 return TRUE;
438}
439
440bool MetaTranslator::release( const QString& filename, bool verbose ) const
441{
442 QTranslator tor( 0 );
443 int finished = 0;
444 int unfinished = 0;
445 int untranslated = 0;
446 TMM::ConstIterator m;
447
448 for ( m = mm.begin(); m != mm.end(); ++m ) {
449 if ( m.key().type() != MetaTranslatorMessage::Obsolete ) {
450 if ( m.key().translation().isEmpty() ) {
451 untranslated++;
452 } else {
453 if ( m.key().type() == MetaTranslatorMessage::Unfinished )
454 unfinished++;
455 else
456 finished++;
457
458 QCString context = m.key().context();
459 QCString sourceText = m.key().sourceText();
460 QCString comment = m.key().comment();
461 QString translation = m.key().translation();
462
463 /*
464 Drop the comment in (context, sourceText, comment),
465 unless (context, sourceText, "") already exists, or
466 unless we already dropped the comment of (context,
467 sourceText, comment0).
468 */
469 if ( comment.isEmpty()
470 || contains(context, sourceText, "")
471 || !tor.findMessage(context, sourceText, "").translation()
472 .isNull() ) {
473 tor.insert( m.key() );
474 } else {
475 tor.insert( QTranslatorMessage(context, sourceText, "",
476 translation) );
477 }
478 }
479 }
480 }
481
482 bool saved = tor.save( filename, QTranslator::Stripped );
483 if ( saved && verbose )
484 fprintf( stderr,
485 " %d finished, %d unfinished and %d untranslated messages\n",
486 finished, unfinished, untranslated );
487
488 return saved;
489}
490
491bool MetaTranslator::contains( const char *context, const char *sourceText,
492 const char *comment ) const
493{
494 return mm.find( MetaTranslatorMessage(context, sourceText, comment) ) !=
495 mm.end();
496}
497
498void MetaTranslator::insert( const MetaTranslatorMessage& m )
499{
500 int pos = mm.count();
501 TMM::Iterator n = mm.find( m );
502 if ( n != mm.end() )
503 pos = *n;
504 mm.replace( m, pos );
505}
506
507void MetaTranslator::stripObsoleteMessages()
508{
509 TMM newmm;
510
511 TMM::Iterator m = mm.begin();
512 while ( m != mm.end() ) {
513 if ( m.key().type() != MetaTranslatorMessage::Obsolete )
514 newmm.insert( m.key(), *m );
515 ++m;
516 }
517 mm = newmm;
518}
519
520void MetaTranslator::stripEmptyContexts()
521{
522 TMM newmm;
523
524 TMM::Iterator m = mm.begin();
525 while ( m != mm.end() ) {
526 if ( QCString(m.key().sourceText()).isEmpty() ) {
527 TMM::Iterator n = m;
528 ++n;
529 // the context comment is followed by other messages
530 if ( n != newmm.end() &&
531 qstrcmp(m.key().context(), n.key().context()) == 0 )
532 newmm.insert( m.key(), *m );
533 } else {
534 newmm.insert( m.key(), *m );
535 }
536 ++m;
537 }
538 mm = newmm;
539}
540
541void MetaTranslator::setCodec( const char *name )
542{
543 const int latin1 = 4;
544
545 codecName = name;
546 codec = QTextCodec::codecForName( name );
547 if ( codec == 0 || codec->mibEnum() == latin1 )
548 codec = 0;
549}
550
551QString MetaTranslator::toUnicode( const char *str, bool utf8 ) const
552{
553 if ( utf8 )
554 return QString::fromUtf8( str );
555 else if ( codec == 0 )
556 return QString( str );
557 else
558 return codec->toUnicode( str );
559}
560
561QValueList<MetaTranslatorMessage> MetaTranslator::messages() const
562{
563 int n = mm.count();
564 TMM::ConstIterator *t = new TMM::ConstIterator[n + 1];
565 TMM::ConstIterator m;
566 for ( m = mm.begin(); m != mm.end(); ++m )
567 t[*m] = m;
568
569 QValueList<MetaTranslatorMessage> val;
570 for ( int i = 0; i < n; i++ )
571 val.append( t[i].key() );
572
573 delete[] t;
574 return val;
575}
576
577QValueList<MetaTranslatorMessage> MetaTranslator::translatedMessages() const
578{
579 QValueList<MetaTranslatorMessage> val;
580 TMM::ConstIterator m;
581 for ( m = mm.begin(); m != mm.end(); ++m ) {
582 if ( m.key().type() == MetaTranslatorMessage::Finished )
583 val.append( m.key() );
584 }
585 return val;
586}
diff --git a/development/translation/shared/metatranslator.h b/development/translation/shared/metatranslator.h
new file mode 100644
index 0000000..d35b202
--- a/dev/null
+++ b/development/translation/shared/metatranslator.h
@@ -0,0 +1,99 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Linguist.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** 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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef METATRANSLATOR_H
22#define METATRANSLATOR_H
23
24#include <qmap.h>
25#include <qstring.h>
26#include <qtranslator.h>
27#include <qvaluelist.h>
28
29class QTextCodec;
30
31class MetaTranslatorMessage : public QTranslatorMessage
32{
33public:
34 enum Type { Unfinished, Finished, Obsolete };
35
36 MetaTranslatorMessage();
37 MetaTranslatorMessage( const char *context, const char *sourceText,
38 const char *comment,
39 const QString& translation = QString::null,
40 bool utf8 = FALSE, Type type = Unfinished );
41 MetaTranslatorMessage( const MetaTranslatorMessage& m );
42
43 MetaTranslatorMessage& operator=( const MetaTranslatorMessage& m );
44
45 void setType( Type nt ) { ty = nt; }
46 Type type() const { return ty; }
47 bool utf8() const { return utfeight; }
48
49 bool operator==( const MetaTranslatorMessage& m ) const;
50 bool operator!=( const MetaTranslatorMessage& m ) const
51 { return !operator==( m ); }
52 bool operator<( const MetaTranslatorMessage& m ) const;
53 bool operator<=( const MetaTranslatorMessage& m )
54 { return !operator>( m ); }
55 bool operator>( const MetaTranslatorMessage& m ) const
56 { return this->operator<( m ); }
57 bool operator>=( const MetaTranslatorMessage& m ) const
58 { return !operator<( m ); }
59
60private:
61 bool utfeight;
62 Type ty;
63};
64
65class MetaTranslator
66{
67public:
68 MetaTranslator();
69 MetaTranslator( const MetaTranslator& tor );
70
71 MetaTranslator& operator=( const MetaTranslator& tor );
72
73 bool load( const QString& filename );
74 bool save( const QString& filename ) const;
75 bool release( const QString& filename, bool verbose = FALSE ) const;
76
77 bool contains( const char *context, const char *sourceText,
78 const char *comment ) const;
79 void insert( const MetaTranslatorMessage& m );
80
81 void stripObsoleteMessages();
82 void stripEmptyContexts();
83
84 void setCodec( const char *name );
85 QString toUnicode( const char *str, bool utf8 ) const;
86
87 QValueList<MetaTranslatorMessage> messages() const;
88 QValueList<MetaTranslatorMessage> translatedMessages() const;
89
90private:
91 typedef QMap<MetaTranslatorMessage, int> TMM;
92 typedef QMap<int, MetaTranslatorMessage> TMMInv;
93
94 TMM mm;
95 QCString codecName;
96 QTextCodec *codec;
97};
98
99#endif
diff --git a/development/translation/shared/opie.cpp b/development/translation/shared/opie.cpp
new file mode 100644
index 0000000..c5c72d1
--- a/dev/null
+++ b/development/translation/shared/opie.cpp
@@ -0,0 +1,40 @@
1#include <stdlib.h>
2
3#include <qdir.h>
4
5#include "opie.h"
6
7OPIE* OPIE::m_self = 0;
8
9
10OPIE::OPIE() {
11}
12OPIE::~OPIE() {
13}
14OPIE* OPIE::self() {
15 if (!m_self ) m_self = new OPIE;
16 return m_self;
17}
18QStringList OPIE::languageList( const QString& _opieDir )const {
19 QString opieDi = opieDir( _opieDir );
20
21 QStringList langs;
22 QDir dir( opieDi + "/i18n/");
23 if (!dir.exists() ) return langs;
24 langs = dir.entryList( QDir::Dirs );
25
26 langs.remove("CVS"); // hey this no language
27 langs.remove("unmaintained"); // remove this one too
28 langs.remove(".");
29 langs.remove("..");
30
31
32
33 return langs;
34}
35QString OPIE::opieDir( const QString& _opieDir ) const{
36 if (!_opieDir.isEmpty() ) return _opieDir;
37 char* dir = ::getenv("OPIEDIR");
38 if (!dir ) return QString::null;
39 return QString::fromLatin1(dir);
40}
diff --git a/development/translation/shared/opie.h b/development/translation/shared/opie.h
new file mode 100644
index 0000000..4646bb0
--- a/dev/null
+++ b/development/translation/shared/opie.h
@@ -0,0 +1,21 @@
1#ifndef OPIE_H
2#define OPIE_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6
7class OPIE {
8public:
9 static OPIE* self();
10 /** get the list of languages */
11 QStringList languageList(const QString& opiedir = QString::null)const;
12 QString opieDir(const QString& opieDir)const;
13
14private:
15 OPIE();
16 ~OPIE();
17 static OPIE* m_self;
18
19};
20
21#endif
diff --git a/development/translation/shared/proparser.cpp b/development/translation/shared/proparser.cpp
new file mode 100644
index 0000000..21d2f86
--- a/dev/null
+++ b/development/translation/shared/proparser.cpp
@@ -0,0 +1,87 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Linguist.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** 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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "proparser.h"
22
23#include <qregexp.h>
24#include <qstringlist.h>
25
26QMap<QString, QString> proFileTagMap( const QString& text )
27{
28 QString t = text;
29
30 /*
31 Strip comments, merge lines ending with backslash, add
32 spaces around '=' and '+=', replace '\n' with ';', and
33 simplify white spaces.
34 */
35 t.replace( QRegExp(QString("#[^\n]$")), QString(" ") );
36 t.replace( QRegExp(QString("\\\\\\s*\n")), QString(" ") );
37 t.replace( "=", QString(" = ") );
38 t.replace( "+ =", QString(" += ") );
39 t.replace( "\n", QString(";") );
40 t = t.simplifyWhiteSpace();
41
42 QMap<QString, QString> tagMap;
43
44 QStringList lines = QStringList::split( QChar(';'), t );
45 QStringList::Iterator line;
46 for ( line = lines.begin(); line != lines.end(); ++line ) {
47 QStringList toks = QStringList::split( QChar(' '), *line );
48
49 if ( toks.count() >= 3 &&
50 (toks[1] == QString("=") || toks[1] == QString("+=")) ) {
51 QString tag = toks.first();
52 int k = tag.findRev( QChar(':') ); // as in 'unix:'
53 if ( k != -1 )
54 tag = tag.mid( k + 1 );
55 toks.remove( toks.begin() );
56
57 QString action = toks.first();
58 toks.remove( toks.begin() );
59
60 if ( tagMap.contains(tag) ) {
61 if ( action == QString("=") )
62 tagMap.replace( tag, toks.join(QChar(' ')) );
63 else
64 tagMap[tag] += QChar( ' ' ) + toks.join( QChar(' ') );
65 } else {
66 tagMap[tag] = toks.join( QChar(' ') );
67 }
68 }
69 }
70
71 QRegExp var( "\\$\\$[a-zA-Z0-9_]+" );
72 QMap<QString, QString>::Iterator it;
73 for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
74 int i = 0;
75
76 while ( (i = var.search(it.data(), i)) != -1 ) {
77 int len = var.matchedLength();
78 QString invocation = (*it).mid( i + 2, len - 2 );
79 QString after;
80 if ( tagMap.contains(invocation) )
81 after = tagMap[invocation];
82 (*it).replace( i, len, after );
83 i += after.length();
84 }
85 }
86 return tagMap;
87}
diff --git a/development/translation/shared/proparser.h b/development/translation/shared/proparser.h
new file mode 100644
index 0000000..6a61d90
--- a/dev/null
+++ b/development/translation/shared/proparser.h
@@ -0,0 +1,29 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Linguist.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** 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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef PROPARSER_H
22#define PROPARSER_H
23
24#include <qmap.h>
25#include <qstring.h>
26
27QMap<QString, QString> proFileTagMap( const QString& text );
28
29#endif