Rewrite describing placeholders %size% and %height%. New way will help avoid

translation mistake.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-08-23 14:02:09 +03:00
parent 872fcc5217
commit 6281f46a8e
7 changed files with 51 additions and 11 deletions

View File

@ -173,6 +173,11 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte
ui->lineEditCustomerName->setText(doc->GetCustomerName()); ui->lineEditCustomerName->setText(doc->GetCustomerName());
ui->labelCreationDate->setText(QDate::currentDate().toString(Qt::SystemLocaleLongDate)); ui->labelCreationDate->setText(QDate::currentDate().toString(Qt::SystemLocaleLongDate));
ui->lineEditSize->setText(doc->GetPatternSize()); ui->lineEditSize->setText(doc->GetPatternSize());
const QString plSize = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_size) + QLatin1String("%");
const QString plHeight = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_height) + QLatin1String("%");
ui->lineEditSize->setToolTip(tr("Use %1 and %2 to insert pattern size and height").arg(plSize, plHeight));
ui->checkBoxShowDate->setChecked(doc->IsDateVisible()); ui->checkBoxShowDate->setChecked(doc->IsDateVisible());
if (doc->MPath().isEmpty() == true) if (doc->MPath().isEmpty() == true)
{ {
@ -184,7 +189,6 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte
ui->checkBoxShowMeasurements->setChecked(doc->IsMeasurementsVisible()); ui->checkBoxShowMeasurements->setChecked(doc->IsMeasurementsVisible());
} }
connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged);
connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged);
connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged);

View File

@ -1053,7 +1053,7 @@
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>401</width> <width>401</width>
<height>241</height> <height>252</height>
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
@ -1139,9 +1139,6 @@
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QLineEdit" name="lineEditSize"> <widget class="QLineEdit" name="lineEditSize">
<property name="toolTip">
<string>Use %size% and %height% to insert pattern size and height</string>
</property>
<property name="maxLength"> <property name="maxLength">
<number>40</number> <number>40</number>
</property> </property>
@ -1189,8 +1186,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>248</x> <x>257</x>
<y>254</y> <y>682</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@ -1205,8 +1202,8 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>316</x> <x>325</x>
<y>260</y> <y>682</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>286</x>

View File

@ -35,6 +35,7 @@
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatternpiecedata.h"
#include "../vmisc/vabstractapplication.h"
#include "vtextmanager.h" #include "vtextmanager.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -324,8 +325,14 @@ void VTextManager::Update(const VAbstractPattern *pDoc, qreal dSize, qreal dHeig
tl.m_qsText = pDoc->GetPatternSize(); tl.m_qsText = pDoc->GetPatternSize();
if (tl.m_qsText.isEmpty() == false) if (tl.m_qsText.isEmpty() == false)
{ {
tl.m_qsText.replace(QApplication::translate("Detail", "%size%", 0), QString::number(dSize)); // Such describing placeholders will help avoid mistake of localization.
tl.m_qsText.replace(QApplication::translate("Detail", "%height%", 0), QString::number(dHeight)); // Translators very often remove '%'.
QString placeholder = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_size) + QLatin1String("%");
tl.m_qsText.replace(placeholder, QString::number(dSize));
placeholder = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_height) + QLatin1String("%");
tl.m_qsText.replace(placeholder, QString::number(dHeight));
tl.m_eFontWeight = QFont::Normal; tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal; tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0; tl.m_iFontSize = 0;

View File

@ -423,6 +423,9 @@ const QStringList builInPostfixOperators = QStringList() << cm_Oprt
<< mm_Oprt << mm_Oprt
<< in_Oprt; << in_Oprt;
const QString pl_size = QStringLiteral("size");
const QString pl_height = QStringLiteral("height");
const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png"); const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png");
const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png"); const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png");

View File

