Fixed issue #853. Valentina doesn't translate user material placeholder.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-05-29 17:55:16 +03:00
parent 4109848349
commit 6869eab05a
2 changed files with 50 additions and 11 deletions

View File

@ -141,7 +141,7 @@ DialogPatternMaterials::~DialogPatternMaterials()
void DialogPatternMaterials::SetPatternMaterials(const QMap<int, QString> &list)
{
ui->tableWidget->setRowCount(userMaterialPlaceholdersQuantity);
QLatin1String per("%");
QChar per('%');
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
{

View File

@ -699,12 +699,32 @@ QString VTranslateVars::PlaceholderToUserText(QString text) const
auto i = placeholders.constBegin();
while (i != placeholders.constEnd())
{
const QString translated = per + i.value().translate(qApp->Settings()->GetLocale()) + per;
const QString original = per + i.key() + per;
if (translated != original)
if (i.key() != pl_userMaterial)
{
text.replace(original, translated);
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;
}
@ -718,12 +738,31 @@ QString VTranslateVars::PlaceholderFromUserText(QString text) const
auto i = placeholders.constBegin();
while (i != placeholders.constEnd())
{
const QString translated = per + i.value().translate(qApp->Settings()->GetLocale()) + per;
const QString original = per + i.key() + per;
if (translated != original)
if (i.key() != pl_userMaterial)
{
text.replace(translated, original);
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;
}