Remove translation for label placeholders.

This commit is contained in:
Roman Telezhynskyi 2020-10-16 13:55:51 +03:00
parent d10f20f399
commit 34e1391ecb
8 changed files with 4 additions and 226 deletions

View File

@ -82,8 +82,7 @@ void DialogPatternMaterials::SetPatternMaterials(const QMap<int, QString> &list)
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
{
const QString translated = qApp->TrVars()->PlaceholderToUser(pl_userMaterial + QString::number(i + 1));
QTableWidgetItem *item = new QTableWidgetItem(per + translated + per);
QTableWidgetItem *item = new QTableWidgetItem(per + pl_userMaterial + QString::number(i + 1) + per);
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
item->setTextAlignment(Qt::AlignLeft);

View File

@ -183,44 +183,6 @@ const QString pl_wCut = QStringLiteral("wCut");
const QString pl_wOnFold = QStringLiteral("wOnFold");
const QString pl_measurement = QStringLiteral("measurement_");
const QStringList labelTemplatePlaceholders = {
pl_size,
pl_height,
pl_hip,
pl_waist,
pl_date,
pl_time,
pl_birthDate,
pl_patternName,
pl_patternNumber,
pl_author,
pl_customer,
pl_email,
pl_userMaterial,
pl_pExt,
pl_pUnits,
pl_pFileName,
pl_mFileName,
pl_mExt,
pl_mUnits,
pl_mSizeUnits,
pl_pLetter,
pl_pAnnotation,
pl_pOrientation,
pl_pRotation,
pl_pTilt,
pl_pFoldPosition,
pl_pName,
pl_pQuantity,
pl_mFabric,
pl_mLining,
pl_mInterfacing,
pl_mInterlining,
pl_wCut,
pl_wOnFold,
pl_measurement
};
const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png");
const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png");

View File

@ -440,8 +440,6 @@ extern const QString pl_measurement;
// Don't forget to syncronize with XSD schema.
const int userMaterialPlaceholdersQuantity = 20;
extern const QStringList labelTemplatePlaceholders;
extern const QString cursorArrowOpenHand;
extern const QString cursorArrowCloseHand;

View File

@ -52,7 +52,6 @@ VTranslateVars::VTranslateVars()
InitPatternMakingSystems();
InitVariables();
InitFunctions();
InitPlaceholder();
PrepareFunctionTranslations();
}
@ -536,46 +535,6 @@ void VTranslateVars::InitFunctions()
"function fmod"));
}
//---------------------------------------------------------------------------------------------------------------------
void VTranslateVars::InitPlaceholder()
{
placeholders.insert(pl_size, translate("VTranslateVars", "size", "placeholder"));
placeholders.insert(pl_height, translate("VTranslateVars", "height", "placeholder"));
placeholders.insert(pl_hip, translate("VTranslateVars", "hip", "placeholder"));
placeholders.insert(pl_waist, translate("VTranslateVars", "waist", "placeholder"));
placeholders.insert(pl_date, translate("VTranslateVars", "date", "placeholder"));
placeholders.insert(pl_time, translate("VTranslateVars", "time", "placeholder"));
placeholders.insert(pl_birthDate, translate("VTranslateVars", "birthDate", "placeholder"));
placeholders.insert(pl_patternName, translate("VTranslateVars", "patternName", "placeholder"));
placeholders.insert(pl_patternNumber, translate("VTranslateVars", "patternNumber", "placeholder"));
placeholders.insert(pl_author, translate("VTranslateVars", "author", "placeholder"));
placeholders.insert(pl_customer, translate("VTranslateVars", "customer", "placeholder"));
placeholders.insert(pl_email, translate("VTranslateVars", "email", "placeholder"));
placeholders.insert(pl_userMaterial, translate("VTranslateVars", "userMaterial", "placeholder"));
placeholders.insert(pl_pExt, translate("VTranslateVars", "pExt", "placeholder"));
placeholders.insert(pl_pUnits, translate("VTranslateVars", "pUnits", "placeholder"));
placeholders.insert(pl_pFileName, translate("VTranslateVars", "pFileName", "placeholder"));
placeholders.insert(pl_mFileName, translate("VTranslateVars", "mFileName", "placeholder"));
placeholders.insert(pl_mExt, translate("VTranslateVars", "mExt", "placeholder"));
placeholders.insert(pl_mUnits, translate("VTranslateVars", "mUnits", "placeholder"));
placeholders.insert(pl_mSizeUnits, translate("VTranslateVars", "mSizeUnits", "placeholder"));
placeholders.insert(pl_pLetter, translate("VTranslateVars", "pLetter", "placeholder"));
placeholders.insert(pl_pAnnotation, translate("VTranslateVars", "pAnnotation", "placeholder"));
placeholders.insert(pl_pOrientation, translate("VTranslateVars", "pOrientation", "placeholder"));
placeholders.insert(pl_pRotation, translate("VTranslateVars", "pRotation", "placeholder"));
placeholders.insert(pl_pTilt, translate("VTranslateVars", "pTilt", "placeholder"));
placeholders.insert(pl_pFoldPosition, translate("VTranslateVars", "pFoldPosition", "placeholder"));
placeholders.insert(pl_pName, translate("VTranslateVars", "pName", "placeholder"));
placeholders.insert(pl_pQuantity, translate("VTranslateVars", "pQuantity", "placeholder"));
placeholders.insert(pl_mFabric, translate("VTranslateVars", "mFabric", "placeholder"));
placeholders.insert(pl_mLining, translate("VTranslateVars", "mLining", "placeholder"));
placeholders.insert(pl_mInterfacing, translate("VTranslateVars", "mInterfacing", "placeholder"));
placeholders.insert(pl_mInterlining, translate("VTranslateVars", "mInterlining", "placeholder"));
placeholders.insert(pl_wCut, translate("VTranslateVars", "wCut", "placeholder"));
placeholders.insert(pl_wOnFold, translate("VTranslateVars", "wOnFold", "placeholder"));
placeholders.insert(pl_measurement, translate("VTranslateVars", "measurement", "placeholder"));
}
#undef translate
//---------------------------------------------------------------------------------------------------------------------
@ -769,101 +728,6 @@ QString VTranslateVars::InternalVarToUser(const QString &var) const
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::PlaceholderToUser(QString var) const
{
QString number;
if (var.startsWith(pl_userMaterial) && var.length() > pl_userMaterial.length())
{
number = var.right(var.length() - pl_userMaterial.length());
var = pl_userMaterial;
}
if (placeholders.contains(var))
{
return placeholders.value(var).translate(qApp->Settings()->GetLocale()) + number;
}
return var;
}
//---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::PlaceholderToUserText(QString text) const
{
QChar per('%');
auto i = placeholders.constBegin();
while (i != placeholders.constEnd())
{
if (i.key() != pl_userMaterial)
{
const QString translated = per + i.value().translate(qApp->Settings()->GetLocale()) + per;
const QString original = per + i.key() + per;
if (translated != original)
{
text.replace(original, translated);
}
}
else
{
const QString material_translated = i.value().translate(qApp->Settings()->GetLocale());
if (text.indexOf(i.key()) != -1)
{
for (int n = 0; n < userMaterialPlaceholdersQuantity; ++n)
{
const QString number = QString::number(n + 1);
const QString original = per + i.key() + number + per;
const QString translated = per + material_translated + number + per;
if (translated != original)
{
text.replace(original, translated);
}
}
}
}
++i;
}
return text;
}
//---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::PlaceholderFromUserText(QString text) const
{
QChar per('%');
auto i = placeholders.constBegin();
while (i != placeholders.constEnd())
{
if (i.key() != pl_userMaterial)
{
const QString original = per + i.key() + per;
const QString translated = per + i.value().translate(qApp->Settings()->GetLocale()) + per;
if (translated != original)
{
text.replace(translated, original);
}
}
else
{
const QString material_translated = i.value().translate(qApp->Settings()->GetLocale());
if (text.indexOf(material_translated) != -1)
{
for (int n = 0; n < userMaterialPlaceholdersQuantity; ++n)
{
const QString number = QString::number(n + 1);
const QString original = per + i.key() + number + per;
const QString translated = per + material_translated + number + per;
if (translated != original)
{
text.replace(translated, original);
}
}
}
}
++i;
}
return text;
}
//---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::VarToUser(const QString &var) const
{
@ -1195,7 +1059,6 @@ void VTranslateVars::Retranslate()
InitPatternMakingSystems();
InitVariables();
InitFunctions();
InitPlaceholder();
PrepareFunctionTranslations();
}

