[TD]translate line names at time of use

This commit is contained in:
wandererfan
2024-07-15 20:01:05 -04:00
committed by WandererFan
parent 4d29b50ef5
commit 16f25ec4a2
3 changed files with 37 additions and 1 deletions

View File

@@ -22,11 +22,36 @@
#include "PreCompiled.h"
#include "Preferences.h"
#include "LineNameEnum.h"
namespace TechDraw {
// these strings have to be kept in order according to Preferences::lineStandard()
std::vector<std::string> LineName::ContextStrings{
"ANSILineTypeEnum",
"ASMELineTypeEnum",
"ISOLineTypeEnum" };
std::string LineName::translationContext(size_t iStandard)
{
if (iStandard < ContextStrings.size() &&
iStandard > 0) {
return ContextStrings[iStandard];
}
return {};
}
std::string LineName::currentTranslationContext()
{
return translationContext(Preferences::lineStandard());
}
//! line numbers begin at 1, not 0
const int ISOLineName::ISOLineNameCount = 15;

View File

@@ -33,8 +33,18 @@
namespace TechDraw
{
//! common definitions for line numbers, names and lineicon names
class TechDrawExport LineName {
public:
static std::string translationContext(size_t iStandard);
static std::string currentTranslationContext();
static std::vector<std::string> ContextStrings;
};
class TechDrawExport ISOLineName {
Q_DECLARE_TR_FUNCTIONS(TechDraw::ISOLineName)

View File

@@ -180,9 +180,10 @@ void DrawGuiUtil::loadLineStyleChoices(QComboBox* combo, LineGenerator* generato
choices = LineGenerator::getLineDescriptions();
}
auto translationContext = LineName::currentTranslationContext();
int itemNumber {0};
for (auto& entry : choices) {
QString qentry = Base::Tools::fromStdString(entry);
QString qentry = QCoreApplication::translate(translationContext.c_str(), entry.c_str());
combo->addItem(qentry);
if (generator) {
combo->setItemIcon(itemNumber, iconForLine(itemNumber + 1, generator));