00001 /********************************************************************** 00002 ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 00003 ** 00004 ** This file is part of Qt Linguist. 00005 ** 00006 ** This file may be distributed and/or modified under the terms of the 00007 ** GNU General Public License version 2 as published by the Free Software 00008 ** Foundation and appearing in the file LICENSE.GPL included in the 00009 ** packaging of this file. 00010 ** 00011 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00012 ** licenses may use this file in accordance with the Qt Commercial License 00013 ** Agreement provided with the Software. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00019 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00020 ** information about Qt Commercial License Agreements. 00021 ** 00022 ** Contact info@trolltech.com if any conditions of this licensing are 00023 ** not clear to you. 00024 ** 00025 **********************************************************************/ 00026 00027 #include <metatranslator.h> 00028 00029 #include <qcstring.h> 00030 #include <qmap.h> 00031 00032 typedef QMap<QCString, MetaTranslatorMessage> TMM; 00033 typedef QValueList<MetaTranslatorMessage> TML; 00034 00035 /* 00036 Augments a MetaTranslator with trivially derived translations. 00037 00038 For example, if "Enabled:" is consistendly translated as "Eingeschaltet:" no 00039 matter the context or the comment, "Eingeschaltet:" is added as the 00040 translation of any untranslated "Enabled:" text and is marked Unfinished. 00041 */ 00042 00043 void applySameTextHeuristic( MetaTranslator *tor, bool verbose ) 00044 { 00045 TMM translated; 00046 TMM avoid; 00047 TMM::Iterator t; 00048 TML untranslated; 00049 TML::Iterator u; 00050 TML all = tor->messages(); 00051 TML::Iterator it; 00052 int inserted = 0; 00053 00054 for ( it = all.begin(); it != all.end(); ++it ) { 00055 if ( (*it).type() == MetaTranslatorMessage::Unfinished ) { 00056 if ( (*it).translation().isEmpty() ) 00057 untranslated.append( *it ); 00058 } else { 00059 QCString key = (*it).sourceText(); 00060 t = translated.find( key ); 00061 if ( t != translated.end() ) { 00062 /* 00063 The same source text is translated at least two 00064 different ways. Do nothing then. 00065 */ 00066 if ( (*t).translation() != (*it).translation() ) { 00067 translated.remove( key ); 00068 avoid.insert( key, *it ); 00069 } 00070 } else if ( !avoid.contains(key) && 00071 !(*it).translation().isEmpty() ) { 00072 translated.insert( key, *it ); 00073 } 00074 } 00075 } 00076 00077 for ( u = untranslated.begin(); u != untranslated.end(); ++u ) { 00078 QCString key = (*u).sourceText(); 00079 t = translated.find( key ); 00080 if ( t != translated.end() ) { 00081 MetaTranslatorMessage m( *u ); 00082 m.setTranslation( (*t).translation() ); 00083 tor->insert( m ); 00084 inserted++; 00085 } 00086 } 00087 if ( verbose && inserted != 0 ) 00088 fprintf( stderr, " same-text heuristic provided %d translation%s\n", 00089 inserted, inserted == 1 ? "" : "s" ); 00090 }
1.4.2