Translation from/to user text.
--HG-- branch : feature
This commit is contained in:
parent
89ed92e93f
commit
0b3342fe3d
|
@ -683,6 +683,44 @@ QString VTranslateVars::PlaceholderToUser(const QString &var) const
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VTranslateVars::PlaceholderToUserText(QString text) const
|
||||||
|
{
|
||||||
|
QChar per('%');
|
||||||
|
auto i = placeholders.constBegin();
|
||||||
|
while (i != placeholders.constEnd())
|
||||||
|
{
|
||||||
|
const QString translated = per + i.value().translate() + per;
|
||||||
|
const QString original = per + i.key() + per;
|
||||||
|
|
||||||
|
while (text.indexOf(original) != -1)
|
||||||
|
{
|
||||||
|
text.replace(original, translated);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VTranslateVars::PlaceholderFromUserText(QString text) const
|
||||||
|
{
|
||||||
|
QChar per('%');
|
||||||
|
auto i = placeholders.constBegin();
|
||||||
|
while (i != placeholders.constEnd())
|
||||||
|
{
|
||||||
|
const QString translated = per + i.value().translate() + per;
|
||||||
|
const QString original = per + i.key() + per;
|
||||||
|
|
||||||
|
while (text.indexOf(translated) != -1)
|
||||||
|
{
|
||||||
|
text.replace(translated, original);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VTranslateVars::VarToUser(const QString &var) const
|
QString VTranslateVars::VarToUser(const QString &var) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
|
|
||||||
#include "vtranslatemeasurements.h"
|
#include "vtranslatemeasurements.h"
|
||||||
|
|
||||||
#define trPL(pl) QLatin1String("%") + qApp->TrVars()->PlaceholderToUser((pl)) + QLatin1String("%")
|
|
||||||
|
|
||||||
class VTranslateVars : public VTranslateMeasurements
|
class VTranslateVars : public VTranslateMeasurements
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -50,6 +48,9 @@ public:
|
||||||
QString InternalVarToUser(const QString &var) const;
|
QString InternalVarToUser(const QString &var) const;
|
||||||
QString PlaceholderToUser(const QString &var) const;
|
QString PlaceholderToUser(const QString &var) const;
|
||||||
|
|
||||||
|
QString PlaceholderToUserText(QString text) const;
|
||||||
|
QString PlaceholderFromUserText(QString text) const;
|
||||||
|
|
||||||
QString VarToUser(const QString &var) const;
|
QString VarToUser(const QString &var) const;
|
||||||
QString VarFromUser(const QString &var) const;
|
QString VarFromUser(const QString &var) const;
|
||||||
|
|
||||||
|
|
|
@ -427,12 +427,13 @@ void DialogEditLabel::SetupControls()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogEditLabel::InitPlaceholdersMenu()
|
void DialogEditLabel::InitPlaceholdersMenu()
|
||||||
{
|
{
|
||||||
|
QChar per('%');
|
||||||
auto i = m_placeholders.constBegin();
|
auto i = m_placeholders.constBegin();
|
||||||
while (i != m_placeholders.constEnd())
|
while (i != m_placeholders.constEnd())
|
||||||
{
|
{
|
||||||
auto value = i.value();
|
auto value = i.value();
|
||||||
QAction *action = m_placeholdersMenu->addAction(value.first);
|
QAction *action = m_placeholdersMenu->addAction(value.first);
|
||||||
action->setData(trPL(i.key()));
|
action->setData(per + qApp->TrVars()->PlaceholderToUser(i.key()) + per);
|
||||||
connect(action, &QAction::triggered, this, &DialogEditLabel::InsertPlaceholder);
|
connect(action, &QAction::triggered, this, &DialogEditLabel::InsertPlaceholder);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
@ -500,7 +501,7 @@ QVector<VLabelTemplateLine> DialogEditLabel::PrepareLines() const
|
||||||
if (lineItem)
|
if (lineItem)
|
||||||
{
|
{
|
||||||
VLabelTemplateLine line;
|
VLabelTemplateLine line;
|
||||||
line.line = lineItem->text();
|
line.line = qApp->TrVars()->PlaceholderFromUserText(lineItem->text());
|
||||||
line.alignment = lineItem->textAlignment();
|
line.alignment = lineItem->textAlignment();
|
||||||
|
|
||||||
const QFont font = lineItem->font();
|
const QFont font = lineItem->font();
|
||||||
|
@ -524,7 +525,7 @@ void DialogEditLabel::InitEditLines(const QVector<VLabelTemplateLine> &lines)
|
||||||
|
|
||||||
for (int i=0; i<lines.size(); ++i)
|
for (int i=0; i<lines.size(); ++i)
|
||||||
{
|
{
|
||||||
QListWidgetItem *item = new QListWidgetItem(lines.at(i).line);
|
QListWidgetItem *item = new QListWidgetItem(qApp->TrVars()->PlaceholderToUserText(lines.at(i).line));
|
||||||
item->setTextAlignment(lines.at(i).alignment);
|
item->setTextAlignment(lines.at(i).alignment);
|
||||||
|
|
||||||
QFont font = item->font();
|
QFont font = item->font();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user