diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/linguist/lupdate/cpp.cpp | 2 | ||||
-rw-r--r-- | tools/linguist/lupdate/main.cpp | 8 | ||||
-rw-r--r-- | tools/linguist/lupdate/merge.cpp | 95 | ||||
-rw-r--r-- | tools/linguist/shared/translator.cpp | 12 |
4 files changed, 61 insertions, 56 deletions
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index 12c06b1..6bd9108 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -1732,7 +1732,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) plural = true; } } - if (!pendingContext.isEmpty()) { + if (!pendingContext.isEmpty() && !prefix.startsWith(strColons)) { QStringList unresolved; if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) { functionContextUnresolved = unresolved.join(strColons); diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp index ecdb0e3..2129265 100644 --- a/tools/linguist/lupdate/main.cpp +++ b/tools/linguist/lupdate/main.cpp @@ -237,18 +237,12 @@ int main(int argc, char **argv) Verbose | // verbose is on by default starting with Qt 4.2 HeuristicSameText | HeuristicSimilarText | HeuristicNumber; int numFiles = 0; - bool standardSyntax = true; bool metTsFlag = false; bool recursiveScan = true; QString extensions = m_defaultExtensions; QSet<QString> extensionsNameFilters; - for (int i = 1; i < argc; ++i) { - if (args.at(i) == QLatin1String("-ts")) - standardSyntax = false; - } - for (int i = 1; i < argc; ++i) { QString arg = args.at(i); if (arg == QLatin1String("-help") @@ -375,8 +369,6 @@ int main(int argc, char **argv) numFiles++; - QString fullText; - codecForTr.clear(); codecForSource.clear(); diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp index 421f07d..fffdf9b 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 @@ -63,7 +60,7 @@ static bool isDigitFriendly(QChar c) static int numberLength(const QString &s, int i) { - if (i < s.size() || !s.at(i).isDigit()) + if (i >= s.size() || !s.at(i).isDigit()) return 0; int pos = i; @@ -90,7 +87,7 @@ static QString zeroKey(const QString &key) QString zeroed; bool metSomething = false; - for (int i = 0; i != key.size(); ++i) { + for (int i = 0; i < key.size(); ++i) { int len = numberLength(key, i); if (len > 0) { i += len; @@ -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; diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 83a182e..4331ce6 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -44,6 +44,10 @@ #include "simtexth.h" #include <stdio.h> +#ifdef Q_OS_WIN +#include <io.h> // required for _setmode, to avoid _O_TEXT streams... +#include <fcntl.h> // for _O_BINARY +#endif #include <QtCore/QDebug> #include <QtCore/QDir> @@ -207,6 +211,10 @@ bool Translator::load(const QString &filename, ConversionData &cd, const QString QFile file; if (filename.isEmpty() || filename == QLatin1String("-")) { +#ifdef Q_OS_WIN + // QFile is broken for text files + ::_setmode(0, _O_BINARY); +#endif if (!file.open(stdin, QIODevice::ReadOnly)) { cd.appendError(QString::fromLatin1("Cannot open stdin!? (%1)") .arg(file.errorString())); @@ -243,6 +251,10 @@ bool Translator::save(const QString &filename, ConversionData &cd, const QString { QFile file; if (filename.isEmpty() || filename == QLatin1String("-")) { +#ifdef Q_OS_WIN + // QFile is broken for text files + ::_setmode(1, _O_BINARY); +#endif if (!file.open(stdout, QIODevice::WriteOnly)) { cd.appendError(QString::fromLatin1("Cannot open stdout!? (%1)") .arg(file.errorString())); |