View File

@ -45,10 +45,6 @@ public:
bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const;
QString InternalVarToUser(const QString &var) const;
QString PlaceholderToUser(QString var) const;
QString PlaceholderToUserText(QString text) const;
QString PlaceholderFromUserText(QString text) const;
QString VarToUser(const QString &var) const;
QString VarFromUser(const QString &var) const;
@ -79,14 +75,12 @@ private:
QMap<QString, qmu::QmuTranslation> variables{};
QMap<QString, qmu::QmuTranslation> functions{};
QMap<QString, qmu::QmuTranslation> functionsDescriptions{};
QMap<QString, qmu::QmuTranslation> placeholders{};
QMap<QString, qmu::QmuTranslation> stDescriptions{};
QMap<QString, QString> translatedFunctions{};
void InitPatternMakingSystems();
void InitVariables();
void InitFunctions();
void InitPlaceholder();
void PrepareFunctionTranslations();

View File

@ -479,7 +479,7 @@ void DialogEditLabel::InitPlaceholdersMenu()
{
auto value = i.value();
QAction *action = m_placeholdersMenu->addAction(value.first);
action->setData(per + qApp->TrVars()->PlaceholderToUser(i.key()) + per);
action->setData(per + i.key() + per);
connect(action, &QAction::triggered, this, &DialogEditLabel::InsertPlaceholder);
++i;
}
@ -606,7 +606,7 @@ QVector<VLabelTemplateLine> DialogEditLabel::GetTemplate() const
if (lineItem)
{
VLabelTemplateLine line;
line.line = qApp->TrVars()->PlaceholderFromUserText(lineItem->text());
line.line = lineItem->text();
line.alignment = lineItem->textAlignment();
line.fontSizeIncrement = lineItem->data(Qt::UserRole).toInt();
@ -631,7 +631,7 @@ void DialogEditLabel::SetTemplate(const QVector<VLabelTemplateLine> &lines)
for (auto &line : lines)
{
QListWidgetItem *item = new QListWidgetItem(qApp->TrVars()->PlaceholderToUserText(line.line));
QListWidgetItem *item = new QListWidgetItem(line.line);
item->setTextAlignment(line.alignment);
item->setData(Qt::UserRole, line.fontSizeIncrement);

View File

@ -225,43 +225,6 @@ void TST_BuitInRegExp::TestCheckInternalVaribleRegExp()
}
}
//---------------------------------------------------------------------------------------------------------------------
void TST_BuitInRegExp::TestTemplatePlaceholders()
{
QSet<QString> originals;
QSet<QString> translations;
QStringList issue;
for (auto &placeholder : labelTemplatePlaceholders)
{
originals.insert(placeholder);
const QString translated = m_trMs->PlaceholderToUser(placeholder);
const QRegularExpression re(QLatin1String("^[^\\s]+$"));
if (re.match(translated).hasMatch())
{
if (not translations.contains(translated))
{
translations.insert(translated);
}
else
{
issue << QString("Duplicate translation '%1' for placeholder '%2' in locale '%3'.\n")
.arg(translated, placeholder, m_locale);
}
}
else
{
issue << QString("Invalid translation '%1' for placeholder '%2' in locale '%3'.\n")
.arg(translated, placeholder, m_locale);
}
}
QVERIFY2(issue.isEmpty(), qUtf8Printable(issue.join("")));
QCOMPARE(originals.size(), labelTemplatePlaceholders.size()); // All tags are unique
QCOMPARE(translations.size(), labelTemplatePlaceholders.size()); // All translated tags are unique
}
//---------------------------------------------------------------------------------------------------------------------
void TST_BuitInRegExp::TestForValidChars_data()
{

View File

@ -61,7 +61,6 @@ private slots:
void TestCheckUnderlineExists();
void TestCheckInternalVaribleRegExp_data();
void TestCheckInternalVaribleRegExp();
void TestTemplatePlaceholders();
void TestForValidChars_data();
void TestForValidChars();
void cleanupTestCase();