summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-01-06 11:34:12 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-01-06 18:16:21 (GMT)
commit2bd2e35078e0cdf9f1458892adcd0939504b59bb (patch)
treec108b6eab601d6854ce2584f9717d90e1d9bc3c0
parent14fc1147d156b9f600a66ec8a5bfc71e936f0bdf (diff)
downloadQt-2bd2e35078e0cdf9f1458892adcd0939504b59bb.zip
Qt-2bd2e35078e0cdf9f1458892adcd0939504b59bb.tar.gz
Qt-2bd2e35078e0cdf9f1458892adcd0939504b59bb.tar.bz2
fix sametext and number heuristics
92e9a48 ("eliminate Translator::replace()") eliminated the correctness as well. whoops. this code should be more efficient as well ...
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/heuristics/expectedoutput.txt5
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/heuristics/lupdatecmd2
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/heuristics/main.cpp62
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/heuristics/project.pro3
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.before38
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.result22
-rw-r--r--tools/linguist/lupdate/merge.cpp91
7 files changed, 178 insertions, 45 deletions
diff --git a/tests/auto/linguist/lupdate/testdata/good/heuristics/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/heuristics/expectedoutput.txt
new file mode 100644
index 0000000..1eed403
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/heuristics/expectedoutput.txt
@@ -0,0 +1,5 @@
+Updating 'project\.ts'\.\.\.
+ Found 3 source text\(s\) \(3 new and 0 already existing\)
+ Removed 5 obsolete entries
+ Number heuristic provided 1 translation\(s\)
+ Same-text heuristic provided 1 translation\(s\)
diff --git a/tests/auto/linguist/lupdate/testdata/good/heuristics/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/heuristics/lupdatecmd
new file mode 100644
index 0000000..6bda261
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/heuristics/lupdatecmd
@@ -0,0 +1,2 @@
+TRANSLATION: project.ts
+lupdate -verbose -disable-heuristic similartext -no-obsolete project.pro
diff --git a/tests/auto/linguist/lupdate/testdata/good/heuristics/main.cpp b/tests/auto/linguist/lupdate/testdata/good/heuristics/main.cpp
new file mode 100644
index 0000000..9f36b33
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/heuristics/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// IMPORTANT!!!! If you want to add testdata to this file,
+// always add it to the end in order to not change the linenumbers of translations!!!
+
+#define QTCORE <QtCore>
+#include QTCORE // Hidden from lupdate, but compiles
+
+class A: public QObject {
+ Q_OBJECT
+ void foo()
+ {
+ // number Heuristics
+ tr("version 2.0 now");
+
+ // same text match
+ tr("this is the matched same text");
+
+ // failed same text
+ tr("this is the non-matched same text");
+ }
+};
+
diff --git a/tests/auto/linguist/lupdate/testdata/good/heuristics/project.pro b/tests/auto/linguist/lupdate/testdata/good/heuristics/project.pro
new file mode 100644
index 0000000..759bea0
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/heuristics/project.pro
@@ -0,0 +1,3 @@
+SOURCES = main.cpp
+
+TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.before b/tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.before
new file mode 100644
index 0000000..ce82810
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.before
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0">
+<context>
+ <name>A</name>
+ <message>
+ <location filename="main.cpp" line="53"/>
+ <source>version 1.0 now</source>
+ <translation>teraz wersja 1.0</translation>
+ </message>
+</context>
+<context>
+ <name>B</name>
+ <message>
+ <location filename="main.cpp" line="56"/>
+ <source>this is the matched same text</source>
+ <translation>der same-text-treffer</translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="59"/>
+ <source>this is the non-matched same text</source>
+ <translation>same-text-reinfall variante eins</translation>
+ </message>
+</context>
+<context>
+ <name>C</name>
+ <message>
+ <location filename="main.cpp" line="56"/>
+ <source>this is the matched same text</source>
+ <translation>der same-text-treffer</translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="59"/>
+ <source>this is the non-matched same text</source>
+ <translation>völlig andere variante des reinfalls mit same-text</translation>
+ </message>
+</context>
+</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.result
new file mode 100644
index 0000000..402ad9a
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/heuristics/project.ts.result
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0">
+<context>
+ <name>A</name>
+ <message>
+ <location filename="main.cpp" line="53"/>
+ <source>version 2.0 now</source>
+ <translation type="unfinished">teraz wersja 1.0 {2.0 ?}</translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="56"/>
+ <source>this is the matched same text</source>
+ <translation type="unfinished">der same-text-treffer</translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="59"/>
+ <source>this is the non-matched same text</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+</TS>
diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp
index 1f006ea..b657282 100644
--- a/tools/linguist/lupdate/merge.cpp
+++ b/tools/linguist/lupdate/merge.cpp
@@ -50,9 +50,6 @@
#include <QtCore/QTextCodec>
#include <QtCore/QVector>
-typedef QList<TranslatorMessage> TML;
-typedef QMap<QString, TranslatorMessage> TMM;
-
QT_BEGIN_NAMESPACE
@@ -225,31 +222,36 @@ static QString translationAttempt(const QString &oldTranslation,
*/
int applyNumberHeuristic(Translator &tor)
{
- TMM translated, untranslated;
- TMM::Iterator t, u;
- TML all = tor.messages();
- TML::Iterator it;
+ QMap<QString, QPair<QString, QString> > translated;
+ QVector<bool> untranslated(tor.messageCount());
int inserted = 0;
- for (it = all.begin(); it != all.end(); ++it) {
- bool hasTranslation = it->isTranslated();
- if (it->type() == TranslatorMessage::Unfinished) {
+ for (int i = 0; i < tor.messageCount(); ++i) {
+ const TranslatorMessage &msg = tor.message(i);
+ bool hasTranslation = msg.isTranslated();
+ if (msg.type() == TranslatorMessage::Unfinished) {
if (!hasTranslation)
- untranslated.insert(it->context() + QLatin1Char('\n')
- + it->sourceText() + QLatin1Char('\n')
- + it->comment(), *it);
- } else if (hasTranslation && it->translations().count() == 1) {
- translated.insert(zeroKey(it->sourceText()), *it);
+ untranslated[i] = true;
+ } else if (hasTranslation && msg.translations().count() == 1) {
+ const QString &key = zeroKey(msg.sourceText());
+ if (!key.isEmpty())
+ translated.insert(key, qMakePair(msg.sourceText(), msg.translation()));
}
}
- for (u = untranslated.begin(); u != untranslated.end(); ++u) {
- t = translated.find(zeroKey((*u).sourceText()));
- if (t != translated.end() && !t.key().isEmpty()
- && t->sourceText() != u->sourceText()) {
- u->setTranslation(translationAttempt(t->translation(), t->sourceText(),
- u->sourceText()));
- inserted++;
+ for (int i = 0; i < tor.messageCount(); ++i) {
+ if (untranslated[i]) {
+ TranslatorMessage &msg = tor.message(i);
+ const QString &key = zeroKey(msg.sourceText());
+ if (!key.isEmpty()) {
+ QMap<QString, QPair<QString, QString> >::ConstIterator t =
+ translated.constFind(key);
+ if (t != translated.constEnd() && t->first != msg.sourceText()) {
+ msg.setTranslation(translationAttempt(t->second, t->first,
+ msg.sourceText()));
+ inserted++;
+ }
+ }
}
}
return inserted;
@@ -268,43 +270,42 @@ int applyNumberHeuristic(Translator &tor)
int applySameTextHeuristic(Translator &tor)
{
- TMM translated;
- TMM avoid;
- TMM::Iterator t;
- TML untranslated;
- TML::Iterator u;
- TML all = tor.messages();
- TML::Iterator it;
+ QMap<QString, QStringList> translated;
+ QMap<QString, bool> avoid; // Want a QTreeSet, in fact
+ QVector<bool> untranslated(tor.messageCount());
int inserted = 0;
- for (it = all.begin(); it != all.end(); ++it) {
- if (!it->isTranslated()) {
- if (it->type() == TranslatorMessage::Unfinished)
- untranslated.append(*it);
+ for (int i = 0; i < tor.messageCount(); ++i) {
+ const TranslatorMessage &msg = tor.message(i);
+ if (!msg.isTranslated()) {
+ if (msg.type() == TranslatorMessage::Unfinished)
+ untranslated[i] = true;
} else {
- QString key = it->sourceText();
- t = translated.find(key);
- if (t != translated.end()) {
+ const QString &key = msg.sourceText();
+ QMap<QString, QStringList>::ConstIterator t = translated.constFind(key);
+ if (t != translated.constEnd()) {
/*
The same source text is translated at least two
different ways. Do nothing then.
*/
- if (t->translations() != it->translations()) {
+ if (*t != msg.translations()) {
translated.remove(key);
- avoid.insert(key, *it);
+ avoid.insert(key, true);
}
} else if (!avoid.contains(key)) {
- translated.insert(key, *it);
+ translated.insert(key, msg.translations());
}
}
}
- for (u = untranslated.begin(); u != untranslated.end(); ++u) {
- QString key = u->sourceText();
- t = translated.find(key);
- if (t != translated.end()) {
- u->setTranslations(t->translations());
- ++inserted;
+ for (int i = 0; i < tor.messageCount(); ++i) {
+ if (untranslated[i]) {
+ TranslatorMessage &msg = tor.message(i);
+ QMap<QString, QStringList>::ConstIterator t = translated.constFind(msg.sourceText());
+ if (t != translated.constEnd()) {
+ msg.setTranslations(*t);
+ ++inserted;
+ }
}
}
return inserted;