@ -592,6 +592,10 @@ extern const QString in_Oprt;
extern const QStringList builInPostfixOperators; extern const QStringList builInPostfixOperators;
// Placeholders
extern const QString pl_size;
extern const QString pl_height;
extern const QString cursorArrowOpenHand; extern const QString cursorArrowOpenHand;
extern const QString cursorArrowCloseHand; extern const QString cursorArrowCloseHand;

View File

@ -55,12 +55,14 @@ VTranslateVars::VTranslateVars()
variables(QMap<QString, QmuTranslation>()), variables(QMap<QString, QmuTranslation>()),
functions(QMap<QString, QmuTranslation>()), functions(QMap<QString, QmuTranslation>()),
postfixOperators(QMap<QString, QmuTranslation>()), postfixOperators(QMap<QString, QmuTranslation>()),
placeholders(QMap<QString, QmuTranslation>()),
stDescriptions(QMap<QString, QmuTranslation>()) stDescriptions(QMap<QString, QmuTranslation>())
{ {
InitPatternMakingSystems(); InitPatternMakingSystems();
InitVariables(); InitVariables();
InitFunctions(); InitFunctions();
InitPostfixOperators(); InitPostfixOperators();
InitPlaceholder();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -430,6 +432,13 @@ void VTranslateVars::InitPostfixOperators()
postfixOperators.insert(in_Oprt, translate("VTranslateVars", "in", "inch")); postfixOperators.insert(in_Oprt, translate("VTranslateVars", "in", "inch"));
} }
//---------------------------------------------------------------------------------------------------------------------
void VTranslateVars::InitPlaceholder()
{
placeholders.insert(pl_size, translate("VTranslateVars", "size", "placeholder"));
placeholders.insert(pl_height, translate("VTranslateVars", "height", "placeholder"));
}
#undef translate #undef translate
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -614,6 +623,17 @@ QString VTranslateVars::InternalVarToUser(const QString &var) const
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::PlaceholderToUser(const QString &var) const
{
if (placeholders.contains(var))
{
return placeholders.value(var).translate();
}
return var;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::VarToUser(const QString &var) const QString VTranslateVars::VarToUser(const QString &var) const
{ {
@ -945,6 +965,7 @@ void VTranslateVars::Retranslate()
InitVariables(); InitVariables();
InitFunctions(); InitFunctions();
InitPostfixOperators(); InitPostfixOperators();
InitPlaceholder();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -46,6 +46,7 @@ public:
bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const; bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const;
QString InternalVarToUser(const QString &var) const; QString InternalVarToUser(const QString &var) const;
QString PlaceholderToUser(const QString &var) 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;
@ -61,6 +62,7 @@ public:
QString FormulaToUser(const QString &formula, bool osSeparator) const; QString FormulaToUser(const QString &formula, bool osSeparator) const;
virtual void Retranslate() Q_DECL_OVERRIDE; virtual void Retranslate() Q_DECL_OVERRIDE;
QMap<QString, qmu::QmuTranslation> GetFunctions() const; QMap<QString, qmu::QmuTranslation> GetFunctions() const;
private: private:
@ -71,12 +73,14 @@ private:
QMap<QString, qmu::QmuTranslation> variables; QMap<QString, qmu::QmuTranslation> variables;
QMap<QString, qmu::QmuTranslation> functions; QMap<QString, qmu::QmuTranslation> functions;
QMap<QString, qmu::QmuTranslation> postfixOperators; QMap<QString, qmu::QmuTranslation> postfixOperators;
QMap<QString, qmu::QmuTranslation> placeholders;
QMap<QString, qmu::QmuTranslation> stDescriptions; QMap<QString, qmu::QmuTranslation> stDescriptions;
void InitPatternMakingSystems(); void InitPatternMakingSystems();
void InitVariables(); void InitVariables();
void InitFunctions(); void InitFunctions();
void InitPostfixOperators(); void InitPostfixOperators();
void InitPlaceholder();
void InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author, void InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author,
const qmu::QmuTranslation &book); const qmu::QmuTranslation &book);