Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

merge.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 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 // defined in numberh.cpp
00030 extern void applyNumberHeuristic( MetaTranslator *tor, bool verbose );
00031 // defined in sametexth.cpp
00032 extern void applySameTextHeuristic( MetaTranslator *tor, bool verbose );
00033 
00034 typedef QValueList<MetaTranslatorMessage> TML;
00035 
00036 /*
00037   Merges two MetaTranslator objects into the first one. The first one
00038   is a set of source texts and translations for a previous version of
00039   the internationalized program; the second one is a set of fresh
00040   source texts newly extracted from the source code, without any
00041   translation yet.
00042 */
00043 
00044 void merge( MetaTranslator *tor, const MetaTranslator *virginTor, bool verbose )
00045 {
00046     int known = 0;
00047     int neww = 0;
00048     int obsoleted = 0;
00049     TML all = tor->messages();
00050     TML::Iterator it;
00051 
00052     /*
00053       The types of all the messages from the vernacular translator
00054       are updated according to the virgin translator.
00055     */
00056     for ( it = all.begin(); it != all.end(); ++it ) {
00057         MetaTranslatorMessage::Type newType;
00058         MetaTranslatorMessage m = *it;
00059 
00060         // skip context comment
00061         if ( !QCString((*it).sourceText()).isEmpty() ) {
00062             if ( !virginTor->contains((*it).context(), (*it).sourceText(),
00063                                       (*it).comment()) ) {
00064                 newType = MetaTranslatorMessage::Obsolete;
00065                 if ( m.type() != MetaTranslatorMessage::Obsolete )
00066                     obsoleted++;
00067             } else {
00068                 switch ( m.type() ) {
00069                 case MetaTranslatorMessage::Finished:
00070                     newType = MetaTranslatorMessage::Finished;
00071                     known++;
00072                     break;
00073                 case MetaTranslatorMessage::Unfinished:
00074                     newType = MetaTranslatorMessage::Unfinished;
00075                     known++;
00076                     break;
00077                 case MetaTranslatorMessage::Obsolete:
00078                     newType = MetaTranslatorMessage::Unfinished;
00079                     neww++;
00080                 }
00081             }
00082 
00083             if ( newType != m.type() ) {
00084                 m.setType( newType );
00085                 tor->insert( m );
00086             }
00087         }
00088     }
00089 
00090     /*
00091       Messages found only in the virgin translator are added to the
00092       vernacular translator. Among these are all the context comments.
00093     */
00094     all = virginTor->messages();
00095 
00096     for ( it = all.begin(); it != all.end(); ++it ) {
00097         if ( !tor->contains((*it).context(), (*it).sourceText(),
00098                             (*it).comment()) ) {
00099             tor->insert( *it );
00100             if ( !QCString((*it).sourceText()).isEmpty() )
00101                 neww++;
00102         }
00103     }
00104 
00105     /*
00106       The same-text heuristic handles cases where a message has an
00107       obsolete counterpart with a different context or comment.
00108     */
00109     applySameTextHeuristic( tor, verbose );
00110 
00111     /*
00112       The number heuristic handles cases where a message has an
00113       obsolete counterpart with mostly numbers differing in the
00114       source text.
00115     */
00116     applyNumberHeuristic( tor, verbose );
00117 
00118     if ( verbose )
00119         fprintf( stderr, " %d known, %d new and %d obsoleted messages\n", known,
00120                  neww, obsoleted );
00121 }

Generated on Sat Nov 5 16:15:58 2005 for OPIE by  doxygen 1.4.2