diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp
index c5cb6aebd5..2fb742be05 100644
--- a/src/Gui/Application.cpp
+++ b/src/Gui/Application.cpp
@@ -2072,10 +2072,12 @@ void Application::runApplication(void)
mainApp.installEventFilter(filter);
}
- if (hGrp->GetBool("UseLocaleFormatting", false)) {
- Translator::instance()->setLocale(hGrp->GetASCII(("Language"), Translator::instance()->activeLanguage().c_str()));
+ // For values different to 1 and 2 use the OS locale settings
+ auto localeFormat = hGrp->GetInt("UseLocaleFormatting", 0);
+ if (localeFormat == 1) {
+ Translator::instance()->setLocale(hGrp->GetASCII("Language", Translator::instance()->activeLanguage().c_str()));
}
- else {
+ else if (localeFormat == 2) {
Translator::instance()->setLocale("C");
}
diff --git a/src/Gui/DlgGeneral.ui b/src/Gui/DlgGeneral.ui
index 68a3caa5b8..ed5e2b7b31 100644
--- a/src/Gui/DlgGeneral.ui
+++ b/src/Gui/DlgGeneral.ui
@@ -106,20 +106,28 @@
-
-
-
- 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
+
-
+
+ Number format of operating system
+
+
+ -
+
+ Use selected language number format
+
+
+ -
+
+ C/POSIX number format
+
+
@@ -174,24 +182,24 @@ If not, C/POSIX default formatting will be used (English-like)
true
-
- 30
-
100
+
+ 30
+
true
false
-
- 16
-
24
+
+ 16
+
Name
@@ -601,6 +609,11 @@ after FreeCAD launches
QCheckBox
+
+ Gui::PrefComboBox
+ QComboBox
+
+
Languages
diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp
index 9903a81587..d9e2e65bf4 100644
--- a/src/Gui/DlgGeneralImp.cpp
+++ b/src/Gui/DlgGeneralImp.cpp
@@ -53,6 +53,7 @@ using namespace Gui::Dialog;
*/
DlgGeneralImp::DlgGeneralImp( QWidget* parent )
: PreferencePage(parent)
+ , localeIndex(0)
, ui(new Ui_DlgGeneral)
{
ui->setupUi(this);
@@ -119,6 +120,38 @@ void DlgGeneralImp::setRecentFileSize()
}
}
+void DlgGeneralImp::setLanguage()
+{
+ ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
+ QString lang = QLocale::languageToString(QLocale().language());
+ QByteArray language = hGrp->GetASCII("Language", (const char*)lang.toLatin1()).c_str();
+ QByteArray current = ui->Languages->itemData(ui->Languages->currentIndex()).toByteArray();
+ if (current != language) {
+ hGrp->SetASCII("Language", current.constData());
+ Translator::instance()->activateLanguage(current.constData());
+ }
+}
+
+void DlgGeneralImp::setNumberLocale()
+{
+ int localeFormat = ui->UseLocaleFormatting->currentIndex();
+
+ // Only make the change if locale setting has changed
+ if (localeIndex == localeFormat)
+ return;
+
+ if (localeFormat == 0) {
+ Translator::instance()->setSystemLocale();
+ }
+ else if (localeFormat == 1) {
+ QByteArray current = ui->Languages->itemData(ui->Languages->currentIndex()).toByteArray();
+ Translator::instance()->setLocale(current.constData());
+ }
+ else if (localeFormat == 2) {
+ Translator::instance()->setLocale("C");
+ }
+}
+
void DlgGeneralImp::saveSettings()
{
int index = ui->AutoloadModuleCombo->currentIndex();
@@ -134,17 +167,10 @@ void DlgGeneralImp::saveSettings()
ui->SplashScreen->onSave();
setRecentFileSize();
- ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
- QString lang = QLocale::languageToString(QLocale().language());
- QByteArray language = hGrp->GetASCII("Language", (const char*)lang.toLatin1()).c_str();
- QByteArray current = ui->Languages->itemData(ui->Languages->currentIndex()).toByteArray();
- if (current != language) {
- hGrp->SetASCII("Language", current.constData());
- Translator::instance()->activateLanguage(current.constData());
- }
- if (ui->UseLocaleFormatting->isChecked())
- Translator::instance()->setLocale(current.constData());
+ setLanguage();
+ setNumberLocale();
+ ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
QVariant size = ui->toolbarIconSize->itemData(ui->toolbarIconSize->currentIndex());
int pixel = size.toInt();
hGrp->SetInt("ToolbarIconSize", pixel);
@@ -196,6 +222,8 @@ void DlgGeneralImp::loadSettings()
auto langToStr = Translator::instance()->activeLanguage();
QByteArray language = hGrp->GetASCII("Language", langToStr.c_str()).c_str();
+ localeIndex = ui->UseLocaleFormatting->currentIndex();
+
int index = 1;
TStringMap list = Translator::instance()->supportedLocales();
ui->Languages->clear();
@@ -303,7 +331,9 @@ void DlgGeneralImp::loadSettings()
void DlgGeneralImp::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
+ int index = ui->UseLocaleFormatting->currentIndex();
ui->retranslateUi(this);
+ ui->UseLocaleFormatting->setCurrentIndex(index);
}
else {
QWidget::changeEvent(e);
diff --git a/src/Gui/DlgGeneralImp.h b/src/Gui/DlgGeneralImp.h
index 0db19ec8ed..6cfa09c918 100644
--- a/src/Gui/DlgGeneralImp.h
+++ b/src/Gui/DlgGeneralImp.h
@@ -64,8 +64,11 @@ private:
void setRecentFileSize();
void saveAsNewPreferencePack();
void revertToSavedConfig();
+ void setLanguage();
+ void setNumberLocale();
private:
+ int localeIndex;
std::unique_ptr ui;
std::unique_ptr newPreferencePackDialog;
std::unique_ptr preferencePackManagementDialog;
diff --git a/src/Gui/Language/Translator.cpp b/src/Gui/Language/Translator.cpp
index a5e18fde07..eaa4148e6e 100644
--- a/src/Gui/Language/Translator.cpp
+++ b/src/Gui/Language/Translator.cpp
@@ -258,16 +258,28 @@ bool Translator::setLocale(const std::string& language) const
if (!bcp47.empty())
loc = QLocale(QString::fromStdString(bcp47));
QLocale::setDefault(loc);
- // Need to manually send the event so locale change is fully took into account on widgets
- auto ev = QEvent(QEvent::LocaleChange);
- qApp->sendEvent(qApp, &ev);
+ updateLocaleChange();
#ifdef FC_DEBUG
Base::Console().Log("Locale changed to %s => %s\n", qPrintable(loc.bcp47Name()), qPrintable(loc.name()));
#endif
+
return (loc.language() != loc.C);
}
+void Translator::setSystemLocale() const
+{
+ QLocale::setDefault(QLocale::system());
+ updateLocaleChange();
+}
+
+void Translator::updateLocaleChange() const
+{
+ // Need to manually send the event so locale change is fully took into account on widgets
+ auto ev = QEvent(QEvent::LocaleChange);
+ qApp->sendEvent(qApp, &ev);
+}
+
QStringList Translator::directories() const
{
QStringList list;
diff --git a/src/Gui/Language/Translator.h b/src/Gui/Language/Translator.h
index 572dddae32..982fd15ce0 100644
--- a/src/Gui/Language/Translator.h
+++ b/src/Gui/Language/Translator.h
@@ -68,6 +68,7 @@ public:
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;
+ void setSystemLocale() const;
/** Returns a list of supported languages. */
TStringList supportedLanguages() const;
/** Returns a map of supported languages/locales. */
@@ -81,6 +82,7 @@ private:
void removeTranslators();
QStringList directories() const;
void installQMFiles(const QDir& dir, const char* locale);
+ void updateLocaleChange() const;
private:
static Translator* _pcSingleton;