From debc454ca545171912f4f26444529183d3b80520 Mon Sep 17 00:00:00 2001 From: Ari Breitkreuz Date: Wed, 26 Aug 2020 21:48:14 +0200 Subject: [PATCH] Load preferred language from settings --- src/control/Control.cpp | 4 ++++ src/control/Control.h | 5 +++++ src/control/settings/Settings.cpp | 2 ++ src/control/settings/Settings.h | 16 +++++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/control/Control.cpp b/src/control/Control.cpp index 7b81b069..90e2e922 100644 --- a/src/control/Control.cpp +++ b/src/control/Control.cpp @@ -88,6 +88,8 @@ Control::Control(GladeSearchpath* gladeSearchPath) { this->settings = new Settings(std::move(name)); this->settings->load(); + this->applyPreferredLanguage(); + TextView::setDpi(settings->getDisplayDpi()); this->pageTypes = new PageTypeHandler(gladeSearchPath); @@ -2458,6 +2460,8 @@ void Control::closeDocument() { this->undoRedoChanged(); } +void Control::applyPreferredLanguage() { setenv("LANGUAGE", this->settings->getPreferredLocale().c_str(), 1); } + auto Control::askToReplace(fs::path const& filepath) const -> bool { if (fs::exists(filepath)) { string msg = FS(FORMAT_STR("The file {1} already exists! Do you want to replace it?") % diff --git a/src/control/Control.h b/src/control/Control.h index f6b59611..0e34fdd4 100644 --- a/src/control/Control.h +++ b/src/control/Control.h @@ -326,6 +326,11 @@ private: */ void closeDocument(); + /** + * Applies the preferred language to the UI + */ + void applyPreferredLanguage(); + RecentManager* recent; UndoRedoHandler* undoRedo; ZoomControl* zoom; diff --git a/src/control/settings/Settings.cpp b/src/control/settings/Settings.cpp index 17bcec02..ade24aaf 100644 --- a/src/control/settings/Settings.cpp +++ b/src/control/settings/Settings.cpp @@ -845,6 +845,8 @@ void Settings::save() { WRITE_BOOL_PROP(inputSystemTPCButton); WRITE_BOOL_PROP(inputSystemDrawOutsideWindow); + WRITE_STRING_PROP(preferredLocale); + WRITE_BOOL_PROP(latexSettings.autoCheckDependencies); // Inline WRITE_STRING_PROP(latexSettings.globalTemplatePath) since it // breaks on Windows due to the native character representation being diff --git a/src/control/settings/Settings.h b/src/control/settings/Settings.h index 8868ae24..6f38a96e 100644 --- a/src/control/settings/Settings.h +++ b/src/control/settings/Settings.h @@ -431,7 +431,6 @@ public: */ bool getTrySelectOnStrokeFiltered() const; - /** * Set snap recognized shapes enabled */ @@ -452,6 +451,16 @@ public: */ bool getRestoreLineWidthEnabled() const; + /** + * Set the preferred locale + */ + void setPreferredLocale(std::string const& locale) const; + + /** + * Get the preferred locale + */ + std::string getPreferredLocale() const { + return "de_DE.UTF-8"; } public: // Custom settings @@ -882,4 +891,9 @@ private: * "Transaction" running, do not save until the end is reached */ bool inTransaction{}; + + /** The preferred locale as its language code + * e.g. "en_US" + */ + std::string preferredLocale; };