author | zecke <zecke> | 2004-01-09 19:13:35 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-01-09 19:13:35 (UTC) |
commit | 56bb9961db1158250bbfe971f4556b56c0bd6581 (patch) (unidiff) | |
tree | a4f40da98f695b5aadd845b68aaab41ac3d81826 /development/translation/opie-lupdate/numberh.cpp | |
parent | 6875988077013544246ae0df7cc2e5d538a7f152 (diff) | |
download | opie-56bb9961db1158250bbfe971f4556b56c0bd6581.zip opie-56bb9961db1158250bbfe971f4556b56c0bd6581.tar.gz opie-56bb9961db1158250bbfe971f4556b56c0bd6581.tar.bz2 |
Update lupdate and shared to Qt3.3 qt-copy sources
Some special replacement for $$(OPIEDIR) to make ar_* happy
Diffstat (limited to 'development/translation/opie-lupdate/numberh.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | development/translation/opie-lupdate/numberh.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/development/translation/opie-lupdate/numberh.cpp b/development/translation/opie-lupdate/numberh.cpp index f7b7bf8..2f12c3d 100644 --- a/development/translation/opie-lupdate/numberh.cpp +++ b/development/translation/opie-lupdate/numberh.cpp | |||
@@ -1,72 +1,78 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 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 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** 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. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 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. | ||
15 | ** | 21 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #include <metatranslator.h> | 27 | #include <metatranslator.h> |
22 | 28 | ||
23 | #include <qmemarray.h> | 29 | #include <qmemarray.h> |
24 | #include <qcstring.h> | 30 | #include <qcstring.h> |
25 | #include <qmap.h> | 31 | #include <qmap.h> |
26 | #include <qstringlist.h> | 32 | #include <qstringlist.h> |
27 | 33 | ||
28 | #include <ctype.h> | 34 | #include <ctype.h> |
29 | 35 | ||
30 | typedef QMap<QCString, MetaTranslatorMessage> TMM; | 36 | typedef QMap<QCString, MetaTranslatorMessage> TMM; |
31 | typedef QValueList<MetaTranslatorMessage> TML; | 37 | typedef QValueList<MetaTranslatorMessage> TML; |
32 | 38 | ||
33 | static bool isDigitFriendly( int c ) | 39 | static bool isDigitFriendly( int c ) |
34 | { | 40 | { |
35 | return ispunct( c ) || isspace( c ); | 41 | return ispunct((uchar)c) || isspace((uchar)c); |
36 | } | 42 | } |
37 | 43 | ||
38 | static int numberLength( const char *s ) | 44 | static int numberLength( const char *s ) |
39 | { | 45 | { |
40 | int i = 0; | 46 | int i = 0; |
41 | 47 | ||
42 | if ( isdigit(s[0]) ) { | 48 | if ( isdigit((uchar)s[0]) ) { |
43 | do { | 49 | do { |
44 | i++; | 50 | i++; |
45 | } while ( isdigit(s[i]) || | 51 | } while (isdigit((uchar)s[i]) || |
46 | (isDigitFriendly(s[i]) && | 52 | (isDigitFriendly(s[i]) && |
47 | (isdigit(s[i + 1]) || | 53 | (isdigit((uchar)s[i + 1]) || |
48 | (isDigitFriendly(s[i + 1]) && isdigit(s[i + 2])))) ); | 54 | (isDigitFriendly(s[i + 1]) && isdigit((uchar)s[i + 2]))))); |
49 | } | 55 | } |
50 | return i; | 56 | return i; |
51 | } | 57 | } |
52 | 58 | ||
53 | /* | 59 | /* |
54 | Returns a version of 'key' where all numbers have been replaced by zeroes. If | 60 | Returns a version of 'key' where all numbers have been replaced by zeroes. If |
55 | there were none, returns "". | 61 | there were none, returns "". |
56 | */ | 62 | */ |
57 | static QCString zeroKey( const char *key ) | 63 | static QCString zeroKey( const char *key ) |
58 | { | 64 | { |
59 | QCString zeroed( strlen(key) + 1 ); | 65 | QCString zeroed( strlen(key) + 1 ); |
60 | char *z = zeroed.data(); | 66 | char *z = zeroed.data(); |
61 | int i = 0, j = 0; | 67 | int i = 0, j = 0; |
62 | int len; | 68 | int len; |
63 | bool metSomething = FALSE; | 69 | bool metSomething = FALSE; |
64 | 70 | ||
65 | while ( key[i] != '\0' ) { | 71 | while ( key[i] != '\0' ) { |
66 | len = numberLength( key + i ); | 72 | len = numberLength( key + i ); |
67 | if ( len > 0 ) { | 73 | if ( len > 0 ) { |
68 | i += len; | 74 | i += len; |
69 | z[j++] = '0'; | 75 | z[j++] = '0'; |
70 | metSomething = TRUE; | 76 | metSomething = TRUE; |
71 | } else { | 77 | } else { |
72 | z[j++] = key[i++]; | 78 | z[j++] = key[i++]; |
@@ -190,46 +196,46 @@ static QString translationAttempt( const QString& oldTranslation, | |||
190 | } | 196 | } |
191 | } | 197 | } |
192 | return attempt; | 198 | return attempt; |
193 | } | 199 | } |
194 | 200 | ||
195 | /* | 201 | /* |
196 | Augments a MetaTranslator with translations easily derived from | 202 | Augments a MetaTranslator with translations easily derived from |
197 | similar existing (probably obsolete) translations. | 203 | similar existing (probably obsolete) translations. |
198 | 204 | ||
199 | For example, if "TeX 3.0" is translated as "XeT 3.0" and "TeX 3.1" | 205 | For example, if "TeX 3.0" is translated as "XeT 3.0" and "TeX 3.1" |
200 | has no translation, "XeT 3.1" is added to the translator and is | 206 | has no translation, "XeT 3.1" is added to the translator and is |
201 | marked Unfinished. | 207 | marked Unfinished. |
202 | */ | 208 | */ |
203 | void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) | 209 | void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) |
204 | { | 210 | { |
205 | TMM translated, untranslated; | 211 | TMM translated, untranslated; |
206 | TMM::Iterator t, u; | 212 | TMM::Iterator t, u; |
207 | TML all = tor->messages(); | 213 | TML all = tor->messages(); |
208 | TML::Iterator it; | 214 | TML::Iterator it; |
209 | int inserted = 0; | 215 | int inserted = 0; |
210 | 216 | ||
211 | for ( it = all.begin(); it != all.end(); ++it ) { | 217 | for ( it = all.begin(); it != all.end(); ++it ) { |
212 | if ( (*it).type() == MetaTranslatorMessage::Unfinished ) { | 218 | if ( (*it).type() == MetaTranslatorMessage::Unfinished ) { |
213 | if ( (*it).translation().isEmpty() ) | 219 | if ( (*it).translation().isEmpty() ) |
214 | untranslated.insert( zeroKey((*it).sourceText()), *it ); | 220 | untranslated.insert(QCString((*it).context()) + "\n" + (*it).sourceText() + "\n" |
221 | + (*it).comment(), *it); | ||
215 | } else if ( !(*it).translation().isEmpty() ) { | 222 | } else if ( !(*it).translation().isEmpty() ) { |
216 | translated.insert( zeroKey((*it).sourceText()), *it ); | 223 | translated.insert( zeroKey((*it).sourceText()), *it ); |
217 | } | 224 | } |
218 | } | 225 | } |
219 | 226 | ||
220 | for ( u = untranslated.begin(); u != untranslated.end(); ++u ) { | 227 | for ( u = untranslated.begin(); u != untranslated.end(); ++u ) { |
221 | t = translated.find( u.key() ); | 228 | t = translated.find( zeroKey((*u).sourceText()) ); |
222 | if ( t != translated.end() && !t.key().isEmpty() && | 229 | if ( t != translated.end() && !t.key().isEmpty() && |
223 | qstrcmp((*t).sourceText(), (*u).sourceText()) != 0 ) { | 230 | qstrcmp((*t).sourceText(), (*u).sourceText()) != 0 ) { |
224 | MetaTranslatorMessage m( *u ); | 231 | MetaTranslatorMessage m( *u ); |
225 | m.setTranslation( translationAttempt((*t).translation(), | 232 | m.setTranslation(translationAttempt((*t).translation(), (*t).sourceText(), |
226 | (*t).sourceText(), | ||
227 | (*u).sourceText()) ); | 233 | (*u).sourceText()) ); |
228 | tor->insert( m ); | 234 | tor->insert( m ); |
229 | inserted++; | 235 | inserted++; |
230 | } | 236 | } |
231 | } | 237 | } |
232 | if ( verbose && inserted != 0 ) | 238 | if ( verbose && inserted != 0 ) |
233 | fprintf( stderr, " number heuristic provided %d translation%s\n", | 239 | fprintf( stderr, " number heuristic provided %d translation%s\n", |
234 | inserted, inserted == 1 ? "" : "s" ); | 240 | inserted, inserted == 1 ? "" : "s" ); |
235 | } | 241 | } |