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.
- New notch type - Check Notch.
- Control a notch width and angle with formulas.
- Independent translation for piece labels.
# Valentina 0.7.52 September 12, 2022
- 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,
[this]() { m_langChanged = true; });
InitPieceLabelLanguages(ui->comboBoxPieceLbelLanguage);
connect(ui->comboBoxPieceLbelLanguage, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this]() { m_pieceLabelLangChanged = true; });
//-------------------- Decimal separator setup
ui->osOptionCheck->setChecked(VAbstractValApplication::VApp()->ValentinaSettings()->GetOsSeparator());
@ -203,6 +207,13 @@ auto PreferencesConfigurationPage::Apply() -> QStringList
settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->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)
{
const auto locale = qvariant_cast<QString>(ui->langCombo->currentData());
@ -299,4 +310,13 @@ void PreferencesConfigurationPage::RetranslateUi()
ui->systemCombo->blockSignals(false);
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
Ui::PreferencesConfigurationPage *ui;
bool m_langChanged{false};
bool m_pieceLabelLangChanged{false};
bool m_systemChanged{false};
bool m_unitChanged{false};
bool m_labelLangChanged{false};

View File

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

View File

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

View File

@ -65,6 +65,79 @@
#include "../vmisc/diagnostic.h"
#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
{
@ -478,58 +551,7 @@ auto UnitsToStr(const Unit &unit, const bool translate) -> QString
//---------------------------------------------------------------------------------------------------------------------
void InitLanguages(QComboBox *combobox)
{
SCASSERT(combobox != nullptr)
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);
}
InitLanguageList(combobox);
// set default translators and language checked
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 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 InitPieceLabelLanguages(QComboBox *combobox);
Q_REQUIRED_RESULT auto SupportedLocales() -> QStringList;
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());
}
//---------------------------------------------------------------------------------------------------------------------
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 *;
auto GetPlaceholderTranslator() -> QSharedPointer<QTranslator>;
protected:
QString m_customerName{};
QDate m_customerBirthDate{};

View File

@ -37,6 +37,7 @@
#include <QLocale>
#include <QMarginsF>
#include <QMessageLogger>
#include <QStringLiteral>
#include <QVariant>
#include <QtDebug>
@ -71,6 +72,8 @@ const qreal VCommonSettings::defaultScrollingAcceleration = 1.3;
const qreal VCommonSettings::scrollingAccelerationMin = 1.0;
const qreal VCommonSettings::scrollingAccelerationMax = 10.0;
const QString VCommonSettings::defaultPieceLabelLocale = QStringLiteral("default");
#ifndef QPRINTENGINE_H
Q_DECLARE_METATYPE(QMarginsF) // NOLINT
#endif
@ -93,6 +96,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveState,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationAutosaveTime,
(QLatin1String("configuration/autosave/time"))) // 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, settingConfigurationUnit, (QLatin1String("configuration/unit"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmItemDeletion,
@ -622,6 +627,18 @@ void VCommonSettings::SetLocale(const QString &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
{

View File

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

View File

@ -670,6 +670,8 @@ void DialogEditLabel::InitPlaceholders()
}
}
QSharedPointer<QTranslator> phTr = VAbstractValApplication::VApp()->GetPlaceholderTranslator();
// Piece tags
m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString()));
m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString()));
@ -679,12 +681,14 @@ void DialogEditLabel::InitPlaceholders()
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_pQuantity, qMakePair(tr("Quantity"), QString()));
m_placeholders.insert(pl_mFabric, qMakePair(tr("Material: Fabric"), tr("Fabric")));
m_placeholders.insert(pl_mLining, qMakePair(tr("Material: Lining"), tr("Lining")));
m_placeholders.insert(pl_mInterfacing, qMakePair(tr("Material: Interfacing"), tr("Interfacing")));
m_placeholders.insert(pl_mInterlining, qMakePair(tr("Material: Interlining"), tr("Interlining")));
m_placeholders.insert(pl_wCut, qMakePair(tr("Word: Cut"), tr("Cut")));
m_placeholders.insert(pl_wOnFold, qMakePair(tr("Word: on fold"), QString()));// By default should be empty
m_placeholders.insert(pl_mFabric, qMakePair(tr("Material: Fabric"), phTr->translate("Placeholder", "Fabric")));
m_placeholders.insert(pl_mLining, qMakePair(tr("Material: Lining"), phTr->translate("Placeholder", "Lining")));
m_placeholders.insert(pl_mInterfacing,
qMakePair(tr("Material: Interfacing"), phTr->translate("Placeholder", "Interfacing")));
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
}
//---------------------------------------------------------------------------------------------------------------------
@ -793,7 +797,8 @@ void DialogEditLabel::SetPiece(const VPiece &piece)
m_placeholders[pl_pQuantity].second = QString::number(pieceData.GetQuantity());
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();