summaryrefslogtreecommitdiff
path: root/development/translation/opie-lupdate/merge.cpp
Unidiff
Diffstat (limited to 'development/translation/opie-lupdate/merge.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--development/translation/opie-lupdate/merge.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/development/translation/opie-lupdate/merge.cpp b/development/translation/opie-lupdate/merge.cpp
new file mode 100644
index 0000000..a96104e
--- a/dev/null
+++ b/development/translation/opie-lupdate/merge.cpp
@@ -0,0 +1,115 @@
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** 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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <metatranslator.h>
22
23// defined in numberh.cpp
24extern void applyNumberHeuristic( MetaTranslator *tor, bool verbose );
25// defined in sametexth.cpp
26extern void applySameTextHeuristic( MetaTranslator *tor, bool verbose );
27
28typedef QValueList<MetaTranslatorMessage> TML;
29
30/*
31 Merges two MetaTranslator objects into the first one. The first one
32 is a set of source texts and translations for a previous version of
33 the internationalized program; the second one is a set of fresh
34 source texts newly extracted from the source code, without any
35 translation yet.
36*/
37
38void merge( MetaTranslator *tor, const MetaTranslator *virginTor, bool verbose )
39{
40 int known = 0;
41 int neww = 0;
42 int obsoleted = 0;
43 TML all = tor->messages();
44 TML::Iterator it;
45
46 /*
47 The types of all the messages from the vernacular translator
48 are updated according to the virgin translator.
49 */
50 for ( it = all.begin(); it != all.end(); ++it ) {
51 MetaTranslatorMessage::Type newType;
52 MetaTranslatorMessage m = *it;
53
54 // skip context comment
55 if ( !QCString((*it).sourceText()).isEmpty() ) {
56 if ( !virginTor->contains((*it).context(), (*it).sourceText(),
57 (*it).comment()) ) {
58 newType = MetaTranslatorMessage::Obsolete;
59 if ( m.type() != MetaTranslatorMessage::Obsolete )
60 obsoleted++;
61 } else {
62 switch ( m.type() ) {
63 case MetaTranslatorMessage::Finished:
64 newType = MetaTranslatorMessage::Finished;
65 known++;
66 break;
67 case MetaTranslatorMessage::Unfinished:
68 newType = MetaTranslatorMessage::Unfinished;
69 known++;
70 break;
71 case MetaTranslatorMessage::Obsolete:
72 newType = MetaTranslatorMessage::Unfinished;
73 neww++;
74 }
75 }
76
77 if ( newType != m.type() ) {
78 m.setType( newType );
79 tor->insert( m );
80 }
81 }
82 }
83
84 /*
85 Messages found only in the virgin translator are added to the
86 vernacular translator. Among these are all the context comments.
87 */
88 all = virginTor->messages();
89
90 for ( it = all.begin(); it != all.end(); ++it ) {
91 if ( !tor->contains((*it).context(), (*it).sourceText(),
92 (*it).comment()) ) {
93 tor->insert( *it );
94 if ( !QCString((*it).sourceText()).isEmpty() )
95 neww++;
96 }
97 }
98
99 /*
100 The same-text heuristic handles cases where a message has an
101 obsolete counterpart with a different context or comment.
102 */
103 applySameTextHeuristic( tor, verbose );
104
105 /*
106 The number heuristic handles cases where a message has an
107 obsolete counterpart with mostly numbers differing in the
108 source text.
109 */
110 applyNumberHeuristic( tor, verbose );
111
112 if ( verbose )
113 fprintf( stderr, " %d known, %d new and %d obsoleted messages\n", known,
114 neww, obsoleted );
115}