diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 06e89cc346..cf95615912 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -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); diff --git a/src/Gui/DlgGeneral.ui b/src/Gui/DlgGeneral.ui index 87429f066b..68a3caa5b8 100644 --- a/src/Gui/DlgGeneral.ui +++ b/src/Gui/DlgGeneral.ui @@ -89,7 +89,7 @@ - + If enabled, numerical keypad decimal separator will be substituted with locale separator @@ -105,6 +105,23 @@ + + + + If enabled, number formatting will be set according to selected language +If not, C/POSIX default formatting will be used (English-like) + + + Use selected language number format + + + UseLocaleFormatting + + + General + + + diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index 4213464a3c..9903a81587 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -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(); diff --git a/src/Gui/Language/Translator.cpp b/src/Gui/Language/Translator.cpp index ca98a1d523..98cbf06f5a 100644 --- a/src/Gui/Language/Translator.cpp +++ b/src/Gui/Language/Translator.cpp @@ -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; diff --git a/src/Gui/Language/Translator.h b/src/Gui/Language/Translator.h index c701dc7a7b..572dddae32 100644 --- a/src/Gui/Language/Translator.h +++ b/src/Gui/Language/Translator.h @@ -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. */