author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the Qt Linguist of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "lupdate.h" |
|
43 |
||
44 |
#include "simtexth.h" |
|
45 |
#include "translator.h" |
|
46 |
||
47 |
#include <QtCore/QDebug> |
|
48 |
#include <QtCore/QMap> |
|
49 |
#include <QtCore/QStringList> |
|
50 |
#include <QtCore/QTextCodec> |
|
51 |
#include <QtCore/QVector> |
|
52 |
||
53 |
typedef QList<TranslatorMessage> TML; |
|
54 |
typedef QMap<QString, TranslatorMessage> TMM; |
|
55 |
||
56 |
||
57 |
QT_BEGIN_NAMESPACE |
|
58 |
||
59 |
static bool isDigitFriendly(QChar c) |
|
60 |
{ |
|
61 |
return c.isPunct() || c.isSpace(); |
|
62 |
} |
|
63 |
||
64 |
static int numberLength(const QString &s, int i) |
|
65 |
{ |
|
66 |
if (i < s.size() || !s.at(i).isDigit()) |
|
67 |
return 0; |
|
68 |
||
69 |
int pos = i; |
|
70 |
do { |
|
71 |
++i; |
|
72 |
} while (i < s.size() |
|
73 |
&& (s.at(i).isDigit() |
|
74 |
|| (isDigitFriendly(s[i]) |
|
75 |
&& i + 1 < s.size() |
|
76 |
&& (s[i + 1].isDigit() |
|
77 |
|| (isDigitFriendly(s[i + 1]) |
|
78 |
&& i + 2 < s.size() |
|
79 |
&& s[i + 2].isDigit()))))); |
|
80 |
return i - pos; |
|
81 |
} |
|
82 |
||
83 |
||
84 |
/* |
|
85 |
Returns a version of 'key' where all numbers have been replaced by zeroes. If |
|
86 |
there were none, returns "". |
|
87 |
*/ |
|
88 |
static QString zeroKey(const QString &key) |
|
89 |
{ |
|
90 |
QString zeroed; |
|
91 |
bool metSomething = false; |
|
92 |
||
93 |
for (int i = 0; i != key.size(); ++i) { |
|
94 |
int len = numberLength(key, i); |
|
95 |
if (len > 0) { |
|
96 |
i += len; |
|
97 |
zeroed.append(QLatin1Char('0')); |
|
98 |
metSomething = true; |
|
99 |
} else { |
|
100 |
zeroed.append(key.at(i)); |
|
101 |
} |
|
102 |
} |
|
103 |
return metSomething ? zeroed : QString(); |
|
104 |
} |
|
105 |
||
106 |
static QString translationAttempt(const QString &oldTranslation, |
|
107 |
const QString &oldSource, const QString &newSource) |
|
108 |
{ |
|
109 |
int p = zeroKey(oldSource).count(QLatin1Char('0')); |
|
110 |
QString attempt; |
|
111 |
QStringList oldNumbers; |
|
112 |
QStringList newNumbers; |
|
113 |
QVector<bool> met(p); |
|
114 |
QVector<int> matchedYet(p); |
|
115 |
int i, j; |
|
116 |
int k = 0, ell, best; |
|
117 |
int m, n; |
|
118 |
int pass; |
|
119 |
||
120 |
/* |
|
121 |
This algorithm is hard to follow, so we'll consider an example |
|
122 |
all along: oldTranslation is "XeT 3.0", oldSource is "TeX 3.0" |
|
123 |
and newSource is "XeT 3.1". |
|
124 |
||
125 |
First, we set up two tables: oldNumbers and newNumbers. In our |
|
126 |
example, oldNumber[0] is "3.0" and newNumber[0] is "3.1". |
|
127 |
*/ |
|
128 |
for (i = 0, j = 0; i < oldSource.size(); i++, j++) { |
|
129 |
m = numberLength(oldSource, i); |
|
130 |
n = numberLength(newSource, j); |
|
131 |
if (m > 0) { |
|
132 |
oldNumbers.append(oldSource.mid(i, m + 1)); |
|
133 |
newNumbers.append(newSource.mid(j, n + 1)); |
|
134 |
i += m; |
|
135 |
j += n; |
|
136 |
met[k] = false; |
|
137 |
matchedYet[k] = 0; |
|
138 |
k++; |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
/* |
|
143 |
We now go over the old translation, "XeT 3.0", one letter at a |
|
144 |
time, looking for numbers found in oldNumbers. Whenever such a |
|
145 |
number is met, it is replaced with its newNumber equivalent. In |
|
146 |
our example, the "3.0" of "XeT 3.0" becomes "3.1". |
|
147 |
*/ |
|
148 |
for (i = 0; i < oldTranslation.length(); i++) { |
|
149 |
attempt += oldTranslation[i]; |
|
150 |
for (k = 0; k < p; k++) { |
|
151 |
if (oldTranslation[i] == oldNumbers[k][matchedYet[k]]) |
|
152 |
matchedYet[k]++; |
|
153 |
else |
|
154 |
matchedYet[k] = 0; |
|
155 |
} |
|
156 |
||
157 |
/* |
|
158 |
Let's find out if the last character ended a match. We make |
|
159 |
two passes over the data. In the first pass, we try to |
|
160 |
match only numbers that weren't matched yet; if that fails, |
|
161 |
the second pass does the trick. This is useful in some |
|
162 |
suspicious cases, flagged below. |
|
163 |
*/ |
|
164 |
for (pass = 0; pass < 2; pass++) { |
|
165 |
best = p; // an impossible value |
|
166 |
for (k = 0; k < p; k++) { |
|
167 |
if ((!met[k] || pass > 0) && |
|
168 |
matchedYet[k] == oldNumbers[k].length() && |
|
169 |
numberLength(oldTranslation, i + 1 - matchedYet[k]) == matchedYet[k]) { |
|
170 |
// the longer the better |
|
171 |
if (best == p || matchedYet[k] > matchedYet[best]) |
|
172 |
best = k; |
|
173 |
} |
|
174 |
} |
|
175 |
if (best != p) { |
|
176 |
attempt.truncate(attempt.length() - matchedYet[best]); |
|
177 |
attempt += newNumbers[best]; |
|
178 |
met[best] = true; |
|
179 |
for (k = 0; k < p; k++) |
|
180 |
matchedYet[k] = 0; |
|
181 |
break; |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
/* |
|
187 |
We flag two kinds of suspicious cases. They are identified as |
|
188 |
such with comments such as "{2000?}" at the end. |
|
189 |
||
190 |
Example of the first kind: old source text "TeX 3.0" translated |
|
191 |
as "XeT 2.0" is flagged "TeX 2.0 {3.0?}", no matter what the |
|
192 |
new text is. |
|
193 |
*/ |
|
194 |
for (k = 0; k < p; k++) { |
|
195 |
if (!met[k]) |
|
196 |
attempt += QLatin1String(" {") + newNumbers[k] + QLatin1String("?}"); |
|
197 |
} |
|
198 |
||
199 |
/* |
|
200 |
Example of the second kind: "1 of 1" translated as "1 af 1", |
|
201 |
with new source text "1 of 2", generates "1 af 2 {1 or 2?}" |
|
202 |
because it's not clear which of "1 af 2" and "2 af 1" is right. |
|
203 |
*/ |
|
204 |
for (k = 0; k < p; k++) { |
|
205 |
for (ell = 0; ell < p; ell++) { |
|
206 |
if (k != ell && oldNumbers[k] == oldNumbers[ell] && |
|
207 |
newNumbers[k] < newNumbers[ell]) |
|
208 |
attempt += QLatin1String(" {") + newNumbers[k] + QLatin1String(" or ") + |
|
209 |
newNumbers[ell] + QLatin1String("?}"); |
|
210 |
} |
|
211 |
} |
|
212 |
return attempt; |
|
213 |
} |
|
214 |
||
215 |
||
216 |
/* |
|
217 |
Augments a Translator with translations easily derived from |
|
218 |
similar existing (probably obsolete) translations. |
|
219 |
||
220 |
For example, if "TeX 3.0" is translated as "XeT 3.0" and "TeX 3.1" |
|
221 |
has no translation, "XeT 3.1" is added to the translator and is |
|
222 |
marked Unfinished. |
|
223 |
||
224 |
Returns the number of additional messages that this heuristic translated. |
|
225 |
*/ |
|
226 |
int applyNumberHeuristic(Translator &tor) |
|
227 |
{ |
|
228 |
TMM translated, untranslated; |
|
229 |
TMM::Iterator t, u; |
|
230 |
TML all = tor.messages(); |
|
231 |
TML::Iterator it; |
|
232 |
int inserted = 0; |
|
233 |
||
234 |
for (it = all.begin(); it != all.end(); ++it) { |
|
235 |
bool hasTranslation = it->isTranslated(); |
|
236 |
if (it->type() == TranslatorMessage::Unfinished) { |
|
237 |
if (!hasTranslation) |
|
238 |
untranslated.insert(it->context() + QLatin1Char('\n') |
|
239 |
+ it->sourceText() + QLatin1Char('\n') |
|
240 |
+ it->comment(), *it); |
|
241 |
} else if (hasTranslation && it->translations().count() == 1) { |
|
242 |
translated.insert(zeroKey(it->sourceText()), *it); |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
for (u = untranslated.begin(); u != untranslated.end(); ++u) { |
|
247 |
t = translated.find(zeroKey((*u).sourceText())); |
|
248 |
if (t != translated.end() && !t.key().isEmpty() |
|
249 |
&& t->sourceText() != u->sourceText()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
u->setTranslation(translationAttempt(t->translation(), t->sourceText(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
u->sourceText())); |
0 | 252 |
inserted++; |
253 |
} |
|
254 |
} |
|
255 |
return inserted; |
|
256 |
} |
|
257 |
||
258 |
||
259 |
/* |
|
260 |
Augments a Translator with trivially derived translations. |
|
261 |
||
262 |
For example, if "Enabled:" is consistendly translated as "Eingeschaltet:" no |
|
263 |
matter the context or the comment, "Eingeschaltet:" is added as the |
|
264 |
translation of any untranslated "Enabled:" text and is marked Unfinished. |
|
265 |
||
266 |
Returns the number of additional messages that this heuristic translated. |
|
267 |
*/ |
|
268 |
||
269 |
int applySameTextHeuristic(Translator &tor) |
|
270 |
{ |
|
271 |
TMM translated; |
|
272 |
TMM avoid; |
|
273 |
TMM::Iterator t; |
|
274 |
TML untranslated; |
|
275 |
TML::Iterator u; |
|
276 |
TML all = tor.messages(); |
|
277 |
TML::Iterator it; |
|
278 |
int inserted = 0; |
|
279 |
||
280 |
for (it = all.begin(); it != all.end(); ++it) { |
|
281 |
if (!it->isTranslated()) { |
|
282 |
if (it->type() == TranslatorMessage::Unfinished) |
|
283 |
untranslated.append(*it); |
|
284 |
} else { |
|
285 |
QString key = it->sourceText(); |
|
286 |
t = translated.find(key); |
|
287 |
if (t != translated.end()) { |
|
288 |
/* |
|
289 |
The same source text is translated at least two |
|
290 |
different ways. Do nothing then. |
|
291 |
*/ |
|
292 |
if (t->translations() != it->translations()) { |
|
293 |
translated.remove(key); |
|
294 |
avoid.insert(key, *it); |
|
295 |
} |
|
296 |
} else if (!avoid.contains(key)) { |
|
297 |
translated.insert(key, *it); |
|
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
||
302 |
for (u = untranslated.begin(); u != untranslated.end(); ++u) { |
|
303 |
QString key = u->sourceText(); |
|
304 |
t = translated.find(key); |
|
305 |
if (t != translated.end()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
u->setTranslations(t->translations()); |
0 | 307 |
++inserted; |
308 |
} |
|
309 |
} |
|
310 |
return inserted; |
|
311 |
} |
|
312 |
||
313 |
||
314 |
||
315 |
/* |
|
316 |
Merges two Translator objects. The first one |
|
317 |
is a set of source texts and translations for a previous version of |
|
318 |
the internationalized program; the second one is a set of fresh |
|
319 |
source texts newly extracted from the source code, without any |
|
320 |
translation yet. |
|
321 |
*/ |
|
322 |
||
323 |
Translator merge(const Translator &tor, const Translator &virginTor, |
|
324 |
UpdateOptions options, QString &err) |
|
325 |
{ |
|
326 |
int known = 0; |
|
327 |
int neww = 0; |
|
328 |
int obsoleted = 0; |
|
329 |
int similarTextHeuristicCount = 0; |
|
330 |
||
331 |
Translator outTor; |
|
332 |
outTor.setLanguageCode(tor.languageCode()); |
|
333 |
outTor.setSourceLanguageCode(tor.sourceLanguageCode()); |
|
334 |
outTor.setLocationsType(tor.locationsType()); |
|
335 |
outTor.setCodecName(tor.codecName()); |
|
336 |
||
337 |
/* |
|
338 |
The types of all the messages from the vernacular translator |
|
339 |
are updated according to the virgin translator. |
|
340 |
*/ |
|
341 |
foreach (TranslatorMessage m, tor.messages()) { |
|
342 |
TranslatorMessage::Type newType = TranslatorMessage::Finished; |
|
343 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
if (m.sourceText().isEmpty() && m.id().isEmpty()) { |
0 | 345 |
// context/file comment |
346 |
TranslatorMessage mv = virginTor.find(m.context()); |
|
347 |
if (!mv.isNull()) |
|
348 |
m.setComment(mv.comment()); |
|
349 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
TranslatorMessage mv; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
int mvi = virginTor.find(m); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
if (mvi < 0) { |
0 | 353 |
if (!(options & HeuristicSimilarText)) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
makeObsolete: |
0 | 355 |
newType = TranslatorMessage::Obsolete; |
356 |
if (m.type() != TranslatorMessage::Obsolete) |
|
357 |
obsoleted++; |
|
358 |
m.clearReferences(); |
|
359 |
} else { |
|
360 |
mv = virginTor.find(m.context(), m.comment(), m.allReferences()); |
|
361 |
if (mv.isNull()) { |
|
362 |
// did not find it in the virgin, mark it as obsolete |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
goto makeObsolete; |
0 | 364 |
} else { |
365 |
// Do not just accept it if its on the same line number, |
|
366 |
// but different source text. |
|
367 |
// Also check if the texts are more or less similar before |
|
368 |
// we consider them to represent the same message... |
|
369 |
if (getSimilarityScore(m.sourceText(), mv.sourceText()) >= textSimilarityThreshold) { |
|
370 |
// It is just slightly modified, assume that it is the same string |
|
371 |
||
372 |
// Mark it as unfinished. (Since the source text |
|
373 |
// was changed it might require re-translating...) |
|
374 |
newType = TranslatorMessage::Unfinished; |
|
375 |
++similarTextHeuristicCount; |
|
376 |
neww++; |
|
377 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
outdateSource: |
0 | 379 |
m.setOldSourceText(m.sourceText()); |
380 |
m.setSourceText(mv.sourceText()); |
|
381 |
const QString &oldpluralsource = m.extra(QLatin1String("po-msgid_plural")); |
|
382 |
if (!oldpluralsource.isEmpty()) { |
|
383 |
m.setExtra(QLatin1String("po-old_msgid_plural"), oldpluralsource); |
|
384 |
m.unsetExtra(QLatin1String("po-msgid_plural")); |
|
385 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
goto copyAttribs; // Update secondary references |
0 | 387 |
} else { |
388 |
// The virgin and vernacular sourceTexts are so |
|
389 |
// different that we could not find it. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
goto makeObsolete; |
0 | 391 |
} |
392 |
} |
|
393 |
} |
|
394 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
mv = virginTor.message(mvi); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
if (!mv.id().isEmpty() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
&& (mv.context() != m.context() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
|| mv.sourceText() != m.sourceText() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
|| mv.comment() != m.comment())) { |
0 | 400 |
known++; |
401 |
newType = TranslatorMessage::Unfinished; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
m.setContext(mv.context()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
m.setComment(mv.comment()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
if (mv.sourceText() != m.sourceText()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
goto outdateSource; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
switch (m.type()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
case TranslatorMessage::Finished: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
default: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
if (m.isPlural() == mv.isPlural()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
newType = TranslatorMessage::Finished; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
newType = TranslatorMessage::Unfinished; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
known++; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
case TranslatorMessage::Unfinished: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
newType = TranslatorMessage::Unfinished; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
known++; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
case TranslatorMessage::Obsolete: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
newType = TranslatorMessage::Unfinished; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
neww++; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
} |
0 | 425 |
} |
426 |
||
427 |
// Always get the filename and linenumber info from the |
|
428 |
// virgin Translator, in case it has changed location. |
|
429 |
// This should also enable us to read a file that does not |
|
430 |
// have the <location> element. |
|
431 |
// why not use operator=()? Because it overwrites e.g. userData. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
432 |
copyAttribs: |
0 | 433 |
m.setReferences(mv.allReferences()); |
434 |
m.setPlural(mv.isPlural()); |
|
435 |
m.setUtf8(mv.isUtf8()); |
|
436 |
m.setExtraComment(mv.extraComment()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
m.setId(mv.id()); |
0 | 438 |
} |
439 |
} |
|
440 |
||
441 |
m.setType(newType); |
|
442 |
outTor.append(m); |
|
443 |
} |
|
444 |
||
445 |
/* |
|
446 |
Messages found only in the virgin translator are added to the |
|
447 |
vernacular translator. |
|
448 |
*/ |
|
449 |
foreach (const TranslatorMessage &mv, virginTor.messages()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
450 |
if (mv.sourceText().isEmpty() && mv.id().isEmpty()) { |
0 | 451 |
if (tor.contains(mv.context())) |
452 |
continue; |
|
453 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
454 |
if (tor.find(mv) >= 0) |
0 | 455 |
continue; |
456 |
if (options & HeuristicSimilarText) { |
|
457 |
TranslatorMessage m = tor.find(mv.context(), mv.comment(), mv.allReferences()); |
|
458 |
if (!m.isNull()) { |
|
459 |
if (getSimilarityScore(m.sourceText(), mv.sourceText()) >= textSimilarityThreshold) |
|
460 |
continue; |
|
461 |
} |
|
462 |
} |
|
463 |
} |
|
464 |
if (options & NoLocations) |
|
465 |
outTor.append(mv); |
|
466 |
else |
|
467 |
outTor.appendSorted(mv); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
if (!mv.sourceText().isEmpty() || !mv.id().isEmpty()) |
0 | 469 |
++neww; |
470 |
} |
|
471 |
||
472 |
/* |
|
473 |
The same-text heuristic handles cases where a message has an |
|
474 |
obsolete counterpart with a different context or comment. |
|
475 |
*/ |
|
476 |
int sameTextHeuristicCount = (options & HeuristicSameText) ? applySameTextHeuristic(outTor) : 0; |
|
477 |
||
478 |
/* |
|
479 |
The number heuristic handles cases where a message has an |
|
480 |
obsolete counterpart with mostly numbers differing in the |
|
481 |
source text. |
|
482 |
*/ |
|
483 |
int sameNumberHeuristicCount = (options & HeuristicNumber) ? applyNumberHeuristic(outTor) : 0; |
|
484 |
||
485 |
if (options & Verbose) { |
|
486 |
int totalFound = neww + known; |
|
487 |
err += QObject::tr(" Found %n source text(s) (%1 new and %2 already existing)\n", 0, totalFound).arg(neww).arg(known); |
|
488 |
||
489 |
if (obsoleted) { |
|
490 |
if (options & NoObsolete) { |
|
491 |
err += QObject::tr(" Removed %n obsolete entries\n", 0, obsoleted); |
|
492 |
} else { |
|
493 |
err += QObject::tr(" Kept %n obsolete entries\n", 0, obsoleted); |
|
494 |
} |
|
495 |
} |
|
496 |
||
497 |
if (sameNumberHeuristicCount) |
|
498 |
err += QObject::tr(" Number heuristic provided %n translation(s)\n", |
|
499 |
0, sameNumberHeuristicCount); |
|
500 |
if (sameTextHeuristicCount) |
|
501 |
err += QObject::tr(" Same-text heuristic provided %n translation(s)\n", |
|
502 |
0, sameTextHeuristicCount); |
|
503 |
if (similarTextHeuristicCount) |
|
504 |
err += QObject::tr(" Similar-text heuristic provided %n translation(s)\n", |
|
505 |
0, similarTextHeuristicCount); |
|
506 |
} |
|
507 |
return outTor; |
|
508 |
} |
|
509 |
||
510 |
QT_END_NAMESPACE |