From b853e7b10b2b7fa77dee8f37cacc70c1d7abbda2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 17 Jan 2019 16:08:55 +0200 Subject: [PATCH] Fixed issue #931. Variable translation for Greek and Chinese are broken. --HG-- branch : release --- ChangeLog.txt | 2 ++ scripts/alphabets.py | 2 +- src/libs/qmuparser/qmuformulabase.cpp | 13 +++---- src/libs/qmuparser/qmuformulabase.h | 3 +- src/libs/vpatterndb/vtranslatevars.cpp | 10 ++++++ .../TranslationsTest/tst_abstractregexp.cpp | 34 +++++++++++++++++++ .../TranslationsTest/tst_abstractregexp.h | 1 + .../TranslationsTest/tst_buitinregexp.cpp | 14 ++++++++ src/test/TranslationsTest/tst_buitinregexp.h | 2 ++ .../tst_measurementregexp.cpp | 14 ++++++++ .../TranslationsTest/tst_measurementregexp.h | 2 ++ 11 files changed, 89 insertions(+), 8 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 610a9f4a9..3438f6790 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,6 +8,8 @@ - [#915] Valentina produces wrong seam allowance for acute angle. - [#923] Valentina produces wrong seam allowance for rollback case. - [#924] Valentina produces wrong passmark for rollback case. +- [#930] Valentina doesn't update translation for variables after dynamic language switch. +- [#931] Variable translation for Greek and Chinese are broken. # Version 0.6.1 October 23, 2018 - [#885] Regression. Broken support for multi size measurements. diff --git a/scripts/alphabets.py b/scripts/alphabets.py index 9149e748e..574e6d113 100755 --- a/scripts/alphabets.py +++ b/scripts/alphabets.py @@ -30,7 +30,7 @@ VIETNAMESE_ALPHABET = set(u'aăâbcdđeêghiklmnoôơpqrstuưvxyAĂÂBCDĐEÊGH HAITIAN_ALPHABET = set(u'aanbchdeèenfghijklmnngoòonouounprstuivwyzAAnBChDEèEnFGHIJKLMNNgOòOnOuOunPRSTUiVWYZ') #HAITIAN ALPHABET GALICIAN_ALPHABET = set(u'abcdefghilmnñopqrstuvxzABCDEFGHILMNÑOPQRSTUVXZ') #GALICIAN ALPHABET DUTCH_ALPHABET = set(u'abcdefghijklmnopqrstuvwxijyzABCDEFGHIJKLMNOPQRSTUVWXIJYZ') #DUTCH ALPHABET -GREEK_ALPHABET = set(u'αβγδεζηθικλμνξοπρσςτυφχψωΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ') #GREEK ALPHABET +GREEK_ALPHABET = set(u'αβγδεζηθικλμνξοπρσςτυφχψωΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΆΈΉΊΌΎΏΐΪΫάέήίΰϊϋόύώ') #GREEK ALPHABET DANISH_ALPHABET = set(u'аbcdefghijklmnopqrstuvwxyzæøåАBCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ') #DANISH ALPHABET INDONESIAN_ALPHABET = set(u'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') #INDONESIAN ALPHABET IRISH_ALPHABET = set(u'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') #IRISH ALPHABET diff --git a/src/libs/qmuparser/qmuformulabase.cpp b/src/libs/qmuparser/qmuformulabase.cpp index 06fa1cee0..e50c2b694 100644 --- a/src/libs/qmuparser/qmuformulabase.cpp +++ b/src/libs/qmuparser/qmuformulabase.cpp @@ -62,12 +62,13 @@ void QmuFormulaBase::InitCharSets() //case. const QStringList symbols { - QStringLiteral("ցЀĆЈVӧĎАғΕĖӅИқΝĞơРңњΥҔĦШҫ̆جگĮаҳѕεشԶиһνԾрÃυلՆӝшËՎїPÓՖXӛӟŞãզhëծpóӞնxßվāŁЃֆĉЋCŬđҐГΒęҘЛΚŘġҠУGاհ"), - QStringLiteral("ЫدԱҰгβطԹõлκKՁÀуςهՉÈыvیՑÐSOřӘћաőcӐթèkàѓżűðsķչøӥӔĀփӣІĈЎґĐΗЖҙĘȚΟОҡĠآΧЦتЮұİزηжԸغẽοоÁՀقχцÉՈيюÑՐђӋі"), - QStringLiteral("әťӆўáŠĺѐfөըnñŰӤӨӹոľЁրăЉŭċБӸēłΔҖЙŤěΜӜDСձģΤӰЩīņحҮбưԳصδHйԻŇμӲӴсՃمτƠщՋєLQŹՓŕÖYśÞaգĽæiŽիӓîqճöyջþĂ"), - QStringLiteral("օЄӦĊЌΑĒДҗјΙȘĚМΡéĵĢФūӚΩبĪЬүќαذԲдҷιظԺмρՂфÇωوՊьÏՒTŚĻJբdçժlïӪղtպӫAւąЇčŃЏĕӯЗΖEțŮĝПΞأĥĹЧΦثÆӳЯI"), - QStringLiteral("سŲԵзζԽпξكՅÄчφNMՍӌяӢՕÔWÎŝÜџёźեägխoӒյôwĶBžսüЂĄև̈ЊČƏљΓВҕĔӮΛКĜΣТҥĤکЪƯخγвŅԴŪضλкԼĴσтÅՄنъÍՌRӕՔZÝŜ"), - QStringLiteral("båդﻩjíլļrӵմzýռپêЅքćچЍďӱҒЕůėژșΘØҚНğńءΠFҢХħΨҪЭųįҶرҲеԷňعθҺнԿفπÂхՇψÊэšՏÒUəÚѝŻşҤӑâeէŐımկòuշÕúտŔ") + QStringLiteral("ցЀĆЈVӧĎАғΕĖӅИқΝĞơРңњΥĦШҫ̆έجگĮаҳѕεشԶиһνԾрÃυلՆӝшËύՎїPÓՖXӛӟŞãզhëҔծpóӞնxßվāŁЃֆĉЋΊCŬđҐГΒęҘЛΚŘġҠУGا"), + QStringLiteral("հЫΪŪدԱҰгβطԹõлκKՁÀуςهՉÈыvیՑÐSOřӘћաőcӐթèkàѓżűðsķչøӥӔĀփӣІĈΏЎґĐΗЖҙĘȚΟОҡĠآΧЦتίЮұİزηжԸغẽοоÁՀقχц"), + QStringLiteral("ÉՈيюÑՐђӋіәťӆўáŠĺѐfөըnñŰӤӨӹոľЁրăЉŭċΌБӸēłΔҖЙŤěΜӜDСձģΤӰЩīņحάҮбưԳصδHйԻŇμӴсՃمτƠщՋόєLQŹՓŕÖYśÞaգĽ"), + QStringLiteral("æiŽիӓîqճöyջþĂօЄӦΉĊЌΑĒДҗјΙȘĚМΡéĵĢФūӚΩبĪЬүќαذԲдҷιظԺмρՂфÇωوՊьÏՒTŚĻJբdçժlïӪղtպӫAւąЇΆčŃЏΎĕӯЗΖEțŮ"), + QStringLiteral("ĝПΞأĥĹЧΦثÆӳЯήIسŲԵзζԽпξكՅÄчφNMՍӌяώӢӲՕÔWÎŝÜџёźեägխoӒյôwĶBžսüЂĄև̈ЊČƏљΓВҕĔӮΛКĜΣТҥĤکΫЪƯخγвŅԴϊضλкԼ"), + QStringLiteral("ĴσтÅՄنϋъÍՌRӕՔZÝŜbåդﻩjíլļrӵմӱzýռپêЅքćچΈЍďΐҒЕůėژșΘØҚНğńءΠFҢХħΨҪЭųįҶرΰҲеԷňعθҺнԿفπÂхՇψÊэšՏÒUəÚѝ"), + QStringLiteral("ŻşҤӑâeէŐımկòuշÕúտŔ") }; symbolsStr = symbols.join(QString()); diff --git a/src/libs/qmuparser/qmuformulabase.h b/src/libs/qmuparser/qmuformulabase.h index c74041ca3..087b46d35 100644 --- a/src/libs/qmuparser/qmuformulabase.h +++ b/src/libs/qmuparser/qmuformulabase.h @@ -43,11 +43,12 @@ public: virtual void InitCharSets() override; + void SetSepForTr(bool osSeparator, bool fromUser); + static void RemoveAll(QMap &map, const QString &val); protected: static qreal* AddVariable(const QString &a_szName, void *a_pUserData); - void SetSepForTr(bool osSeparator, bool fromUser); void SetSepForEval(); private: Q_DISABLE_COPY(QmuFormulaBase) diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index ed78d416b..751012a3f 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -772,6 +772,11 @@ QString VTranslateVars::PlaceholderFromUserText(QString text) const //--------------------------------------------------------------------------------------------------------------------- QString VTranslateVars::VarToUser(const QString &var) const { + if (qApp->Settings()->GetLocale() == QStringLiteral("zh_CN")) + { + return var; // We do not support translation of variables for Chinese + } + if (measurements.contains(var)) { return measurements.value(var).translate(qApp->Settings()->GetLocale()); @@ -788,6 +793,11 @@ QString VTranslateVars::VarToUser(const QString &var) const //--------------------------------------------------------------------------------------------------------------------- QString VTranslateVars::VarFromUser(const QString &var) const { + if (qApp->Settings()->GetLocale() == QStringLiteral("zh_CN")) + { + return var; // We do not support translation of variables for Chinese + } + QString newVar = var; int bias = 0; if (MeasurementsFromUser(newVar, 0, var, bias)) diff --git a/src/test/TranslationsTest/tst_abstractregexp.cpp b/src/test/TranslationsTest/tst_abstractregexp.cpp index 932252ec8..c77489f27 100644 --- a/src/test/TranslationsTest/tst_abstractregexp.cpp +++ b/src/test/TranslationsTest/tst_abstractregexp.cpp @@ -28,6 +28,7 @@ #include "tst_abstractregexp.h" #include "../qmuparser/qmudef.h" +#include "../qmuparser/qmuformulabase.h" #include "../vmisc/logging.h" #include "../vpatterndb/vtranslatevars.h" @@ -36,6 +37,17 @@ #include #include +namespace +{ +QString PrepareValidNameChars() +{ + qmu::QmuFormulaBase parser; + parser.InitCharSets(); + parser.SetSepForTr(false, true); + return parser.ValidNameChars(); +} +} // anonymous namespace + //--------------------------------------------------------------------------------------------------------------------- TST_AbstractRegExp::TST_AbstractRegExp(const QString &locale, QObject *parent) : AbstractTest(parent), @@ -190,3 +202,25 @@ void TST_AbstractRegExp::CallTestCheckNoOriginalNamesInTranslation() } } +//--------------------------------------------------------------------------------------------------------------------- +void TST_AbstractRegExp::CallTestForValidCharacters() +{ + QFETCH(QString, originalName); + + static const QString validNameChars = PrepareValidNameChars(); + + if (QLocale() == QLocale(QStringLiteral("zh_CN"))) + { + const QString message = QStringLiteral("We do not support translation of variables for locale zh_CN"); + QSKIP(qUtf8Printable(message)); + } + + const QString translated = m_trMs->VarToUser(originalName); + const int pos = FindFirstNotOf(translated, validNameChars); + if (pos != -1) + { + const QString message = QStringLiteral("Translated string '%1' contains invalid character '%2' at position '%3'.") + .arg(translated).arg(translated.at(pos)).arg(pos); + QFAIL(qUtf8Printable(message)); + } +} diff --git a/src/test/TranslationsTest/tst_abstractregexp.h b/src/test/TranslationsTest/tst_abstractregexp.h index 4f99d436b..3b41a5a43 100644 --- a/src/test/TranslationsTest/tst_abstractregexp.h +++ b/src/test/TranslationsTest/tst_abstractregexp.h @@ -59,6 +59,7 @@ protected: void CallTestCheckRegExpNames(); void CallTestCheckIsNamesUnique(); void CallTestCheckNoOriginalNamesInTranslation(); + void CallTestForValidCharacters(); private: Q_DISABLE_COPY(TST_AbstractRegExp) diff --git a/src/test/TranslationsTest/tst_buitinregexp.cpp b/src/test/TranslationsTest/tst_buitinregexp.cpp index b8a08d720..01865d47c 100644 --- a/src/test/TranslationsTest/tst_buitinregexp.cpp +++ b/src/test/TranslationsTest/tst_buitinregexp.cpp @@ -63,6 +63,8 @@ void TST_BuitInRegExp::initTestCase() QSKIP(qUtf8Printable(message)); } + QLocale::setDefault(QLocale(m_locale)); + InitTrMs();//Very important do this after loading QM files. } @@ -262,6 +264,18 @@ void TST_BuitInRegExp::TestTemplatePlaceholders() QCOMPARE(translations.size(), labelTemplatePlaceholders.size()); // All translated tags are unique } +//--------------------------------------------------------------------------------------------------------------------- +void TST_BuitInRegExp::TestForValidChars_data() +{ + PrepareData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_BuitInRegExp::TestForValidChars() +{ + CallTestForValidCharacters(); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_BuitInRegExp::cleanupTestCase() { diff --git a/src/test/TranslationsTest/tst_buitinregexp.h b/src/test/TranslationsTest/tst_buitinregexp.h index 4c209bac8..4738ba62d 100644 --- a/src/test/TranslationsTest/tst_buitinregexp.h +++ b/src/test/TranslationsTest/tst_buitinregexp.h @@ -62,6 +62,8 @@ private slots: void TestCheckInternalVaribleRegExp_data(); void TestCheckInternalVaribleRegExp(); void TestTemplatePlaceholders(); + void TestForValidChars_data(); + void TestForValidChars(); void cleanupTestCase(); private: diff --git a/src/test/TranslationsTest/tst_measurementregexp.cpp b/src/test/TranslationsTest/tst_measurementregexp.cpp index 6ce6579f3..0e070d87f 100644 --- a/src/test/TranslationsTest/tst_measurementregexp.cpp +++ b/src/test/TranslationsTest/tst_measurementregexp.cpp @@ -92,6 +92,8 @@ void TST_MeasurementRegExp::initTestCase() QSKIP(qUtf8Printable(message)); } + QLocale::setDefault(QLocale(m_locale)); + InitTrMs();//Very important do this after loading QM files. } @@ -143,6 +145,18 @@ void TST_MeasurementRegExp::TestCheckNoOriginalNamesInTranslation() CallTestCheckNoOriginalNamesInTranslation(); } +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::TestForValidChars_data() +{ + PrepareData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::TestForValidChars() +{ + CallTestForValidCharacters(); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_MeasurementRegExp::cleanupTestCase() { diff --git a/src/test/TranslationsTest/tst_measurementregexp.h b/src/test/TranslationsTest/tst_measurementregexp.h index 8856d7a16..559a6a75e 100644 --- a/src/test/TranslationsTest/tst_measurementregexp.h +++ b/src/test/TranslationsTest/tst_measurementregexp.h @@ -59,6 +59,8 @@ private slots: void TestCheckIsNamesUnique(); void TestCheckNoOriginalNamesInTranslation_data(); void TestCheckNoOriginalNamesInTranslation(); + void TestForValidChars_data(); + void TestForValidChars(); void cleanupTestCase(); private: