Independent translation for piece labels.

This commit is contained in:
Roman Telezhynskyi 2023-05-16 19:20:19 +03:00
parent e2815f39ed
commit f69eaafe86
12 changed files with 202 additions and 75 deletions

View File

@ -27,6 +27,7 @@
- Simplify number of versions for DXF AAMA/ASTM. - Simplify number of versions for DXF AAMA/ASTM.
- New notch type - Check Notch. - New notch type - Check Notch.
- Control a notch width and angle with formulas. - Control a notch width and angle with formulas.
- Independent translation for piece labels.
# Valentina 0.7.52 September 12, 2022 # Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru. - Fix crash when default locale is ru.

View File

@ -59,6 +59,10 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
connect(ui->langCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(ui->langCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this]() { m_langChanged = true; }); [this]() { m_langChanged = true; });
InitPieceLabelLanguages(ui->comboBoxPieceLbelLanguage);
connect(ui->comboBoxPieceLbelLanguage, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this]() { m_pieceLabelLangChanged = true; });
//-------------------- Decimal separator setup //-------------------- Decimal separator setup
ui->osOptionCheck->setChecked(VAbstractValApplication::VApp()->ValentinaSettings()->GetOsSeparator()); ui->osOptionCheck->setChecked(VAbstractValApplication::VApp()->ValentinaSettings()->GetOsSeparator());
@ -203,6 +207,13 @@ auto PreferencesConfigurationPage::Apply() -> QStringList
settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->isChecked()); settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->isChecked());
settings->SetInteractiveTools(ui->checkBoxInteractiveTools->isChecked()); settings->SetInteractiveTools(ui->checkBoxInteractiveTools->isChecked());
if (m_pieceLabelLangChanged)
{
const auto locale = qvariant_cast<QString>(ui->comboBoxPieceLbelLanguage->currentData());
settings->SetPieceLabelLocale(locale);
m_pieceLabelLangChanged = false;
}
if (m_langChanged || m_systemChanged) if (m_langChanged || m_systemChanged)
{ {
const auto locale = qvariant_cast<QString>(ui->langCombo->currentData()); const auto locale = qvariant_cast<QString>(ui->langCombo->currentData());
@ -299,4 +310,13 @@ void PreferencesConfigurationPage::RetranslateUi()
ui->systemCombo->blockSignals(false); ui->systemCombo->blockSignals(false);
ui->systemCombo->setCurrentIndex(ui->systemCombo->findData(code)); ui->systemCombo->setCurrentIndex(ui->systemCombo->findData(code));
} }
{
ui->comboBoxPieceLbelLanguage->blockSignals(true);
const auto code = qvariant_cast<QString>(ui->comboBoxPieceLbelLanguage->currentData());
InitPieceLabelLanguages(ui->comboBoxPieceLbelLanguage);
ui->comboBoxPieceLbelLanguage->setCurrentIndex(-1);
ui->comboBoxPieceLbelLanguage->blockSignals(false);
ui->comboBoxPieceLbelLanguage->setCurrentIndex(ui->comboBoxPieceLbelLanguage->findData(code));
}
} }

View File

@ -53,6 +53,7 @@ private:
Q_DISABLE_COPY_MOVE(PreferencesConfigurationPage) // NOLINT Q_DISABLE_COPY_MOVE(PreferencesConfigurationPage) // NOLINT
Ui::PreferencesConfigurationPage *ui; Ui::PreferencesConfigurationPage *ui;
bool m_langChanged{false}; bool m_langChanged{false};
bool m_pieceLabelLangChanged{false};
bool m_systemChanged{false}; bool m_systemChanged{false};
bool m_unitChanged{false}; bool m_unitChanged{false};
bool m_labelLangChanged{false}; bool m_labelLangChanged{false};

View File

@ -35,7 +35,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>624</width> <width>624</width>
<height>867</height> <height>898</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -104,13 +104,20 @@
<widget class="QComboBox" name="langCombo"/> <widget class="QComboBox" name="langCombo"/>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Piece label language:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Decimal separator parts:</string> <string>Decimal separator parts:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="2" column="1">
<widget class="QCheckBox" name="osOptionCheck"> <widget class="QCheckBox" name="osOptionCheck">
<property name="text"> <property name="text">
<string notr="true">&lt; With OS options &gt;</string> <string notr="true">&lt; With OS options &gt;</string>
@ -120,26 +127,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>Default unit:</string> <string>Default unit:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="1">
<widget class="QComboBox" name="unitCombo"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>Label language:</string> <string>Label language:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="4" column="1">
<widget class="QComboBox" name="unitCombo"/>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="labelCombo"/> <widget class="QComboBox" name="labelCombo"/>
</item> </item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxPieceLbelLanguage"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -36,7 +36,6 @@
#include <QLatin1String> #include <QLatin1String>
#include <QRegularExpression> #include <QRegularExpression>
#include <QtMath> #include <QtMath>
#include <QGlobalStatic>
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vabstractvalapplication.h"
@ -328,11 +327,14 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) ->
placeholders.insert(pl_pName, QString()); placeholders.insert(pl_pName, QString());
placeholders.insert(pl_pQuantity, QString()); placeholders.insert(pl_pQuantity, QString());
placeholders.insert(pl_wOnFold, QString()); placeholders.insert(pl_wOnFold, QString());
placeholders.insert(pl_mFabric, QObject::tr("Fabric"));
placeholders.insert(pl_mLining, QObject::tr("Lining")); QSharedPointer<QTranslator> phTr = VAbstractValApplication::VApp()->GetPlaceholderTranslator();
placeholders.insert(pl_mInterfacing, QObject::tr("Interfacing"));
placeholders.insert(pl_mInterlining, QObject::tr("Interlining")); placeholders.insert(pl_mFabric, phTr->translate("Placeholder", "Fabric"));
placeholders.insert(pl_wCut, QObject::tr("Cut")); placeholders.insert(pl_mLining, phTr->translate("Placeholder", "Lining"));
placeholders.insert(pl_mInterfacing, phTr->translate("Placeholder", "Interfacing"));
placeholders.insert(pl_mInterlining, phTr->translate("Placeholder", "Interlining"));
placeholders.insert(pl_wCut, phTr->translate("Placeholder", "Cut"));
return placeholders; return placeholders;
} }
@ -352,7 +354,8 @@ void InitPiecePlaceholders(QMap<QString, QString> &placeholders, const QString &
if (data.IsOnFold()) if (data.IsOnFold())
{ {
placeholders[pl_wOnFold] = QObject::tr("on fold"); QSharedPointer<QTranslator> phTr = VAbstractValApplication::VApp()->GetPlaceholderTranslator();
placeholders[pl_wOnFold] = phTr->translate("Placeholder", "on fold");
} }
VContainer completeData = *pattern; VContainer completeData = *pattern;

View File

@ -65,6 +65,79 @@
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
namespace
{
//---------------------------------------------------------------------------------------------------------------------
auto LocalList() -> QStringList
{
static QStringList fileNames;
// Check if file names have already been cached
if (!fileNames.isEmpty())
{
return fileNames;
}
QDirIterator it(VAbstractApplication::translationsPath(), QStringList("valentina_*.qm"), QDir::Files,
QDirIterator::Subdirectories);
while (it.hasNext())
{
it.next();
fileNames.append(it.fileName());
}
return fileNames;
}
//---------------------------------------------------------------------------------------------------------------------
void InitLanguageList(QComboBox *combobox)
{
SCASSERT(combobox != nullptr)
combobox->clear();
const QStringList fileNames = LocalList();
bool englishUS = false;
const QString en_US = QStringLiteral("en_US");
for (auto locale : fileNames)
{
// get locale extracted by filename "valentina_de_De.qm"
locale.truncate(locale.lastIndexOf('.')); // "valentina_de_De"
locale.remove(0, locale.indexOf('_') + 1); // "de_De"
if (locale.startsWith(QLatin1String("ru")))
{
continue;
}
if (not englishUS)
{
englishUS = (en_US == locale);
}
QLocale loc = QLocale(locale);
QString lang = loc.nativeLanguageName();
// Since Qt 5.12 country names have spaces
QString country = QLocale::countryToString(loc.country()).remove(' ');
if (country == QLatin1String("Czechia"))
{
country = QLatin1String("CzechRepublic");
}
QIcon ico(QString("://flags/%1.png").arg(country));
combobox->addItem(ico, lang, locale);
}
if (combobox->count() == 0 || not englishUS)
{
// English language is internal and doens't have own *.qm file.
// Since Qt 5.12 country names have spaces
QIcon ico(QString("://flags/%1.png").arg(QLocale::countryToString(QLocale::UnitedStates).remove(' ')));
QString lang = QLocale(en_US).nativeLanguageName();
combobox->addItem(ico, lang, en_US);
}
}
} // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto QPixmapFromCache(const QString &pixmapPath) -> QPixmap auto QPixmapFromCache(const QString &pixmapPath) -> QPixmap
{ {
@ -478,58 +551,7 @@ auto UnitsToStr(const Unit &unit, const bool translate) -> QString
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void InitLanguages(QComboBox *combobox) void InitLanguages(QComboBox *combobox)
{ {
SCASSERT(combobox != nullptr) InitLanguageList(combobox);
combobox->clear();
QStringList fileNames;
QDirIterator it(VAbstractApplication::translationsPath(), QStringList("valentina_*.qm"), QDir::Files,
QDirIterator::Subdirectories);
while (it.hasNext())
{
it.next();
fileNames.append(it.fileName());
}
bool englishUS = false;
const QString en_US = QStringLiteral("en_US");
for (auto locale : fileNames)
{
// get locale extracted by filename "valentina_de_De.qm"
locale.truncate(locale.lastIndexOf('.')); // "valentina_de_De"
locale.remove(0, locale.indexOf('_') + 1); // "de_De"
if (locale.startsWith(QLatin1String("ru")))
{
continue;
}
if (not englishUS)
{
englishUS = (en_US == locale);
}
QLocale loc = QLocale(locale);
QString lang = loc.nativeLanguageName();
// Since Qt 5.12 country names have spaces
QString country = QLocale::countryToString(loc.country()).remove(' ');
if (country == QLatin1String("Czechia"))
{
country = QLatin1String("CzechRepublic");
}
QIcon ico(QString("://flags/%1.png").arg(country));
combobox->addItem(ico, lang, locale);
}
if (combobox->count() == 0 || not englishUS)
{
// English language is internal and doens't have own *.qm file.
// Since Qt 5.12 country names have spaces
QIcon ico(QString("://flags/%1.png").arg(QLocale::countryToString(QLocale::UnitedStates).remove(' ')));
QString lang = QLocale(en_US).nativeLanguageName();
combobox->addItem(ico, lang, en_US);
}
// set default translators and language checked // set default translators and language checked
qint32 index = combobox->findData(VAbstractApplication::VApp()->Settings()->GetLocale()); qint32 index = combobox->findData(VAbstractApplication::VApp()->Settings()->GetLocale());
@ -539,6 +561,21 @@ void InitLanguages(QComboBox *combobox)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void InitPieceLabelLanguages(QComboBox *combobox)
{
InitLanguageList(combobox);
combobox->addItem(QApplication::translate("InitPieceLabelLanguages", "Default"),
VCommonSettings::defaultPieceLabelLocale);
qint32 index = combobox->findData(VAbstractApplication::VApp()->Settings()->GetPieceLabelLocale());
if (index != -1)
{
combobox->setCurrentIndex(index);
}
}
const quint32 CustomSARecord::streamHeader = 0xEBFF7586; // CRC-32Q string "CustomSARecord" const quint32 CustomSARecord::streamHeader = 0xEBFF7586; // CRC-32Q string "CustomSARecord"
const quint16 CustomSARecord::classVersion = 1; const quint16 CustomSARecord::classVersion = 1;

View File

@ -699,6 +699,7 @@ Q_DECL_RELAXED_CONSTEXPR inline auto UnitConvertor(const QMarginsF &margins, con
} }
void InitLanguages(QComboBox *combobox); void InitLanguages(QComboBox *combobox);
void InitPieceLabelLanguages(QComboBox *combobox);
Q_REQUIRED_RESULT auto SupportedLocales() -> QStringList; Q_REQUIRED_RESULT auto SupportedLocales() -> QStringList;
Q_REQUIRED_RESULT auto StrippedName(const QString &fullFileName) -> QString; Q_REQUIRED_RESULT auto StrippedName(const QString &fullFileName) -> QString;

View File

@ -82,3 +82,29 @@ auto VAbstractValApplication::VApp() -> VAbstractValApplication *
{ {
return qobject_cast<VAbstractValApplication *>(QCoreApplication::instance()); return qobject_cast<VAbstractValApplication *>(QCoreApplication::instance());
} }
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractValApplication::GetPlaceholderTranslator() -> QSharedPointer<QTranslator>
{
VValentinaSettings *settings = ValentinaSettings();
QString pieceLabelLocale = settings->GetPieceLabelLocale();
if (pieceLabelLocale == VCommonSettings::defaultPieceLabelLocale)
{
pieceLabelLocale = settings->GetLocale();
}
if (pieceLabelLocale.startsWith(QLatin1String("ru")))
{
return QSharedPointer<QTranslator>(new QTranslator);
}
QSharedPointer<QTranslator> translator = QSharedPointer<QTranslator>(new QTranslator);
const QString appQmDir = VAbstractApplication::translationsPath(settings->GetLocale());
if (translator->load(QStringLiteral("valentina_") + pieceLabelLocale, appQmDir))
{
return translator;
}
return QSharedPointer<QTranslator>(new QTranslator);
}

View File

@ -126,6 +126,8 @@ class VAbstractValApplication : public VAbstractApplication
static auto VApp() -> VAbstractValApplication *; static auto VApp() -> VAbstractValApplication *;
auto GetPlaceholderTranslator() -> QSharedPointer<QTranslator>;
protected: protected:
QString m_customerName{}; QString m_customerName{};
QDate m_customerBirthDate{}; QDate m_customerBirthDate{};

View File

@ -37,6 +37,7 @@
#include <QLocale> #include <QLocale>
#include <QMarginsF> #include <QMarginsF>
#include <QMessageLogger> #include <QMessageLogger>
#include <QStringLiteral>
#include <QVariant> #include <QVariant>
#include <QtDebug> #include <QtDebug>
@ -71,6 +72,8 @@ const qreal VCommonSettings::defaultScrollingAcceleration = 1.3;
const qreal VCommonSettings::scrollingAccelerationMin = 1.0; const qreal VCommonSettings::scrollingAccelerationMin = 1.0;
const qreal VCommonSettings::scrollingAccelerationMax = 10.0; const qreal VCommonSettings::scrollingAccelerationMax = 10.0;
const QString VCommonSettings::defaultPieceLabelLocale = QStringLiteral("default");
#ifndef QPRINTENGINE_H #ifndef QPRINTENGINE_H
Q_DECLARE_METATYPE(QMarginsF) // NOLINT Q_DECLARE_METATYPE(QMarginsF) // NOLINT
#endif #endif
@ -93,6 +96,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveState,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveTime, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveTime,
(QLatin1String("configuration/autosave/time"))) // NOLINT (QLatin1String("configuration/autosave/time"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationLocale, (QLatin1String("configuration/locale"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationLocale, (QLatin1String("configuration/locale"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationPieceLabelLocale, // NOLINT
(QLatin1String("configuration/pieceLabelLocale")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPMSystemCode, (QLatin1String("configuration/pmscode"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPMSystemCode, (QLatin1String("configuration/pmscode"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationUnit, (QLatin1String("configuration/unit"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationUnit, (QLatin1String("configuration/unit"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmItemDeletion, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmItemDeletion,
@ -622,6 +627,18 @@ void VCommonSettings::SetLocale(const QString &value)
*localeCached = value; *localeCached = value;
} }
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetPieceLabelLocale() const -> QString
{
return value(*settingConfigurationPieceLabelLocale, VCommonSettings::defaultPieceLabelLocale).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPieceLabelLocale(const QString &value)
{
setValue(*settingConfigurationPieceLabelLocale, value);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetPMSystemCode() const -> QString auto VCommonSettings::GetPMSystemCode() const -> QString
{ {

View File

@ -99,6 +99,10 @@ class VCommonSettings : public QSettings
auto GetLocale() const -> QString; auto GetLocale() const -> QString;
void SetLocale(const QString &value); void SetLocale(const QString &value);
static const QString defaultPieceLabelLocale;
auto GetPieceLabelLocale() const -> QString;
void SetPieceLabelLocale(const QString &value);
auto GetPMSystemCode() const -> QString; auto GetPMSystemCode() const -> QString;
void SetPMSystemCode(const QString &value); void SetPMSystemCode(const QString &value);

View File

@ -670,6 +670,8 @@ void DialogEditLabel::InitPlaceholders()
} }
} }
QSharedPointer<QTranslator> phTr = VAbstractValApplication::VApp()->GetPlaceholderTranslator();
// Piece tags // Piece tags
m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString())); m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString()));
m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString())); m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString()));
@ -679,11 +681,13 @@ void DialogEditLabel::InitPlaceholders()
m_placeholders.insert(pl_pFoldPosition, qMakePair(tr("Piece fold position"), QString())); m_placeholders.insert(pl_pFoldPosition, qMakePair(tr("Piece fold position"), QString()));
m_placeholders.insert(pl_pName, qMakePair(tr("Piece name"), QString())); m_placeholders.insert(pl_pName, qMakePair(tr("Piece name"), QString()));
m_placeholders.insert(pl_pQuantity, qMakePair(tr("Quantity"), QString())); m_placeholders.insert(pl_pQuantity, qMakePair(tr("Quantity"), QString()));
m_placeholders.insert(pl_mFabric, qMakePair(tr("Material: Fabric"), tr("Fabric"))); m_placeholders.insert(pl_mFabric, qMakePair(tr("Material: Fabric"), phTr->translate("Placeholder", "Fabric")));
m_placeholders.insert(pl_mLining, qMakePair(tr("Material: Lining"), tr("Lining"))); m_placeholders.insert(pl_mLining, qMakePair(tr("Material: Lining"), phTr->translate("Placeholder", "Lining")));
m_placeholders.insert(pl_mInterfacing, qMakePair(tr("Material: Interfacing"), tr("Interfacing"))); m_placeholders.insert(pl_mInterfacing,
m_placeholders.insert(pl_mInterlining, qMakePair(tr("Material: Interlining"), tr("Interlining"))); qMakePair(tr("Material: Interfacing"), phTr->translate("Placeholder", "Interfacing")));
m_placeholders.insert(pl_wCut, qMakePair(tr("Word: Cut"), tr("Cut"))); m_placeholders.insert(pl_mInterlining,
qMakePair(tr("Material: Interlining"), phTr->translate("Placeholder", "Interlining")));
m_placeholders.insert(pl_wCut, qMakePair(tr("Word: Cut"), phTr->translate("Placeholder", "Cut")));
m_placeholders.insert(pl_wOnFold, qMakePair(tr("Word: on fold"), QString())); // By default should be empty m_placeholders.insert(pl_wOnFold, qMakePair(tr("Word: on fold"), QString())); // By default should be empty
} }
@ -793,7 +797,8 @@ void DialogEditLabel::SetPiece(const VPiece &piece)
m_placeholders[pl_pQuantity].second = QString::number(pieceData.GetQuantity()); m_placeholders[pl_pQuantity].second = QString::number(pieceData.GetQuantity());
if (pieceData.IsOnFold()) if (pieceData.IsOnFold())
{ {
m_placeholders[pl_wOnFold].second = tr("on fold"); QSharedPointer<QTranslator> phTr = VAbstractValApplication::VApp()->GetPlaceholderTranslator();
m_placeholders[pl_wOnFold].second = phTr->translate("Placeholder", "on fold");
} }
VContainer completeData = m_doc->GetCompleteData(); VContainer completeData = m_doc->GetCompleteData();