summaryrefslogtreecommitdiff
path: root/development/translation/shared/metatranslator.cpp
authorzecke <zecke>2004-01-09 19:13:35 (UTC)
committer zecke <zecke>2004-01-09 19:13:35 (UTC)
commit56bb9961db1158250bbfe971f4556b56c0bd6581 (patch) (unidiff)
treea4f40da98f695b5aadd845b68aaab41ac3d81826 /development/translation/shared/metatranslator.cpp
parent6875988077013544246ae0df7cc2e5d538a7f152 (diff)
downloadopie-56bb9961db1158250bbfe971f4556b56c0bd6581.zip
opie-56bb9961db1158250bbfe971f4556b56c0bd6581.tar.gz
opie-56bb9961db1158250bbfe971f4556b56c0bd6581.tar.bz2
Update lupdate and shared to Qt3.3 qt-copy sources
Some special replacement for $$(OPIEDIR) to make ar_* happy
Diffstat (limited to 'development/translation/shared/metatranslator.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--development/translation/shared/metatranslator.cpp34
1 files changed, 22 insertions, 12 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
@@ -1,46 +1,52 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Linguist. 4** This file is part of Qt Linguist.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 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.
18** 24**
19**********************************************************************/ 25**********************************************************************/
20 26
21#include "metatranslator.h" 27#include "metatranslator.h"
22 28
23#include <qapplication.h> 29#include <qapplication.h>
24#include <qcstring.h> 30#include <qcstring.h>
25#include <qfile.h> 31#include <qfile.h>
26#include <qmessagebox.h> 32#include <qmessagebox.h>
27#include <qtextcodec.h> 33#include <qtextcodec.h>
28#include <qtextstream.h> 34#include <qtextstream.h>
29#include <qxml.h> 35#include <qxml.h>
30 36
31static bool encodingIsUtf8( const QXmlAttributes& atts ) 37static bool encodingIsUtf8( const QXmlAttributes& atts )
32{ 38{
33 for ( int i = 0; i < atts.length(); i++ ) { 39 for ( int i = 0; i < atts.length(); i++ ) {
34 // utf8="true" is a pre-3.0 syntax 40 // utf8="true" is a pre-3.0 syntax
35 if ( atts.qName(i) == QString("utf8") ) { 41 if ( atts.qName(i) == QString("utf8") ) {
36 return ( atts.value(i) == QString("true") ); 42 return ( atts.value(i) == QString("true") );
37 } else if ( atts.qName(i) == QString("encoding") ) { 43 } else if ( atts.qName(i) == QString("encoding") ) {
38 return ( atts.value(i) == QString("UTF-8") ); 44 return ( atts.value(i) == QString("UTF-8") );
39 } 45 }
40 } 46 }
41 return FALSE; 47 return FALSE;
42} 48}
43 49
44class TsHandler : public QXmlDefaultHandler 50class TsHandler : public QXmlDefaultHandler
45{ 51{
46public: 52public:
@@ -109,69 +115,71 @@ bool TsHandler::startElement( const QString& /* namespaceURI */,
109 for ( int i = 0; i < atts.length(); i++ ) { 115 for ( int i = 0; i < atts.length(); i++ ) {
110 if ( atts.qName(i) == QString("type") ) { 116 if ( atts.qName(i) == QString("type") ) {
111 if ( atts.value(i) == QString("unfinished") ) 117 if ( atts.value(i) == QString("unfinished") )
112 type = MetaTranslatorMessage::Unfinished; 118 type = MetaTranslatorMessage::Unfinished;
113 else if ( atts.value(i) == QString("obsolete") ) 119 else if ( atts.value(i) == QString("obsolete") )
114 type = MetaTranslatorMessage::Obsolete; 120 type = MetaTranslatorMessage::Obsolete;
115 else 121 else
116 type = MetaTranslatorMessage::Finished; 122 type = MetaTranslatorMessage::Finished;
117 } 123 }
118 } 124 }
119 } 125 }
120 accum.truncate( 0 ); 126 accum.truncate( 0 );
121 } 127 }
122 return TRUE; 128 return TRUE;
123} 129}
124 130
125bool TsHandler::endElement( const QString& /* namespaceURI */, 131bool TsHandler::endElement( const QString& /* namespaceURI */,
126 const QString& /* localName */, 132 const QString& /* localName */,
127 const QString& qName ) 133 const QString& qName )
128{ 134{
129 if ( qName == QString("codec") || qName == QString("defaultcodec") ) { 135 if ( qName == QString("codec") || qName == QString("defaultcodec") ) {
130 // "codec" is a pre-3.0 syntax 136 // "codec" is a pre-3.0 syntax
131 tor->setCodec( accum ); 137 tor->setCodec( accum );
132 } else if ( qName == QString("name") ) { 138 } else if ( qName == QString("name") ) {
133 context = accum; 139 context = accum;
134 } else if ( qName == QString("source") ) { 140 } else if ( qName == QString("source") ) {
135 source = accum; 141 source = accum;
136 } else if ( qName == QString("comment") ) { 142 } else if ( qName == QString("comment") ) {
137 if ( inMessage ) { 143 if ( inMessage ) {
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 }
149 } else if ( qName == QString("translation") ) { 157 } else if ( qName == QString("translation") ) {
150 translation = accum; 158 translation = accum;
151 } else if ( qName == QString("message") ) { 159 } else if ( qName == QString("message") ) {
152 if ( messageIsUtf8 ) 160 if ( messageIsUtf8 )
153 tor->insert( MetaTranslatorMessage(context.utf8(), source.utf8(), 161 tor->insert( MetaTranslatorMessage(context.utf8(), source.utf8(),
154 comment.utf8(), translation, 162 comment.utf8(), translation,
155 TRUE, type) ); 163 TRUE, type) );
156 else 164 else
157 tor->insert( MetaTranslatorMessage(context.ascii(), source.ascii(), 165 tor->insert( MetaTranslatorMessage(context.ascii(), source.ascii(),
158 comment.ascii(), translation, 166 comment.ascii(), translation,
159 FALSE, type) ); 167 FALSE, type) );
160 inMessage = FALSE; 168 inMessage = FALSE;
161 } 169 }
162 return TRUE; 170 return TRUE;
163} 171}
164 172
165bool TsHandler::characters( const QString& ch ) 173bool TsHandler::characters( const QString& ch )
166{ 174{
167 QString t = ch; 175 QString t = ch;
168 t.replace( "\r", "" ); 176 t.replace( "\r", "" );
169 accum += t; 177 accum += t;
170 return TRUE; 178 return TRUE;
171} 179}
172 180
173bool TsHandler::fatalError( const QXmlParseException& exception ) 181bool TsHandler::fatalError( const QXmlParseException& exception )
174{ 182{
175 if ( ferrorCount++ == 0 ) { 183 if ( ferrorCount++ == 0 ) {
176 QString msg; 184 QString msg;
177 msg.sprintf( "Parse error at line %d, column %d (%s).", 185 msg.sprintf( "Parse error at line %d, column %d (%s).",
@@ -286,273 +294,275 @@ MetaTranslatorMessage::MetaTranslatorMessage( const char *context,
286MetaTranslatorMessage::MetaTranslatorMessage( const MetaTranslatorMessage& m ) 294MetaTranslatorMessage::MetaTranslatorMessage( const MetaTranslatorMessage& m )
287 : QTranslatorMessage( m ), utfeight( m.utfeight ), ty( m.ty ) 295 : QTranslatorMessage( m ), utfeight( m.utfeight ), ty( m.ty )
288{ 296{
289} 297}
290 298
291MetaTranslatorMessage& MetaTranslatorMessage::operator=( 299MetaTranslatorMessage& MetaTranslatorMessage::operator=(
292 const MetaTranslatorMessage& m ) 300 const MetaTranslatorMessage& m )
293{ 301{
294 QTranslatorMessage::operator=( m ); 302 QTranslatorMessage::operator=( m );
295 utfeight = m.utfeight; 303 utfeight = m.utfeight;
296 ty = m.ty; 304 ty = m.ty;
297 return *this; 305 return *this;
298} 306}
299 307
300bool MetaTranslatorMessage::operator==( const MetaTranslatorMessage& m ) const 308bool MetaTranslatorMessage::operator==( const MetaTranslatorMessage& m ) const
301{ 309{
302 return qstrcmp( context(), m.context() ) == 0 && 310 return qstrcmp( context(), m.context() ) == 0 &&
303 qstrcmp( sourceText(), m.sourceText() ) == 0 && 311 qstrcmp( sourceText(), m.sourceText() ) == 0 &&
304 qstrcmp( comment(), m.comment() ) == 0; 312 qstrcmp( comment(), m.comment() ) == 0;
305} 313}
306 314
307bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const 315bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const
308{ 316{
309 int delta = qstrcmp( context(), m.context() ); 317 int delta = qstrcmp( context(), m.context() );
310 if ( delta == 0 ) 318 if ( delta == 0 )
311 delta = qstrcmp( sourceText(), m.sourceText() ); 319 delta = qstrcmp( sourceText(), m.sourceText() );
312 if ( delta == 0 ) 320 if ( delta == 0 )
313 delta = qstrcmp( comment(), m.comment() ); 321 delta = qstrcmp( comment(), m.comment() );
314 return delta < 0; 322 return delta < 0;
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 )
329{ 336{
330 mm = tor.mm; 337 mm = tor.mm;
331 codecName = tor.codecName; 338 codecName = tor.codecName;
332 codec = tor.codec; 339 codec = tor.codec;
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;
343 355
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"
351 "-only-CharData", FALSE ); 362 "-only-CharData", FALSE );
352 QXmlDefaultHandler *hand = new TsHandler( this ); 363 QXmlDefaultHandler *hand = new TsHandler( this );
353 reader.setContentHandler( hand ); 364 reader.setContentHandler( hand );
354 reader.setErrorHandler( hand ); 365 reader.setErrorHandler( hand );
355 366
356 bool ok = reader.parse( in ); 367 bool ok = reader.parse( in );
357 reader.setContentHandler( 0 ); 368 reader.setContentHandler( 0 );
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
366bool MetaTranslator::save( const QString& filename ) const 375bool MetaTranslator::save( const QString& filename ) const
367{ 376{
368 QFile f( filename ); 377 QFile f( filename );
369 if ( !f.open(IO_WriteOnly) ) 378 if ( !f.open(IO_WriteOnly) )
370 return FALSE; 379 return FALSE;
371 380
372 QTextStream t( &f ); 381 QTextStream t( &f );
373 t.setCodec( QTextCodec::codecForName("ISO-8859-1") ); 382 t.setCodec( QTextCodec::codecForName("ISO-8859-1") );
374 383
375 t << "<!DOCTYPE TS><TS>\n"; 384 t << "<!DOCTYPE TS><TS>\n";
376 if ( codecName != "ISO-8859-1" ) 385 if ( codecName != "ISO-8859-1" )
377 t << "<defaultcodec>" << codecName << "</defaultcodec>\n"; 386 t << "<defaultcodec>" << codecName << "</defaultcodec>\n";
378 TMM::ConstIterator m = mm.begin(); 387 TMM::ConstIterator m = mm.begin();
379 while ( m != mm.end() ) { 388 while ( m != mm.end() ) {
380 TMMInv inv; 389 TMMInv inv;
381 TMMInv::Iterator i; 390 TMMInv::Iterator i;
382 bool contextIsUtf8 = m.key().utf8(); 391 bool contextIsUtf8 = m.key().utf8();
383 QCString context = m.key().context(); 392 QCString context = m.key().context();
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() );
391 } 400 }
392 } else { 401 } else {
393 inv.insert( *m, m.key() ); 402 inv.insert( *m, m.key() );
394 } 403 }
395 } while ( ++m != mm.end() && QCString(m.key().context()) == context ); 404 } while ( ++m != mm.end() && QCString(m.key().context()) == context );
396 405
397 t << "<context"; 406 t << "<context";
398 if ( contextIsUtf8 ) 407 if ( contextIsUtf8 )
399 t << " encoding=\"UTF-8\""; 408 t << " encoding=\"UTF-8\"";
400 t << ">\n"; 409 t << ">\n";
401 t << " <name>" << evilBytes( context, contextIsUtf8 ) 410 t << " <name>" << evilBytes( context, contextIsUtf8 )
402 << "</name>\n"; 411 << "</name>\n";
403 if ( !comment.isEmpty() ) 412 if ( !comment.isEmpty() )
404 t << " <comment>" << evilBytes( comment, contextIsUtf8 ) 413 t << " <comment>" << evilBytes( comment, contextIsUtf8 )
405 << "</comment>\n"; 414 << "</comment>\n";
406 415
407 for ( i = inv.begin(); i != inv.end(); ++i ) { 416 for ( i = inv.begin(); i != inv.end(); ++i ) {
408 // no need for such noise 417 // no need for such noise
409 if ( (*i).type() == MetaTranslatorMessage::Obsolete && 418 if ( (*i).type() == MetaTranslatorMessage::Obsolete &&
410 (*i).translation().isEmpty() ) 419 (*i).translation().isEmpty() )
411 continue; 420 continue;
412 421
413 t << " <message"; 422 t << " <message";
414 if ( (*i).utf8() ) 423 if ( (*i).utf8() )
415 t << " encoding=\"UTF-8\""; 424 t << " encoding=\"UTF-8\"";
416 t << ">\n" 425 t << ">\n"
417 << " <source>" << evilBytes( (*i).sourceText(), 426 << " <source>" << evilBytes( (*i).sourceText(),
418 (*i).utf8() ) 427 (*i).utf8() )
419 << "</source>\n"; 428 << "</source>\n";
420 if ( !QCString((*i).comment()).isEmpty() ) 429 if ( !QCString((*i).comment()).isEmpty() )
421 t << " <comment>" << evilBytes( (*i).comment(), 430 t << " <comment>" << evilBytes( (*i).comment(),
422 (*i).utf8() ) 431 (*i).utf8() )
423 << "</comment>\n"; 432 << "</comment>\n";
424 t << " <translation"; 433 t << " <translation";
425 if ( (*i).type() == MetaTranslatorMessage::Unfinished ) 434 if ( (*i).type() == MetaTranslatorMessage::Unfinished )
426 t << " type=\"unfinished\""; 435 t << " type=\"unfinished\"";
427 else if ( (*i).type() == MetaTranslatorMessage::Obsolete ) 436 else if ( (*i).type() == MetaTranslatorMessage::Obsolete )
428 t << " type=\"obsolete\""; 437 t << " type=\"obsolete\"";
429 t << ">" << protect( (*i).translation().utf8() ) 438 t << ">" << protect( (*i).translation().utf8() )
430 << "</translation>\n"; 439 << "</translation>\n";
431 t << " </message>\n"; 440 t << " </message>\n";
432 } 441 }
433 t << "</context>\n"; 442 t << "</context>\n";
434 } 443 }
435 t << "</TS>\n"; 444 t << "</TS>\n";
436 f.close(); 445 f.close();
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;
444 int unfinished = 0; 454 int unfinished = 0;
445 int untranslated = 0; 455 int untranslated = 0;
446 TMM::ConstIterator m; 456 TMM::ConstIterator m;
447 457
448 for ( m = mm.begin(); m != mm.end(); ++m ) { 458 for ( m = mm.begin(); m != mm.end(); ++m ) {
449 if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { 459 if ( m.key().type() != MetaTranslatorMessage::Obsolete ) {
450 if ( m.key().translation().isEmpty() ) { 460 if ( m.key().translation().isEmpty() ) {
451 untranslated++; 461 untranslated++;
452 } else { 462 } else {
453 if ( m.key().type() == MetaTranslatorMessage::Unfinished ) 463 if ( m.key().type() == MetaTranslatorMessage::Unfinished )
454 unfinished++; 464 unfinished++;
455 else 465 else
456 finished++; 466 finished++;
457 467
458 QCString context = m.key().context(); 468 QCString context = m.key().context();
459 QCString sourceText = m.key().sourceText(); 469 QCString sourceText = m.key().sourceText();
460 QCString comment = m.key().comment(); 470 QCString comment = m.key().comment();
461 QString translation = m.key().translation(); 471 QString translation = m.key().translation();
462 472
463 /* 473 /*
464 Drop the comment in (context, sourceText, comment), 474 Drop the comment in (context, sourceText, comment),
465 unless (context, sourceText, "") already exists, or 475 unless (context, sourceText, "") already exists, or
466 unless we already dropped the comment of (context, 476 unless we already dropped the comment of (context,
467 sourceText, comment0). 477 sourceText, comment0).
468 */ 478 */
469 if ( comment.isEmpty() 479 if ( comment.isEmpty()
470 || contains(context, sourceText, "") 480 || contains(context, sourceText, "")
471 || !tor.findMessage(context, sourceText, "").translation() 481 || !tor.findMessage(context, sourceText, "").translation()
472 .isNull() ) { 482 .isNull() ) {
473 tor.insert( m.key() ); 483 tor.insert( m.key() );
474 } else { 484 } else {
475 tor.insert( QTranslatorMessage(context, sourceText, "", 485 tor.insert( QTranslatorMessage(context, sourceText, "",
476 translation) ); 486 translation) );
477 } 487 }
478 } 488 }
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",
486 finished, unfinished, untranslated ); 496 finished, unfinished, untranslated );
487 497
488 return saved; 498 return saved;
489} 499}
490 500
491bool MetaTranslator::contains( const char *context, const char *sourceText, 501bool MetaTranslator::contains( const char *context, const char *sourceText,
492 const char *comment ) const 502 const char *comment ) const
493{ 503{
494 return mm.find( MetaTranslatorMessage(context, sourceText, comment) ) != 504 return mm.find( MetaTranslatorMessage(context, sourceText, comment) ) !=
495 mm.end(); 505 mm.end();
496} 506}
497 507
498void MetaTranslator::insert( const MetaTranslatorMessage& m ) 508void MetaTranslator::insert( const MetaTranslatorMessage& m )
499{ 509{
500 int pos = mm.count(); 510 int pos = mm.count();
501 TMM::Iterator n = mm.find( m ); 511 TMM::Iterator n = mm.find( m );
502 if ( n != mm.end() ) 512 if ( n != mm.end() )
503 pos = *n; 513 pos = *n;
504 mm.replace( m, pos ); 514 mm.replace( m, pos );
505} 515}
506 516
507void MetaTranslator::stripObsoleteMessages() 517void MetaTranslator::stripObsoleteMessages()
508{ 518{
509 TMM newmm; 519 TMM newmm;
510 520
511 TMM::Iterator m = mm.begin(); 521 TMM::Iterator m = mm.begin();
512 while ( m != mm.end() ) { 522 while ( m != mm.end() ) {
513 if ( m.key().type() != MetaTranslatorMessage::Obsolete ) 523 if ( m.key().type() != MetaTranslatorMessage::Obsolete )
514 newmm.insert( m.key(), *m ); 524 newmm.insert( m.key(), *m );
515 ++m; 525 ++m;
516 } 526 }
517 mm = newmm; 527 mm = newmm;
518} 528}
519 529
520void MetaTranslator::stripEmptyContexts() 530void MetaTranslator::stripEmptyContexts()
521{ 531{
522 TMM newmm; 532 TMM newmm;
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
530 if ( n != newmm.end() && 540 if ( n != newmm.end() &&
531 qstrcmp(m.key().context(), n.key().context()) == 0 ) 541 qstrcmp(m.key().context(), n.key().context()) == 0 )
532 newmm.insert( m.key(), *m ); 542 newmm.insert( m.key(), *m );
533 } else { 543 } else {
534 newmm.insert( m.key(), *m ); 544 newmm.insert( m.key(), *m );
535 } 545 }
536 ++m; 546 ++m;
537 } 547 }
538 mm = newmm; 548 mm = newmm;
539} 549}
540 550
541void MetaTranslator::setCodec( const char *name ) 551void MetaTranslator::setCodec( const char *name )
542{ 552{
543 const int latin1 = 4; 553 const int latin1 = 4;
544 554
545 codecName = name; 555 codecName = name;
546 codec = QTextCodec::codecForName( name ); 556 codec = QTextCodec::codecForName( name );
547 if ( codec == 0 || codec->mibEnum() == latin1 ) 557 if ( codec == 0 || codec->mibEnum() == latin1 )
548 codec = 0; 558 codec = 0;
549} 559}
550 560
551QString MetaTranslator::toUnicode( const char *str, bool utf8 ) const 561QString MetaTranslator::toUnicode( const char *str, bool utf8 ) const
552{ 562{
553 if ( utf8 ) 563 if ( utf8 )
554 return QString::fromUtf8( str ); 564 return QString::fromUtf8( str );
555 else if ( codec == 0 ) 565 else if ( codec == 0 )
556 return QString( str ); 566 return QString( str );
557 else 567 else
558 return codec->toUnicode( str ); 568 return codec->toUnicode( str );