Diffstat (limited to 'development/translation/opie-lupdate/sametexth.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | development/translation/opie-lupdate/sametexth.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/development/translation/opie-lupdate/sametexth.cpp b/development/translation/opie-lupdate/sametexth.cpp new file mode 100644 index 0000000..574cfd5 --- a/dev/null +++ b/development/translation/opie-lupdate/sametexth.cpp | |||
@@ -0,0 +1,84 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 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 | #include <qcstring.h> | ||
24 | #include <qmap.h> | ||
25 | |||
26 | typedef QMap<QCString, MetaTranslatorMessage> TMM; | ||
27 | typedef QValueList<MetaTranslatorMessage> TML; | ||
28 | |||
29 | /* | ||
30 | Augments a MetaTranslator with trivially derived translations. | ||
31 | |||
32 | For example, if "Enabled:" is consistendly translated as "Eingeschaltet:" no | ||
33 | matter the context or the comment, "Eingeschaltet:" is added as the | ||
34 | translation of any untranslated "Enabled:" text and is marked Unfinished. | ||
35 | */ | ||
36 | |||
37 | void applySameTextHeuristic( MetaTranslator *tor, bool verbose ) | ||
38 | { | ||
39 | TMM translated; | ||
40 | TMM avoid; | ||
41 | TMM::Iterator t; | ||
42 | TML untranslated; | ||
43 | TML::Iterator u; | ||
44 | TML all = tor->messages(); | ||
45 | TML::Iterator it; | ||
46 | int inserted = 0; | ||
47 | |||
48 | for ( it = all.begin(); it != all.end(); ++it ) { | ||
49 | if ( (*it).type() == MetaTranslatorMessage::Unfinished ) { | ||
50 | if ( (*it).translation().isEmpty() ) | ||
51 | untranslated.append( *it ); | ||
52 | } else { | ||
53 | QCString key = (*it).sourceText(); | ||
54 | t = translated.find( key ); | ||
55 | if ( t != translated.end() ) { | ||
56 | /* | ||
57 | The same source text is translated at least two | ||
58 | different ways. Do nothing then. | ||
59 | */ | ||
60 | if ( (*t).translation() != (*it).translation() ) { | ||
61 | translated.remove( key ); | ||
62 | avoid.insert( key, *it ); | ||
63 | } | ||
64 | } else if ( !avoid.contains(key) && | ||
65 | !(*it).translation().isEmpty() ) { | ||
66 | translated.insert( key, *it ); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | for ( u = untranslated.begin(); u != untranslated.end(); ++u ) { | ||
72 | QCString key = (*u).sourceText(); | ||
73 | t = translated.find( key ); | ||
74 | if ( t != translated.end() ) { | ||
75 | MetaTranslatorMessage m( *u ); | ||
76 | m.setTranslation( (*t).translation() ); | ||
77 | tor->insert( m ); | ||
78 | inserted++; | ||
79 | } | ||
80 | } | ||
81 | if ( verbose && inserted != 0 ) | ||
82 | fprintf( stderr, " same-text heuristic provided %d translation%s\n", | ||
83 | inserted, inserted == 1 ? "" : "s" ); | ||
84 | } | ||