Fix issues with translations.
This commit is contained in:
parent
9c0fe9131a
commit
9878a2dba1
|
@ -371,7 +371,7 @@ void InitPiecePlaceholders(QMap<QString, QString> &placeholders, const QString &
|
||||||
}
|
}
|
||||||
catch (qmu::QmuParserError &e)
|
catch (qmu::QmuParserError &e)
|
||||||
{
|
{
|
||||||
const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg());
|
const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %1.").arg(e.GetMsg());
|
||||||
VAbstractApplication::VApp()->IsPedantic()
|
VAbstractApplication::VApp()->IsPedantic()
|
||||||
? throw VException(errorMsg)
|
? throw VException(errorMsg)
|
||||||
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
||||||
|
@ -385,7 +385,7 @@ void InitPiecePlaceholders(QMap<QString, QString> &placeholders, const QString &
|
||||||
}
|
}
|
||||||
catch (qmu::QmuParserError &e)
|
catch (qmu::QmuParserError &e)
|
||||||
{
|
{
|
||||||
const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg());
|
const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %1.").arg(e.GetMsg());
|
||||||
VAbstractApplication::VApp()->IsPedantic()
|
VAbstractApplication::VApp()->IsPedantic()
|
||||||
? throw VException(errorMsg)
|
? throw VException(errorMsg)
|
||||||
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
||||||
|
|
|
@ -981,9 +981,10 @@ auto VTranslateVars::InternalVarToUser(const QString &var) const -> QString
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VTranslateVars::VarToUser(const QString &var) const -> QString
|
auto VTranslateVars::VarToUser(const QString &var) const -> QString
|
||||||
{
|
{
|
||||||
if (VAbstractApplication::VApp()->Settings()->GetLocale() == QStringLiteral("zh_CN"))
|
const QString locale = VAbstractApplication::VApp()->Settings()->GetLocale();
|
||||||
|
if (locale == QStringLiteral("zh_CN") || locale == QStringLiteral("he_IL"))
|
||||||
{
|
{
|
||||||
return var; // We do not support translation of variables for Chinese
|
return var; // We do not support translation of variables for these locales
|
||||||
}
|
}
|
||||||
|
|
||||||
if (measurements.contains(var))
|
if (measurements.contains(var))
|
||||||
|
@ -1002,7 +1003,8 @@ auto VTranslateVars::VarToUser(const QString &var) const -> QString
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VTranslateVars::VarFromUser(const QString &var) const -> QString
|
auto VTranslateVars::VarFromUser(const QString &var) const -> QString
|
||||||
{
|
{
|
||||||
if (VAbstractApplication::VApp()->Settings()->GetLocale() == QStringLiteral("zh_CN"))
|
const QString locale = VAbstractApplication::VApp()->Settings()->GetLocale();
|
||||||
|
if (locale == QStringLiteral("zh_CN") || locale == QStringLiteral("he_IL"))
|
||||||
{
|
{
|
||||||
return var; // We do not support translation of variables for Chinese
|
return var; // We do not support translation of variables for Chinese
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ enum ErrorState
|
||||||
ErrorLoad = 0,
|
ErrorLoad = 0,
|
||||||
ErrorInstall,
|
ErrorInstall,
|
||||||
ErrorSize,
|
ErrorSize,
|
||||||
|
ErrorMissing,
|
||||||
NoError
|
NoError
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -814,7 +814,7 @@ void DialogEditLabel::SetPiece(const VPiece &piece)
|
||||||
}
|
}
|
||||||
catch (qmu::QmuParserError &e)
|
catch (qmu::QmuParserError &e)
|
||||||
{
|
{
|
||||||
const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg());
|
const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %1.").arg(e.GetMsg());
|
||||||
VAbstractApplication::VApp()->IsPedantic()
|
VAbstractApplication::VApp()->IsPedantic()
|
||||||
? throw VException(errorMsg)
|
? throw VException(errorMsg)
|
||||||
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
||||||
|
@ -828,7 +828,7 @@ void DialogEditLabel::SetPiece(const VPiece &piece)
|
||||||
}
|
}
|
||||||
catch (qmu::QmuParserError &e)
|
catch (qmu::QmuParserError &e)
|
||||||
{
|
{
|
||||||
const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg());
|
const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %1.").arg(e.GetMsg());
|
||||||
VAbstractApplication::VApp()->IsPedantic()
|
VAbstractApplication::VApp()->IsPedantic()
|
||||||
? throw VException(errorMsg)
|
? throw VException(errorMsg)
|
||||||
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
||||||
|
|
|
@ -53,10 +53,13 @@ auto main(int argc, char **argv) -> int
|
||||||
const QStringList locales = SupportedLocales();
|
const QStringList locales = SupportedLocales();
|
||||||
for (const auto &locale : locales)
|
for (const auto &locale : locales)
|
||||||
{
|
{
|
||||||
for(quint32 s = 0; s < TST_MeasurementRegExp::systemCounts; ++s)
|
for (const auto &s : TST_MeasurementRegExp::pmSystems)
|
||||||
|
{
|
||||||
|
if (locale != QStringLiteral("zh_CN") && locale != QStringLiteral("he_IL"))
|
||||||
{
|
{
|
||||||
ASSERT_TEST(new TST_MeasurementRegExp(s, locale));
|
ASSERT_TEST(new TST_MeasurementRegExp(s, locale));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT_TEST(new TST_TSLocaleTranslation(locale));
|
ASSERT_TEST(new TST_TSLocaleTranslation(locale));
|
||||||
ASSERT_TEST(new TST_BuitInRegExp(locale));
|
ASSERT_TEST(new TST_BuitInRegExp(locale));
|
||||||
|
|
|
@ -33,14 +33,25 @@
|
||||||
#include "abstracttest.h"
|
#include "abstracttest.h"
|
||||||
|
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
const quint32 TST_MeasurementRegExp::systemCounts = 56; // count of pattern making systems
|
namespace
|
||||||
|
{
|
||||||
|
auto InitializePmSystems() noexcept -> QStringList
|
||||||
|
{
|
||||||
|
return {"p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13",
|
||||||
|
"p14", "p15", "p16", "p17", "p18", "p19", "p20", "p21", "p22", "p23", "p24", "p25", "p26", "p27",
|
||||||
|
"p28", "p29", "p30", "p31", "p32", "p33", "p34", "p35", "p36", "p37", "p38", "p39", "p40", "p41",
|
||||||
|
"p42", "p43", "p44", "p45", "p46", "p47", "p48", "p49", "p50", "p51", "p52", "p53", "p54", "p998"};
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
const QStringList TST_MeasurementRegExp::pmSystems = InitializePmSystems();
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
TST_MeasurementRegExp::TST_MeasurementRegExp(quint32 systemCode, const QString &locale, QObject *parent)
|
TST_MeasurementRegExp::TST_MeasurementRegExp(const QString &systemCode, const QString &locale, QObject *parent)
|
||||||
: TST_AbstractRegExp(locale, parent),
|
: TST_AbstractRegExp(locale, parent),
|
||||||
m_systemCode(systemCode),
|
m_systemCode(systemCode),
|
||||||
m_system(),
|
|
||||||
m_pmsTranslator(nullptr)
|
m_pmsTranslator(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -54,13 +65,6 @@ TST_MeasurementRegExp::~TST_MeasurementRegExp()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_MeasurementRegExp::initTestCase()
|
void TST_MeasurementRegExp::initTestCase()
|
||||||
{
|
{
|
||||||
if (m_systemCode > systemCounts)
|
|
||||||
{
|
|
||||||
QFAIL("Unexpected system code.");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_system = QString("p%1").arg(m_systemCode);
|
|
||||||
|
|
||||||
if (m_locale.isEmpty())
|
if (m_locale.isEmpty())
|
||||||
{
|
{
|
||||||
QFAIL("Empty locale code.");
|
QFAIL("Empty locale code.");
|
||||||
|
@ -73,19 +77,24 @@ void TST_MeasurementRegExp::initTestCase()
|
||||||
QFAIL("Unsupported locale code.");
|
QFAIL("Unsupported locale code.");
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCombinations(systemCounts, locales);
|
TestCombinations(locales);
|
||||||
|
|
||||||
if (LoadMeasurements(m_system, m_locale) != NoError)
|
const int res = LoadMeasurements(m_systemCode, m_locale);
|
||||||
|
if (res != NoError)
|
||||||
{
|
{
|
||||||
const QString message = QString("Couldn't load measurements. System = %1, locale = %2")
|
const QString message =
|
||||||
.arg(m_system, m_locale);
|
QStringLiteral("Couldn't load measurements. System = %1, locale = %2").arg(m_systemCode, m_locale);
|
||||||
QSKIP(qUtf8Printable(message));
|
|
||||||
|
if (res == ErrorMissing)
|
||||||
|
{
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoadVariables(m_locale) != NoError)
|
if (LoadVariables(m_locale) != NoError)
|
||||||
{
|
{
|
||||||
const QString message = QString("Couldn't load variables. System = %1, locale = %2")
|
const QString message =
|
||||||
.arg(m_system, m_locale);
|
QString("Couldn't load variables. System = %1, locale = %2").arg(m_systemCode, m_locale);
|
||||||
QSKIP(qUtf8Printable(message));
|
QSKIP(qUtf8Printable(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +130,9 @@ void TST_MeasurementRegExp::TestCheckRegExpNames()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_MeasurementRegExp::TestCheckIsNamesUnique_data()
|
void TST_MeasurementRegExp::TestCheckIsNamesUnique_data()
|
||||||
{
|
{
|
||||||
|
QTest::addColumn<QString>("translatedName");
|
||||||
|
QTest::addColumn<QStringList>("originalNames");
|
||||||
|
|
||||||
const QStringList originalNames = AllNames();
|
const QStringList originalNames = AllNames();
|
||||||
QMultiMap<QString, QString> names;
|
QMultiMap<QString, QString> names;
|
||||||
for (const auto &originalName : originalNames)
|
for (const auto &originalName : originalNames)
|
||||||
|
@ -128,13 +140,10 @@ void TST_MeasurementRegExp::TestCheckIsNamesUnique_data()
|
||||||
names.insert(m_trMs->VarToUser(originalName), originalName);
|
names.insert(m_trMs->VarToUser(originalName), originalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTest::addColumn<QString>("translatedName");
|
|
||||||
QTest::addColumn<QStringList>("originalNames");
|
|
||||||
|
|
||||||
QList<QString> keys = names.uniqueKeys();
|
QList<QString> keys = names.uniqueKeys();
|
||||||
for (const auto &key : keys)
|
for (const auto &key : keys)
|
||||||
{
|
{
|
||||||
const QString tag = QString("System: '%1', locale: '%2'. Name '%3'").arg(m_system, m_locale, key);
|
const QString tag = QString("System: '%1', locale: '%2'. Name '%3'").arg(m_systemCode, m_locale, key);
|
||||||
QTest::newRow(qUtf8Printable(tag)) << key << QStringList(names.values(key));
|
QTest::newRow(qUtf8Printable(tag)) << key << QStringList(names.values(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,13 +154,6 @@ void TST_MeasurementRegExp::TestCheckIsNamesUnique()
|
||||||
QFETCH(QString, translatedName);
|
QFETCH(QString, translatedName);
|
||||||
QFETCH(QStringList, originalNames);
|
QFETCH(QStringList, originalNames);
|
||||||
|
|
||||||
if (QLocale() == QLocale(QStringLiteral("zh_CN")) || QLocale() == QLocale(QStringLiteral("he_IL")))
|
|
||||||
{
|
|
||||||
const QString message = QStringLiteral("We do not support translation of variables for locale %1")
|
|
||||||
.arg(QLocale().name());
|
|
||||||
QSKIP(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalNames.size() > 1)
|
if (originalNames.size() > 1)
|
||||||
{
|
{
|
||||||
const QString message = QString("Name is not unique. Translated name:'%1' also assosiated with: %2.")
|
const QString message = QString("Name is not unique. Translated name:'%1' also assosiated with: %2.")
|
||||||
|
@ -187,14 +189,14 @@ void TST_MeasurementRegExp::TestForValidChars()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_MeasurementRegExp::cleanupTestCase()
|
void TST_MeasurementRegExp::cleanupTestCase()
|
||||||
{
|
{
|
||||||
RemoveTrMeasurements(m_system, m_locale);
|
RemoveTrMeasurements(m_systemCode, m_locale);
|
||||||
RemoveTrVariables(m_locale);
|
RemoveTrVariables(m_locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_MeasurementRegExp::TestCombinations(int systemCounts, const QStringList &locales) const
|
void TST_MeasurementRegExp::TestCombinations(const QStringList &locales) const
|
||||||
{
|
{
|
||||||
const vsizetype combinations = systemCounts * locales.size();
|
const vsizetype combinations = TST_MeasurementRegExp::pmSystems.size() * locales.size();
|
||||||
|
|
||||||
QDir dir(TranslationsPath());
|
QDir dir(TranslationsPath());
|
||||||
const QStringList fileNames = dir.entryList(QStringList("measurements_p*_*.qm"));
|
const QStringList fileNames = dir.entryList(QStringList("measurements_p*_*.qm"));
|
||||||
|
@ -214,7 +216,7 @@ void TST_MeasurementRegExp::PrepareData()
|
||||||
|
|
||||||
for (const auto &str : originalNames)
|
for (const auto &str : originalNames)
|
||||||
{
|
{
|
||||||
const QString tag = QString("System: '%1', locale: '%2'. Name '%3'").arg(m_system, m_locale, str);
|
const QString tag = QString("System: '%1', locale: '%2'. Name '%3'").arg(m_systemCode, m_locale, str);
|
||||||
QTest::newRow(qUtf8Printable(tag)) << str;
|
QTest::newRow(qUtf8Printable(tag)) << str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +231,19 @@ auto TST_MeasurementRegExp::AllNames() -> QStringList
|
||||||
auto TST_MeasurementRegExp::LoadMeasurements(const QString &checkedSystem, const QString &checkedLocale) -> int
|
auto TST_MeasurementRegExp::LoadMeasurements(const QString &checkedSystem, const QString &checkedLocale) -> int
|
||||||
{
|
{
|
||||||
const QString path = TranslationsPath();
|
const QString path = TranslationsPath();
|
||||||
const QString file = QString("measurements_%1_%2.qm").arg(checkedSystem, checkedLocale);
|
const QString file = QStringLiteral("measurements_%1_%2.qm").arg(checkedSystem, checkedLocale);
|
||||||
|
|
||||||
|
QFileInfo info(path + QLatin1String("/") + file);
|
||||||
|
|
||||||
|
if (not info.exists())
|
||||||
|
{
|
||||||
|
const QString message =
|
||||||
|
QString("File for translation for system = %1 and locale = %2 doesn't exists. \nFull path: %3/%4")
|
||||||
|
.arg(checkedSystem, checkedLocale, path, file);
|
||||||
|
QWARN(qUtf8Printable(message));
|
||||||
|
|
||||||
|
return ErrorMissing;
|
||||||
|
}
|
||||||
|
|
||||||
if (QFileInfo(path + QLatin1String("/") + file).size() <= 34)
|
if (QFileInfo(path + QLatin1String("/") + file).size() <= 34)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,11 +40,11 @@ class VTranslateVars;
|
||||||
class TST_MeasurementRegExp : public TST_AbstractRegExp
|
class TST_MeasurementRegExp : public TST_AbstractRegExp
|
||||||
{
|
{
|
||||||
Q_OBJECT // NOLINT
|
Q_OBJECT // NOLINT
|
||||||
public:
|
|
||||||
TST_MeasurementRegExp(quint32 systemCode, const QString &locale, QObject *parent = nullptr);
|
public : TST_MeasurementRegExp(const QString &systemCode, const QString &locale, QObject *parent = nullptr);
|
||||||
virtual ~TST_MeasurementRegExp();
|
virtual ~TST_MeasurementRegExp();
|
||||||
|
|
||||||
static const quint32 systemCounts;
|
static const QStringList pmSystems;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void PrepareData() override;
|
virtual void PrepareData() override;
|
||||||
|
@ -68,8 +68,7 @@ private:
|
||||||
// cppcheck-suppress unknownMacro
|
// cppcheck-suppress unknownMacro
|
||||||
Q_DISABLE_COPY_MOVE(TST_MeasurementRegExp) // NOLINT
|
Q_DISABLE_COPY_MOVE(TST_MeasurementRegExp) // NOLINT
|
||||||
|
|
||||||
quint32 m_systemCode;
|
QString m_systemCode;
|
||||||
QString m_system;
|
|
||||||
QPointer<QTranslator> m_pmsTranslator;
|
QPointer<QTranslator> m_pmsTranslator;
|
||||||
|
|
||||||
void TestCombinations(const QStringList &locales) const;
|
void TestCombinations(const QStringList &locales) const;
|
||||||
|
|
|
@ -138,10 +138,8 @@ void TST_TSLocaleTranslation::CheckPlaceMarkerExist()
|
||||||
|
|
||||||
if (sourceMarkerFlag != translationMarkerFlag)
|
if (sourceMarkerFlag != translationMarkerFlag)
|
||||||
{
|
{
|
||||||
const QString message =
|
const QString message = QString("String '%1'. Placemark '%%2' mismatch. ")
|
||||||
QString("Compare to source string in the translation string '%1' was missed place marker ")
|
.arg(translation, QString().setNum(sourceMarkCount + 1));
|
||||||
.arg(translation) + QLatin1String("'%") + QString().setNum(sourceMarkCount) +
|
|
||||||
QLatin1String("'.");
|
|
||||||
QFAIL(qUtf8Printable(message));
|
QFAIL(qUtf8Printable(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,26 @@ void TST_TSTranslation::CheckEnglishLocalization_data()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto PluralForm = [translationTag]()
|
||||||
|
{
|
||||||
|
QDomNodeList children = translationTag.childNodes();
|
||||||
|
for (int i = 0; i < children.size(); ++i)
|
||||||
|
{
|
||||||
|
QDomNode child = children.item(i);
|
||||||
|
if (child.isElement())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (PluralForm())
|
||||||
|
{
|
||||||
|
continue; // do not check plural forms
|
||||||
|
}
|
||||||
|
|
||||||
const QString translation = translationTag.text();
|
const QString translation = translationTag.text();
|
||||||
if (translation.isEmpty())
|
if (translation.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user