Gui: add preference to use selected language number formatting, fixes #6330
If not enabled (default), will defaults to C/POSIX formatting
This commit is contained in:
@@ -1920,13 +1920,11 @@ void Application::runApplication(void)
|
||||
// http://forum.freecadweb.org/viewtopic.php?f=3&t=15540
|
||||
mainApp.setAttribute(Qt::AA_DontShowIconsInMenus, false);
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
// Make sure that we use '.' as decimal point. See also
|
||||
// http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559846
|
||||
// and issue #0002891
|
||||
// http://doc.qt.io/qt-5/qcoreapplication.html#locale-settings
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
#endif
|
||||
|
||||
// check if a single or multiple instances can run
|
||||
it = cfg.find("SingleInstance");
|
||||
@@ -2072,6 +2070,13 @@ void Application::runApplication(void)
|
||||
mainApp.installEventFilter(filter);
|
||||
}
|
||||
|
||||
if (hGrp->GetBool("UseLocaleFormatting", false)) {
|
||||
Translator::instance()->setLocale(hGrp->GetASCII(("Language"), Translator::instance()->activeLanguage().c_str()));
|
||||
}
|
||||
else {
|
||||
Translator::instance()->setLocale("C");
|
||||
}
|
||||
|
||||
// set text cursor blinking state
|
||||
int blinkTime = hGrp->GetBool("EnableCursorBlinking", true) ? -1 : 0;
|
||||
qApp->setCursorFlashTime(blinkTime);
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::PrefCheckBox" name="SubstituteDecimal">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, numerical keypad decimal separator will be substituted with locale separator</string>
|
||||
@@ -105,6 +105,23 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="Gui::PrefCheckBox" name="UseLocaleFormatting">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, number formatting will be set according to selected language
|
||||
If not, C/POSIX default formatting will be used (English-like)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use selected language number format</string>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>UseLocaleFormatting</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -128,6 +128,7 @@ void DlgGeneralImp::saveSettings()
|
||||
SetASCII("AutoloadModule", startWbName.toLatin1());
|
||||
|
||||
ui->SubstituteDecimal->onSave();
|
||||
ui->UseLocaleFormatting->onSave();
|
||||
ui->RecentFiles->onSave();
|
||||
ui->EnableCursorBlinking->onSave();
|
||||
ui->SplashScreen->onSave();
|
||||
@@ -141,6 +142,8 @@ void DlgGeneralImp::saveSettings()
|
||||
hGrp->SetASCII("Language", current.constData());
|
||||
Translator::instance()->activateLanguage(current.constData());
|
||||
}
|
||||
if (ui->UseLocaleFormatting->isChecked())
|
||||
Translator::instance()->setLocale(current.constData());
|
||||
|
||||
QVariant size = ui->toolbarIconSize->itemData(ui->toolbarIconSize->currentIndex());
|
||||
int pixel = size.toInt();
|
||||
@@ -183,14 +186,15 @@ void DlgGeneralImp::loadSettings()
|
||||
ui->AutoloadModuleCombo->setCurrentIndex(ui->AutoloadModuleCombo->findData(startWbName));
|
||||
|
||||
ui->SubstituteDecimal->onRestore();
|
||||
ui->UseLocaleFormatting->onRestore();
|
||||
ui->RecentFiles->onRestore();
|
||||
ui->EnableCursorBlinking->onRestore();
|
||||
ui->SplashScreen->onRestore();
|
||||
|
||||
// search for the language files
|
||||
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
|
||||
QString langToStr = QLocale::languageToString(QLocale().language());
|
||||
QByteArray language = hGrp->GetASCII("Language", langToStr.toLatin1()).c_str();
|
||||
auto langToStr = Translator::instance()->activeLanguage();
|
||||
QByteArray language = hGrp->GetASCII("Language", langToStr.c_str()).c_str();
|
||||
|
||||
int index = 1;
|
||||
TStringMap list = Translator::instance()->supportedLocales();
|
||||
|
||||
@@ -251,6 +251,19 @@ std::string Translator::locale(const std::string& lang) const
|
||||
return loc;
|
||||
}
|
||||
|
||||
bool Translator::setLocale(const std::string& language) const
|
||||
{
|
||||
auto loc = QLocale::c(); //Defaulting to POSIX locale
|
||||
auto bcp47 = locale(language);
|
||||
if (!bcp47.empty())
|
||||
loc = QLocale(QString::fromStdString(bcp47));
|
||||
QLocale::setDefault(loc);
|
||||
#ifdef FC_DEBUG
|
||||
Base::Console().Log("Locale changed to %s => %s\n", qPrintable(loc.bcp47Name()), qPrintable(loc.name()));
|
||||
#endif
|
||||
return (loc.language() != loc.C);
|
||||
}
|
||||
|
||||
QStringList Translator::directories() const
|
||||
{
|
||||
QStringList list;
|
||||
|
||||
@@ -66,6 +66,8 @@ public:
|
||||
std::string activeLanguage() const;
|
||||
/** Returns the locale (e.g. "de") to the given language name. */
|
||||
std::string locale(const std::string&) const;
|
||||
/** Sets default Qt locale based on given language name. Returns true if matching QLocale found**/
|
||||
bool setLocale(const std::string&) const;
|
||||
/** Returns a list of supported languages. */
|
||||
TStringList supportedLanguages() const;
|
||||
/** Returns a map of supported languages/locales. */
|
||||
|
||||
Reference in New Issue
Block a user