source: trunk/tools/linguist/lupdate/merge.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Linguist.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
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**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
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.
21**
22** Contact info@trolltech.com if any conditions of this licensing are
23** not clear to you.
24**
25**********************************************************************/
26
27#include <metatranslator.h>
28
29// defined in numberh.cpp
30extern void applyNumberHeuristic( MetaTranslator *tor, bool verbose );
31// defined in sametexth.cpp
32extern void applySameTextHeuristic( MetaTranslator *tor, bool verbose );
33
34typedef QValueList<MetaTranslatorMessage> TML;
35
36/*
37 Merges two MetaTranslator objects into the first one. The first one
38 is a set of source texts and translations for a previous version of
39 the internationalized program; the second one is a set of fresh
40 source texts newly extracted from the source code, without any
41 translation yet.
42*/
43
44void merge( MetaTranslator *tor, const MetaTranslator *virginTor, bool verbose )
45{
46 int known = 0;
47 int neww = 0;
48 int obsoleted = 0;
49 TML all = tor->messages();
50 TML::Iterator it;
51
52 /*
53 The types of all the messages from the vernacular translator
54 are updated according to the virgin translator.
55 */
56 for ( it = all.begin(); it != all.end(); ++it ) {
57 MetaTranslatorMessage::Type newType;
58 MetaTranslatorMessage m = *it;
59
60 // skip context comment
61 if ( !QCString((*it).sourceText()).isEmpty() ) {
62 if ( !virginTor->contains((*it).context(), (*it).sourceText(),
63 (*it).comment()) ) {
64 newType = MetaTranslatorMessage::Obsolete;
65 if ( m.type() != MetaTranslatorMessage::Obsolete )
66 obsoleted++;
67 } else {
68 switch ( m.type() ) {
69 case MetaTranslatorMessage::Finished:
70 newType = MetaTranslatorMessage::Finished;
71 known++;
72 break;
73 case MetaTranslatorMessage::Unfinished:
74 default:
75 newType = MetaTranslatorMessage::Unfinished;
76 known++;
77 break;
78 case MetaTranslatorMessage::Obsolete:
79 newType = MetaTranslatorMessage::Unfinished;
80 neww++;
81 }
82 }
83
84 if ( newType != m.type() ) {
85 m.setType( newType );
86 tor->insert( m );
87 }
88 }
89 }
90
91 /*
92 Messages found only in the virgin translator are added to the
93 vernacular translator. Among these are all the context comments.
94 */
95 all = virginTor->messages();
96
97 for ( it = all.begin(); it != all.end(); ++it ) {
98 if ( !tor->contains((*it).context(), (*it).sourceText(),
99 (*it).comment()) ) {
100 tor->insert( *it );
101 if ( !QCString((*it).sourceText()).isEmpty() )
102 neww++;
103 }
104 }
105
106 /*
107 The same-text heuristic handles cases where a message has an
108 obsolete counterpart with a different context or comment.
109 */
110 applySameTextHeuristic( tor, verbose );
111
112 /*
113 The number heuristic handles cases where a message has an
114 obsolete counterpart with mostly numbers differing in the
115 source text.
116 */
117 applyNumberHeuristic( tor, verbose );
118
119 if ( verbose )
120 fprintf( stderr, " %d known, %d new and %d obsoleted messages\n", known,
121 neww, obsoleted );
122}
Note: See TracBrowser for help on using the repository browser.