source: trunk/tools/linguist/lupdate/sametexth.cpp@ 7

Last change on this file since 7 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.0 KB
Line 
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** 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#include <qcstring.h>
30#include <qmap.h>
31
32typedef QMap<QCString, MetaTranslatorMessage> TMM;
33typedef QValueList<MetaTranslatorMessage> TML;
34
35/*
36 Augments a MetaTranslator with trivially derived translations.
37
38 For example, if "Enabled:" is consistendly translated as "Eingeschaltet:" no
39 matter the context or the comment, "Eingeschaltet:" is added as the
40 translation of any untranslated "Enabled:" text and is marked Unfinished.
41*/
42
43void applySameTextHeuristic( MetaTranslator *tor, bool verbose )
44{
45 TMM translated;
46 TMM avoid;
47 TMM::Iterator t;
48 TML untranslated;
49 TML::Iterator u;
50 TML all = tor->messages();
51 TML::Iterator it;
52 int inserted = 0;
53
54 for ( it = all.begin(); it != all.end(); ++it ) {
55 if ( (*it).type() == MetaTranslatorMessage::Unfinished ) {
56 if ( (*it).translation().isEmpty() )
57 untranslated.append( *it );
58 } else {
59 QCString key = (*it).sourceText();
60 t = translated.find( key );
61 if ( t != translated.end() ) {
62 /*
63 The same source text is translated at least two
64 different ways. Do nothing then.
65 */
66 if ( (*t).translation() != (*it).translation() ) {
67 translated.remove( key );
68 avoid.insert( key, *it );
69 }
70 } else if ( !avoid.contains(key) &&
71 !(*it).translation().isEmpty() ) {
72 translated.insert( key, *it );
73 }
74 }
75 }
76
77 for ( u = untranslated.begin(); u != untranslated.end(); ++u ) {
78 QCString key = (*u).sourceText();
79 t = translated.find( key );
80 if ( t != translated.end() ) {
81 MetaTranslatorMessage m( *u );
82 m.setTranslation( (*t).translation() );
83 tor->insert( m );
84 inserted++;
85 }
86 }
87 if ( verbose && inserted != 0 )
88 fprintf( stderr, " same-text heuristic provided %d translation%s\n",
89 inserted, inserted == 1 ? "" : "s" );
90}
Note: See TracBrowser for help on using the repository browser.