Diffstat (limited to 'development/translation/shared/metatranslator.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | development/translation/shared/metatranslator.cpp | 34 |
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 | |||
@@ -5,16 +5,22 @@ | |||
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 | ||
@@ -135,17 +141,19 @@ bool TsHandler::endElement( const QString& /* namespaceURI */, | |||
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") ) { |
@@ -312,42 +320,45 @@ bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const | |||
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 | ||
317 | MetaTranslator::MetaTranslator() | 325 | MetaTranslator::MetaTranslator() |
318 | : codecName( "ISO-8859-1" ), codec( 0 ) | ||
319 | { | 326 | { |
327 | clear(); | ||
320 | } | 328 | } |
321 | 329 | ||
322 | MetaTranslator::MetaTranslator( const MetaTranslator& tor ) | 330 | MetaTranslator::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 | ||
328 | MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) | 335 | MetaTranslator& 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 | ||
336 | bool MetaTranslator::load( const QString& filename ) | 343 | void MetaTranslator::clear() |
337 | { | 344 | { |
338 | mm.clear(); | 345 | mm.clear(); |
346 | codecName = "ISO-8859-1"; | ||
347 | codec = 0; | ||
348 | } | ||
339 | 349 | ||
350 | bool 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 ); |
@@ -355,14 +366,12 @@ bool MetaTranslator::load( const QString& filename ) | |||
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 | ||
366 | bool MetaTranslator::save( const QString& filename ) const | 375 | bool MetaTranslator::save( const QString& filename ) const |
367 | { | 376 | { |
368 | QFile f( filename ); | 377 | QFile f( filename ); |
@@ -381,13 +390,13 @@ bool MetaTranslator::save( const QString& filename ) const | |||
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() ); |
@@ -434,13 +443,14 @@ bool MetaTranslator::save( const QString& filename ) const | |||
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 | ||
440 | bool MetaTranslator::release( const QString& filename, bool verbose ) const | 449 | bool 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; |
@@ -476,13 +486,13 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const | |||
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; |
@@ -520,13 +530,13 @@ void MetaTranslator::stripObsoleteMessages() | |||
520 | void MetaTranslator::stripEmptyContexts() | 530 | void 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 ); |