author | zecke <zecke> | 2004-01-09 19:13:35 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-01-09 19:13:35 (UTC) |
commit | 56bb9961db1158250bbfe971f4556b56c0bd6581 (patch) (side-by-side diff) | |
tree | a4f40da98f695b5aadd845b68aaab41ac3d81826 /development/translation/shared/metatranslator.cpp | |
parent | 6875988077013544246ae0df7cc2e5d538a7f152 (diff) | |
download | opie-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) (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 @@ -1,30 +1,36 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of Qt Linguist. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** +** 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 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** 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. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "metatranslator.h" #include <qapplication.h> #include <qcstring.h> #include <qfile.h> #include <qmessagebox.h> #include <qtextcodec.h> #include <qtextstream.h> #include <qxml.h> @@ -125,37 +131,39 @@ bool TsHandler::startElement( const QString& /* namespaceURI */, bool TsHandler::endElement( const QString& /* namespaceURI */, const QString& /* localName */, const QString& qName ) { if ( qName == QString("codec") || qName == QString("defaultcodec") ) { // "codec" is a pre-3.0 syntax tor->setCodec( accum ); } else if ( qName == QString("name") ) { context = accum; } else if ( qName == QString("source") ) { source = accum; } else if ( qName == QString("comment") ) { if ( inMessage ) { comment = accum; } else { if ( contextIsUtf8 ) - tor->insert( MetaTranslatorMessage(context.utf8(), "", + tor->insert( MetaTranslatorMessage(context.utf8(), + ContextComment, accum.utf8(), QString::null, TRUE, MetaTranslatorMessage::Unfinished) ); else - tor->insert( MetaTranslatorMessage(context.ascii(), "", + tor->insert( MetaTranslatorMessage(context.ascii(), + ContextComment, accum.ascii(), QString::null, FALSE, MetaTranslatorMessage::Unfinished) ); } } else if ( qName == QString("translation") ) { translation = accum; } else if ( qName == QString("message") ) { if ( messageIsUtf8 ) tor->insert( MetaTranslatorMessage(context.utf8(), source.utf8(), comment.utf8(), translation, TRUE, type) ); else tor->insert( MetaTranslatorMessage(context.ascii(), source.ascii(), comment.ascii(), translation, FALSE, type) ); inMessage = FALSE; } @@ -302,102 +310,103 @@ bool MetaTranslatorMessage::operator==( const MetaTranslatorMessage& m ) const return qstrcmp( context(), m.context() ) == 0 && qstrcmp( sourceText(), m.sourceText() ) == 0 && qstrcmp( comment(), m.comment() ) == 0; } bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const { int delta = qstrcmp( context(), m.context() ); if ( delta == 0 ) delta = qstrcmp( sourceText(), m.sourceText() ); if ( delta == 0 ) delta = qstrcmp( comment(), m.comment() ); return delta < 0; } MetaTranslator::MetaTranslator() - : codecName( "ISO-8859-1" ), codec( 0 ) { + clear(); } MetaTranslator::MetaTranslator( const MetaTranslator& tor ) : mm( tor.mm ), codecName( tor.codecName ), codec( tor.codec ) { - } MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) { mm = tor.mm; codecName = tor.codecName; codec = tor.codec; return *this; } -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 ); if ( !f.open(IO_ReadOnly) ) return FALSE; QTextStream t( &f ); QXmlInputSource in( t ); QXmlSimpleReader reader; - // don't click on these! reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" "-only-CharData", FALSE ); QXmlDefaultHandler *hand = new TsHandler( this ); reader.setContentHandler( hand ); reader.setErrorHandler( hand ); bool ok = reader.parse( in ); reader.setContentHandler( 0 ); reader.setErrorHandler( 0 ); delete hand; f.close(); - if ( !ok ) - mm.clear(); return ok; } bool MetaTranslator::save( const QString& filename ) const { QFile f( filename ); if ( !f.open(IO_WriteOnly) ) return FALSE; QTextStream t( &f ); t.setCodec( QTextCodec::codecForName("ISO-8859-1") ); t << "<!DOCTYPE TS><TS>\n"; if ( codecName != "ISO-8859-1" ) t << "<defaultcodec>" << codecName << "</defaultcodec>\n"; TMM::ConstIterator m = mm.begin(); while ( m != mm.end() ) { TMMInv inv; TMMInv::Iterator i; bool contextIsUtf8 = m.key().utf8(); QCString context = m.key().context(); QCString comment = ""; do { - if ( QCString(m.key().sourceText()).isEmpty() ) { + if ( QCString(m.key().sourceText()) == ContextComment ) { if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { contextIsUtf8 = m.key().utf8(); comment = QCString( m.key().comment() ); } } else { inv.insert( *m, m.key() ); } } while ( ++m != mm.end() && QCString(m.key().context()) == context ); t << "<context"; if ( contextIsUtf8 ) t << " encoding=\"UTF-8\""; t << ">\n"; t << " <name>" << evilBytes( context, contextIsUtf8 ) << "</name>\n"; if ( !comment.isEmpty() ) @@ -424,33 +433,34 @@ bool MetaTranslator::save( const QString& filename ) const t << " <translation"; if ( (*i).type() == MetaTranslatorMessage::Unfinished ) t << " type=\"unfinished\""; else if ( (*i).type() == MetaTranslatorMessage::Obsolete ) t << " type=\"obsolete\""; t << ">" << protect( (*i).translation().utf8() ) << "</translation>\n"; t << " </message>\n"; } t << "</context>\n"; } t << "</TS>\n"; f.close(); return TRUE; } -bool MetaTranslator::release( const QString& filename, bool verbose ) const +bool MetaTranslator::release( const QString& filename, bool verbose, + QTranslator::SaveMode mode ) const { QTranslator tor( 0 ); int finished = 0; int unfinished = 0; int untranslated = 0; TMM::ConstIterator m; for ( m = mm.begin(); m != mm.end(); ++m ) { if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { if ( m.key().translation().isEmpty() ) { untranslated++; } else { if ( m.key().type() == MetaTranslatorMessage::Unfinished ) unfinished++; else finished++; @@ -466,33 +476,33 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const unless we already dropped the comment of (context, sourceText, comment0). */ if ( comment.isEmpty() || contains(context, sourceText, "") || !tor.findMessage(context, sourceText, "").translation() .isNull() ) { tor.insert( m.key() ); } else { tor.insert( QTranslatorMessage(context, sourceText, "", translation) ); } } } } - bool saved = tor.save( filename, QTranslator::Stripped ); + bool saved = tor.save( filename, mode ); if ( saved && verbose ) fprintf( stderr, " %d finished, %d unfinished and %d untranslated messages\n", finished, unfinished, untranslated ); return saved; } bool MetaTranslator::contains( const char *context, const char *sourceText, const char *comment ) const { return mm.find( MetaTranslatorMessage(context, sourceText, comment) ) != mm.end(); } void MetaTranslator::insert( const MetaTranslatorMessage& m ) @@ -510,33 +520,33 @@ void MetaTranslator::stripObsoleteMessages() TMM::Iterator m = mm.begin(); while ( m != mm.end() ) { if ( m.key().type() != MetaTranslatorMessage::Obsolete ) newmm.insert( m.key(), *m ); ++m; } mm = newmm; } void MetaTranslator::stripEmptyContexts() { TMM newmm; TMM::Iterator m = mm.begin(); while ( m != mm.end() ) { - if ( QCString(m.key().sourceText()).isEmpty() ) { + if ( QCString(m.key().sourceText()) == ContextComment ) { TMM::Iterator n = m; ++n; // the context comment is followed by other messages if ( n != newmm.end() && qstrcmp(m.key().context(), n.key().context()) == 0 ) newmm.insert( m.key(), *m ); } else { newmm.insert( m.key(), *m ); } ++m; } mm = newmm; } void MetaTranslator::setCodec( const char *name ) { |