Fixed issue #931. Variable translation for Greek and Chinese are broken.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2019-01-17 16:08:55 +02:00
parent 2ffb316b36
commit b853e7b10b
11 changed files with 89 additions and 8 deletions

View File

@ -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.

View File

@ -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

View File

@ -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());

View File

@ -43,11 +43,12 @@ public:
virtual void InitCharSets() override;
void SetSepForTr(bool osSeparator, bool fromUser);
static void RemoveAll(QMap<int, QString> &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)

View File

@ -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))

View File

@ -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 <QtTest>
#include <QTranslator>
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));
}
}

View File

@ -59,6 +59,7 @@ protected:
void CallTestCheckRegExpNames();
void CallTestCheckIsNamesUnique();
void CallTestCheckNoOriginalNamesInTranslation();
void CallTestForValidCharacters();
private:
Q_DISABLE_COPY(TST_AbstractRegExp)

View File

@ -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()
{

View File

@ -62,6 +62,8 @@ private slots:
void TestCheckInternalVaribleRegExp_data();
void TestCheckInternalVaribleRegExp();
void TestTemplatePlaceholders();
void TestForValidChars_data();
void TestForValidChars();
void cleanupTestCase();
private:

View File

@ -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()
{

View File

@ -59,6 +59,8 @@ private slots:
void TestCheckIsNamesUnique();
void TestCheckNoOriginalNamesInTranslation_data();
void TestCheckNoOriginalNamesInTranslation();
void TestForValidChars_data();
void TestForValidChars();
void cleanupTestCase();
private: