summaryrefslogtreecommitdiff
path: root/tools/linguist
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2009-04-02 18:56:04 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2009-04-02 18:56:04 +0200
commit87d9469e428296a2fb8d0f266900cdfe816eaf0a (patch)
treef8219cadd57c0013f619030b44068adc009e2058 /tools/linguist
parentceb253c234f840f7aeec10fa4450e840c6b242f4 (diff)
parent7c09fda559760b8488d3130a5932fee04b2f6979 (diff)
downloadqt4-tools-87d9469e428296a2fb8d0f266900cdfe816eaf0a.tar.gz
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts: tools/linguist/shared/profileevaluator.cpp
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/lconvert/main.cpp2
-rw-r--r--tools/linguist/linguist/messagemodel.cpp10
-rw-r--r--tools/linguist/lrelease/main.cpp15
-rw-r--r--tools/linguist/lupdate/main.cpp1
-rw-r--r--tools/linguist/shared/profileevaluator.cpp14
-rw-r--r--tools/linguist/shared/qm.cpp1
-rw-r--r--tools/linguist/shared/translator.cpp58
-rw-r--r--tools/linguist/shared/translator.h5
-rw-r--r--tools/linguist/shared/translatormessage.h26
-rw-r--r--tools/linguist/shared/ts.cpp6
10 files changed, 87 insertions, 51 deletions
diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp
index 8a214097a4..bdc6c9a112 100644
--- a/tools/linguist/lconvert/main.cpp
+++ b/tools/linguist/lconvert/main.cpp
@@ -205,6 +205,7 @@ int main(int argc, char *argv[])
qWarning() << qPrintable(cd.error());
return 2;
}
+ Translator::reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose);
for (int i = 1; i < inFiles.size(); ++i) {
Translator tr2;
@@ -212,6 +213,7 @@ int main(int argc, char *argv[])
qWarning() << qPrintable(cd.error());
return 2;
}
+ Translator::reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose);
for (int j = 0; j < tr2.messageCount(); ++j)
tr.replaceSorted(tr2.message(j));
}
diff --git a/tools/linguist/linguist/messagemodel.cpp b/tools/linguist/linguist/messagemodel.cpp
index b049ab9acc..7a8063bb74 100644
--- a/tools/linguist/linguist/messagemodel.cpp
+++ b/tools/linguist/linguist/messagemodel.cpp
@@ -209,19 +209,19 @@ bool DataModel::load(const QString &fileName, bool *langGuessed, QWidget *parent
return false;
}
- QList<TranslatorMessage> dupes = tor.findDuplicates();
+ QSet<TranslatorMessagePtr> dupes = tor.resolveDuplicates();
if (!dupes.isEmpty()) {
QString err = tr("<qt>Duplicate messages found in '%1':").arg(Qt::escape(fileName));
int numdups = 0;
- foreach (const TranslatorMessage &msg, dupes) {
+ foreach (const TranslatorMessagePtr &msg, dupes) {
if (++numdups >= 5) {
err += tr("<p>[more duplicates omitted]");
break;
}
err += tr("<p>* Context: %1<br>* Source: %2")
- .arg(Qt::escape(msg.context()), Qt::escape(msg.sourceText()));
- if (!msg.comment().isEmpty())
- err += tr("<br>* Comment: %3").arg(Qt::escape(msg.comment()));
+ .arg(Qt::escape(msg->context()), Qt::escape(msg->sourceText()));
+ if (!msg->comment().isEmpty())
+ err += tr("<br>* Comment: %3").arg(Qt::escape(msg->comment()));
}
QMessageBox::warning(parent, QObject::tr("Qt Linguist"), err);
}
diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp
index 0440325442..7d0452f152 100644
--- a/tools/linguist/lrelease/main.cpp
+++ b/tools/linguist/lrelease/main.cpp
@@ -93,19 +93,6 @@ static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbo
} else {
if (!cd.errors().isEmpty())
printOut(cd.error());
- const QList<TranslatorMessage> dupes = tor.findDuplicates();
- if (!dupes.isEmpty()) {
- qWarning("lrelease error: duplicate messages found in '%s':",
- qPrintable(tsFileName));
- foreach (const TranslatorMessage &msg, dupes) {
- qWarning("\n* Context: %s\n* Source: %s",
- qPrintable(msg.context()),
- qPrintable(msg.sourceText()));
- if (!msg.comment().isEmpty())
- qWarning("\n* Comment: %s", qPrintable(msg.comment()));
- }
- ok = false;
- }
}
return ok;
}
@@ -114,6 +101,8 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName,
bool verbose, bool ignoreUnfinished,
bool removeIdentical, TranslatorSaveMode mode)
{
+ Translator::reportDuplicates(tor.resolveDuplicates(), qmFileName, verbose);
+
if (verbose)
printOut(QCoreApplication::tr( "Updating '%1'...\n").arg(qmFileName));
if (removeIdentical) {
diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp
index b2418579f9..8a70b55281 100644
--- a/tools/linguist/lupdate/main.cpp
+++ b/tools/linguist/lupdate/main.cpp
@@ -150,6 +150,7 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
*fail = true;
continue;
}
+ tor.resolveDuplicates();
cd.clearErrors();
if (!codecForTr.isEmpty() && codecForTr != tor.codecName())
qWarning("lupdate warning: Codec for tr() '%s' disagrees with "
diff --git a/tools/linguist/shared/profileevaluator.cpp b/tools/linguist/shared/profileevaluator.cpp
index 173b46e923..ec69156159 100644
--- a/tools/linguist/shared/profileevaluator.cpp
+++ b/tools/linguist/shared/profileevaluator.cpp
@@ -258,8 +258,12 @@ bool ProFileEvaluator::Private::read(ProFile *pro)
return false;
}
+ m_block = 0;
+ m_commentItem = 0;
+ m_contNextLine = false;
m_syntaxError = false;
m_lineNo = 1;
+ m_blockstack.clear();
m_blockstack.push(pro);
QTextStream ts(&file);
@@ -1204,9 +1208,10 @@ bool ProFileEvaluator::Private::isActiveConfig(const QString &config, bool regex
QStringList ProFileEvaluator::Private::evaluateExpandFunction(const QString &func, const QString &arguments)
{
QStringList argumentsList = split_arg_list(arguments);
+
QStringList args;
for (int i = 0; i < argumentsList.count(); ++i)
- args += expandVariableReferences(argumentsList[i]);
+ args += expandVariableReferences(argumentsList[i]).join(Option::field_sep);
enum ExpandFunc { E_MEMBER=1, E_FIRST, E_LAST, E_CAT, E_FROMFILE, E_EVAL, E_LIST,
E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
@@ -1693,10 +1698,11 @@ bool ProFileEvaluator::Private::evaluateConditionalFunction(const QString &funct
for (int mut = 0; mut < mutuals.count(); mut++) {
if (configs[i] == mutuals[mut].trimmed()) {
cond = (configs[i] == args[0]);
- break;
+ goto done_T_CONFIG;
}
}
}
+ done_T_CONFIG:
break;
}
case T_CONTAINS: {
@@ -1723,12 +1729,12 @@ bool ProFileEvaluator::Private::evaluateConditionalFunction(const QString &funct
for (int mut = 0; mut < mutuals.count(); mut++) {
if (val == mutuals[mut].trimmed()) {
cond = (regx.exactMatch(val) || val == args[1]);
- break;
+ goto done_T_CONTAINS;
}
}
}
}
-
+ done_T_CONTAINS:
break;
}
case T_COUNT: {
diff --git a/tools/linguist/shared/qm.cpp b/tools/linguist/shared/qm.cpp
index d19b5198c1..5563ac5743 100644
--- a/tools/linguist/shared/qm.cpp
+++ b/tools/linguist/shared/qm.cpp
@@ -659,7 +659,6 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
msg.setComment(comment);
translator.append(msg);
}
- translator.resolveDualEncoded();
return ok;
}
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp
index 3721204173..312bb7116c 100644
--- a/tools/linguist/shared/translator.cpp
+++ b/tools/linguist/shared/translator.cpp
@@ -416,38 +416,52 @@ void Translator::dropTranslations()
}
}
-QList<TranslatorMessage> Translator::findDuplicates() const
+QSet<TranslatorMessagePtr> Translator::resolveDuplicates()
{
- QHash<TranslatorMessage, int> dups;
- foreach (const TranslatorMessage &msg, m_messages)
- dups[msg]++;
- QList<TranslatorMessage> ret;
- QHash<TranslatorMessage, int>::ConstIterator it = dups.constBegin(), end = dups.constEnd();
- for (; it != end; ++it)
- if (it.value() > 1)
- ret.append(it.key());
- return ret;
-}
-
-void Translator::resolveDualEncoded()
-{
- QHash<TranslatorMessage, int> dups;
+ QSet<TranslatorMessagePtr> dups;
+ QHash<TranslatorMessagePtr, int> refs;
for (int i = 0; i < m_messages.count();) {
const TranslatorMessage &msg = m_messages.at(i);
- QHash<TranslatorMessage, int>::ConstIterator it = dups.constFind(msg);
- if (it != dups.constEnd()) {
+ QHash<TranslatorMessagePtr, int>::ConstIterator it = refs.constFind(msg);
+ if (it != refs.constEnd()) {
TranslatorMessage &omsg = m_messages[*it];
if (omsg.isUtf8() != msg.isUtf8() && !omsg.isNonUtf8()) {
+ // Dual-encoded message
omsg.setUtf8(true);
omsg.setNonUtf8(true);
- m_messages.removeAt(i);
- continue;
+ } else {
+ // Duplicate
+ dups.insert(omsg);
}
- // Regular dupe; will complain later
+ if (!omsg.isTranslated() && msg.isTranslated())
+ omsg.setTranslations(msg.translations());
+ m_messages.removeAt(i);
} else {
- dups[msg] = i;
+ refs[msg] = i;
+ ++i;
+ }
+ }
+ return dups;
+}
+
+void Translator::reportDuplicates(const QSet<TranslatorMessagePtr> &dupes,
+ const QString &fileName, bool verbose)
+{
+ if (!dupes.isEmpty()) {
+ if (!verbose) {
+ qWarning("Warning: dropping duplicate messages in '%s'\n(try -verbose for more info).",
+ qPrintable(fileName));
+ } else {
+ qWarning("Warning: dropping duplicate messages in '%s':", qPrintable(fileName));
+ foreach (const TranslatorMessagePtr &msg, dupes) {
+ qWarning("\n* Context: %s\n* Source: %s",
+ qPrintable(msg->context()),
+ qPrintable(msg->sourceText()));
+ if (!msg->comment().isEmpty())
+ qWarning("* Comment: %s", qPrintable(msg->comment()));
+ }
+ qWarning();
}
- ++i;
}
}
diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h
index 0f83c1d742..4e97000f74 100644
--- a/tools/linguist/shared/translator.h
+++ b/tools/linguist/shared/translator.h
@@ -132,9 +132,10 @@ public:
void stripNonPluralForms();
void stripIdenticalSourceTranslations();
void dropTranslations();
- QList<TranslatorMessage> findDuplicates() const;
- void resolveDualEncoded();
void makeFileNamesAbsolute(const QDir &originalPath);
+ QSet<TranslatorMessagePtr> resolveDuplicates();
+ static void reportDuplicates(const QSet<TranslatorMessagePtr> &dupes,
+ const QString &fileName, bool verbose);
void setCodecName(const QByteArray &name);
QByteArray codecName() const { return m_codecName; }
diff --git a/tools/linguist/shared/translatormessage.h b/tools/linguist/shared/translatormessage.h
index 363019ede5..7d31925137 100644
--- a/tools/linguist/shared/translatormessage.h
+++ b/tools/linguist/shared/translatormessage.h
@@ -179,6 +179,32 @@ Q_DECLARE_TYPEINFO(TranslatorMessage, Q_MOVABLE_TYPE);
int qHash(const TranslatorMessage &msg);
+struct TranslatorMessagePtr {
+ TranslatorMessagePtr(const TranslatorMessage &tm)
+ {
+ ptr = &tm;
+ }
+
+ inline const TranslatorMessage *operator->() const
+ {
+ return ptr;
+ }
+
+ const TranslatorMessage *ptr;
+};
+
+Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE);
+
+static inline int qHash(TranslatorMessagePtr tmp)
+{
+ return qHash(*tmp.ptr);
+}
+
+static inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2)
+{
+ return *tmp1.ptr == *tmp2.ptr;
+}
+
QT_END_NAMESPACE
#endif // QT_NO_TRANSLATION
diff --git a/tools/linguist/shared/ts.cpp b/tools/linguist/shared/ts.cpp
index 8a6d365a8e..22f2a1b147 100644
--- a/tools/linguist/shared/ts.cpp
+++ b/tools/linguist/shared/ts.cpp
@@ -242,7 +242,7 @@ bool TSReader::read(Translator &translator)
STRING(userdata);
STRING(utf8);
STRING(value);
- STRING(version);
+ //STRING(version);
STRING(yes);
static const QString strextrans(QLatin1String("extra-"));
@@ -266,15 +266,13 @@ bool TSReader::read(Translator &translator)
QString currentFile;
QXmlStreamAttributes atts = attributes();
- QString version = atts.value(strversion).toString();
+ //QString version = atts.value(strversion).toString();
translator.setLanguageCode(atts.value(strlanguage).toString());
translator.setSourceLanguageCode(atts.value(strsourcelanguage).toString());
while (!atEnd()) {
readNext();
if (isEndElement()) {
// </TS> found, finish local loop
- if (version == QLatin1String("1.1"))
- translator.resolveDualEncoded();
break;
} else if (isWhiteSpace()) {
// ignore these, just whitespace