diff options
author | Lucie Gerard <lucie.gerard@qt.io> | 2019-04-01 14:23:14 +0200 |
---|---|---|
committer | Lucie Gerard <lucie.gerard@qt.io> | 2019-04-02 07:35:15 +0000 |
commit | 9364c3fcc8c98f70aceaac5b72823e290504cb2a (patch) | |
tree | c30e55902353e45045817b9bc1b2ab56e1b0e7ad /src | |
parent | d9aebed5c8520911f290da0d66b6cb849ccb9657 (diff) |
lupdate: Do not touch a translated file without target language
[ChangeLog][lupdate] lupdate will now generate an error if it is asked
to update a .ts file with translations, but without a target language.
This is to ensure that plural translations are not destroyed.
Fixes: QTBUG-53775
Change-Id: I646c1f2ec42a32dbc1a4676ad784887613607b78
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/linguist/lupdate/main.cpp | 13 | ||||
-rw-r--r-- | src/linguist/shared/translator.cpp | 11 | ||||
-rw-r--r-- | src/linguist/shared/translator.h | 1 |
3 files changed, 25 insertions, 0 deletions
diff --git a/src/linguist/lupdate/main.cpp b/src/linguist/lupdate/main.cpp index 134eab336..ba1126aa7 100644 --- a/src/linguist/lupdate/main.cpp +++ b/src/linguist/lupdate/main.cpp @@ -310,6 +310,19 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil printErr(LU::tr("lupdate warning: Specified source language '%1' disagrees with" " existing file's language '%2'. Ignoring.\n") .arg(sourceLanguage, tor.sourceLanguageCode())); + // If there is translation in the file, the language should be recognized + // (when the language is not recognized, plural translations are lost) + if (tor.translationsExist()) { + QLocale::Language l; + QLocale::Country c; + tor.languageAndCountry(tor.languageCode(), &l, &c); + QStringList forms; + if (!getNumerusInfo(l, c, 0, &forms, 0)) { + printErr(LU::tr("File %1 won't be updated: it contains translation but the" + " target language is not recognized\n").arg(fileName)); + continue; + } + } } else { if (!targetLanguage.isEmpty()) tor.setLanguageCode(targetLanguage); diff --git a/src/linguist/shared/translator.cpp b/src/linguist/shared/translator.cpp index af669e235..db28ea396 100644 --- a/src/linguist/shared/translator.cpp +++ b/src/linguist/shared/translator.cpp @@ -433,6 +433,17 @@ void Translator::stripUntranslatedMessages() m_indexOk = false; } +bool Translator::translationsExist() +{ + for (TMM::Iterator it = m_messages.begin(); it != m_messages.end(); ) { + if (it->isTranslated()) + return true; + else + ++it; + } + return false; +} + void Translator::stripEmptyContexts() { for (TMM::Iterator it = m_messages.begin(); it != m_messages.end();) diff --git a/src/linguist/shared/translator.h b/src/linguist/shared/translator.h index 8919a13df..5b5d12250 100644 --- a/src/linguist/shared/translator.h +++ b/src/linguist/shared/translator.h @@ -135,6 +135,7 @@ public: void dropTranslations(); void dropUiLines(); void makeFileNamesAbsolute(const QDir &originalPath); + bool translationsExist(); struct Duplicates { QSet<int> byId, byContents; }; Duplicates resolveDuplicates(); |