diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2011-06-10 12:12:36 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2011-06-10 12:12:36 (GMT) |
commit | af66d24cd6ba0ec5cbe2d6ecd899a0f1977637eb (patch) | |
tree | 0b7a83889728bdc2ab8414a51c51193a175edb0b /tools/linguist/shared/translator.cpp | |
parent | c6e155472da8b7192952420aa628677680c3c34a (diff) | |
parent | b9993f684c7ef8c04aa6a0e87af596609957f906 (diff) | |
download | Qt-af66d24cd6ba0ec5cbe2d6ecd899a0f1977637eb.zip Qt-af66d24cd6ba0ec5cbe2d6ecd899a0f1977637eb.tar.gz Qt-af66d24cd6ba0ec5cbe2d6ecd899a0f1977637eb.tar.bz2 |
Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qt-fire-team
* 'master' of git://scm.dev.nokia.troll.no/qt/qt-fire-team: (118 commits)
Fix compilation of lrelease on Windows
Allow selecting fonts with irregular style names
Fix missing empty lines in Qt HTML when displayed in compliant browsers
Fix autotest on Windows
Update internal state before emitting configurationChanged() signals.
Fix compilation of qtconfig without X11
Compile on Mac OS X
Fixed qmlshadersplugin manual test shaders on SGX family GPU:s.
Fixed qmlshadersplugin on windows VC2008 toolchain.
Reset input context in Symbian when another window is opened.
KERN-EXEC 3 panic in QCoeFepInputContext::translateInputWidget()
Fix for QTBUG-18947. Changed the macosx deployment target to 10.5
Ammend last commit
Implemented QAccessibleTextEdit::attributes()
Changing cursor position in all boundaries
code clean-up for QSystemSemaphore
simplify QSharedMemoryPrivate::cleanHandle()
minor improvements for QSharedMemory
fix potential keyfile leaking
refactoring of the QWSSharedMemory class
...
Diffstat (limited to 'tools/linguist/shared/translator.cpp')
-rw-r--r-- | tools/linguist/shared/translator.cpp | 196 |
1 files changed, 104 insertions, 92 deletions
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index a29372a..bd13bf7 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -79,7 +79,8 @@ QString QObject::tr(const char *sourceText, const char *, int n) Translator::Translator() : m_codec(QTextCodec::codecForName("ISO-8859-1")), - m_locationsType(AbsoluteLocations) + m_locationsType(AbsoluteLocations), + m_indexOk(true) { } @@ -101,20 +102,58 @@ QList<Translator::FileFormat> &Translator::registeredFileFormats() return theFormats; } +void Translator::addIndex(int idx, const TranslatorMessage &msg) const +{ + if (msg.sourceText().isEmpty() && msg.id().isEmpty()) { + m_ctxCmtIdx[msg.context()] = idx; + } else { + m_msgIdx[TMMKey(msg)] = idx; + if (!msg.id().isEmpty()) + m_idMsgIdx[msg.id()] = idx; + } +} + +void Translator::delIndex(int idx) const +{ + const TranslatorMessage &msg = m_messages.at(idx); + if (msg.sourceText().isEmpty() && msg.id().isEmpty()) { + m_ctxCmtIdx.remove(msg.context()); + } else { + m_msgIdx.remove(TMMKey(msg)); + if (!msg.id().isEmpty()) + m_idMsgIdx.remove(msg.id()); + } +} + +void Translator::ensureIndexed() const +{ + if (!m_indexOk) { + m_indexOk = true; + m_ctxCmtIdx.clear(); + m_idMsgIdx.clear(); + m_msgIdx.clear(); + for (int i = 0; i < m_messages.count(); i++) + addIndex(i, m_messages.at(i)); + } +} + void Translator::replaceSorted(const TranslatorMessage &msg) { int index = find(msg); - if (index == -1) + if (index == -1) { appendSorted(msg); - else + } else { + delIndex(index); m_messages[index] = msg; + addIndex(index, msg); + } } void Translator::extend(const TranslatorMessage &msg) { int index = find(msg); if (index == -1) { - m_messages.append(msg); + append(msg); } else { TranslatorMessage &emsg = m_messages[index]; emsg.addReferenceUniq(msg.fileName(), msg.lineNumber()); @@ -132,16 +171,22 @@ void Translator::extend(const TranslatorMessage &msg) } } +void Translator::insert(int idx, const TranslatorMessage &msg) +{ + addIndex(idx, msg); + m_messages.insert(idx, msg); +} + void Translator::append(const TranslatorMessage &msg) { - m_messages.append(msg); + insert(m_messages.count(), msg); } void Translator::appendSorted(const TranslatorMessage &msg) { int msgLine = msg.lineNumber(); if (msgLine < 0) { - m_messages.append(msg); + append(msg); return; } @@ -189,11 +234,11 @@ void Translator::appendSorted(const TranslatorMessage &msg) thisScore = 1; } if (thisScore > bestScore || (thisScore == bestScore && thisSize > bestSize)) - m_messages.insert(thisIdx, msg); + insert(thisIdx, msg); else if (bestScore) - m_messages.insert(bestIdx, msg); + insert(bestIdx, msg); else - m_messages.append(msg); + append(msg); } static QString guessFormat(const QString &filename, const QString &format) @@ -329,34 +374,20 @@ void Translator::languageAndCountry(const QString &languageCode, } } -bool Translator::release(QFile *iod, ConversionData &cd) const -{ - foreach (const FileFormat &format, registeredFileFormats()) { - if (format.extension == QLatin1String("qm")) - return (*format.saver)(*this, *iod, cd); - } - cd.appendError(QLatin1String("No .qm saver available.")); - return false; -} - int Translator::find(const TranslatorMessage &msg) const { - for (int i = 0; i < m_messages.count(); ++i) { - const TranslatorMessage &tmsg = m_messages.at(i); - if (msg.id().isEmpty() || tmsg.id().isEmpty()) { - if (msg.context() == tmsg.context() - && msg.sourceText() == tmsg.sourceText() - && msg.comment() == tmsg.comment()) - return i; - } else { - if (msg.id() == tmsg.id()) - return i; - } - } - return -1; + ensureIndexed(); + if (msg.id().isEmpty()) + return m_msgIdx.value(TMMKey(msg), -1); + int i = m_idMsgIdx.value(msg.id(), -1); + if (i >= 0) + return i; + i = m_msgIdx.value(TMMKey(msg), -1); + // If both have an id, then find only by id. + return i >= 0 && m_messages.at(i).id().isEmpty() ? i : -1; } -TranslatorMessage Translator::find(const QString &context, +int Translator::find(const QString &context, const QString &comment, const TranslatorMessage::References &refs) const { if (!refs.isEmpty()) { @@ -365,75 +396,68 @@ TranslatorMessage Translator::find(const QString &context, foreach (const TranslatorMessage::Reference &itref, it->allReferences()) foreach (const TranslatorMessage::Reference &ref, refs) if (itref == ref) - return *it; + return it - m_messages.constBegin(); } } - return TranslatorMessage(); -} - -bool Translator::contains(const QString &context) const -{ - foreach (const TranslatorMessage &msg, m_messages) - if (msg.context() == context && msg.sourceText().isEmpty() && msg.id().isEmpty()) - return true; - return false; + return -1; } -TranslatorMessage Translator::find(const QString &context) const +int Translator::find(const QString &context) const { - foreach (const TranslatorMessage &msg, m_messages) - if (msg.context() == context && msg.sourceText().isEmpty() && msg.id().isEmpty()) - return msg; - return TranslatorMessage(); + ensureIndexed(); + return m_ctxCmtIdx.value(context, -1); } void Translator::stripObsoleteMessages() { - TMM newmm; - for (TMM::ConstIterator it = m_messages.begin(); it != m_messages.end(); ++it) - if (it->type() != TranslatorMessage::Obsolete) - newmm.append(*it); - m_messages = newmm; + for (TMM::Iterator it = m_messages.begin(); it != m_messages.end(); ) + if (it->type() == TranslatorMessage::Obsolete) + it = m_messages.erase(it); + else + ++it; + m_indexOk = false; } void Translator::stripFinishedMessages() { - TMM newmm; - for (TMM::ConstIterator it = m_messages.begin(); it != m_messages.end(); ++it) - if (it->type() != TranslatorMessage::Finished) - newmm.append(*it); - m_messages = newmm; + for (TMM::Iterator it = m_messages.begin(); it != m_messages.end(); ) + if (it->type() == TranslatorMessage::Finished) + it = m_messages.erase(it); + else + ++it; + m_indexOk = false; } void Translator::stripEmptyContexts() { - TMM newmm; - for (TMM::ConstIterator it = m_messages.begin(); it != m_messages.end(); ++it) - if (it->sourceText() != QLatin1String(ContextComment)) - newmm.append(*it); - m_messages = newmm; + for (TMM::Iterator it = m_messages.begin(); it != m_messages.end();) + if (it->sourceText() == QLatin1String(ContextComment)) + it = m_messages.erase(it); + else + ++it; + m_indexOk = false; } void Translator::stripNonPluralForms() { - TMM newmm; - for (TMM::ConstIterator it = m_messages.begin(); it != m_messages.end(); ++it) - if (it->isPlural()) - newmm.append(*it); - m_messages = newmm; + for (TMM::Iterator it = m_messages.begin(); it != m_messages.end(); ) + if (!it->isPlural()) + it = m_messages.erase(it); + else + ++it; + m_indexOk = false; } void Translator::stripIdenticalSourceTranslations() { - TMM newmm; - for (TMM::ConstIterator it = m_messages.begin(); it != m_messages.end(); ++it) { + for (TMM::Iterator it = m_messages.begin(); it != m_messages.end(); ) { // we need to have just one translation, and it be equal to the source - if (it->translations().count() != 1) - newmm.append(*it); - else if (it->translation() != it->sourceText()) - newmm.append(*it); + if (it->translations().count() == 1 && it->translation() == it->sourceText()) + it = m_messages.erase(it); + else + ++it; } - m_messages = newmm; + m_indexOk = false; } void Translator::dropTranslations() @@ -579,6 +603,7 @@ Translator::Duplicates Translator::resolveDuplicates() } if (!omsg->isTranslated() && msg.isTranslated()) omsg->setTranslations(msg.translations()); + m_indexOk = false; m_messages.removeAt(i); } return dups; @@ -610,20 +635,18 @@ void Translator::reportDuplicates(const Duplicates &dupes, // Used by lupdate to be able to search using absolute paths during merging void Translator::makeFileNamesAbsolute(const QDir &originalPath) { - TMM newmm; for (TMM::iterator it = m_messages.begin(); it != m_messages.end(); ++it) { - TranslatorMessage msg = *it; + TranslatorMessage &msg = *it; + TranslatorMessage::References refs = msg.allReferences(); msg.setReferences(TranslatorMessage::References()); - foreach (const TranslatorMessage::Reference &ref, it->allReferences()) { + foreach (const TranslatorMessage::Reference &ref, refs) { QString fileName = ref.fileName(); QFileInfo fi (fileName); if (fi.isRelative()) fileName = originalPath.absoluteFilePath(fileName); msg.addReference(fileName, ref.lineNumber()); } - newmm.append(msg); } - m_messages = newmm; } QList<TranslatorMessage> Translator::messages() const @@ -631,15 +654,6 @@ QList<TranslatorMessage> Translator::messages() const return m_messages; } -QList<TranslatorMessage> Translator::translatedMessages() const -{ - TMM result; - for (TMM::ConstIterator it = m_messages.begin(); it != m_messages.end(); ++it) - if (it->type() == TranslatorMessage::Finished) - result.append(*it); - return result; -} - QStringList Translator::normalizedTranslations(const TranslatorMessage &msg, int numPlurals) { QStringList translations = msg.translations(); @@ -680,9 +694,7 @@ void Translator::normalizeTranslations(ConversionData &cd) tlns.removeLast(); truncated = true; } - TranslatorMessage msg2(msg); - msg2.setTranslations(tlns); - m_messages[i] = msg2; + m_messages[i].setTranslations(tlns); } } if (truncated) |