From af961477ad11bf6ebbc40c7d349ebc6931e69c7d Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Tue, 4 Feb 2014 19:19:40 +0000 Subject: [PATCH] Further language support refactoring. --- src/backend/helpers.cpp | 19 ++++++++++++++++--- src/backend/helpers.h | 2 ++ src/gui/main.cpp | 37 +++++++++++++++---------------------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/backend/helpers.cpp b/src/backend/helpers.cpp index b0c88bca..ff3cd389 100644 --- a/src/backend/helpers.cpp +++ b/src/backend/helpers.cpp @@ -236,22 +236,27 @@ namespace boss { if (_code == g_lang_any) { _name = "None Specified"; _isoCode = ""; + _locale = "en.UTF-8"; } else if (_code == g_lang_english) { _name = "English"; _isoCode = "eng"; + _locale = "en.UTF-8"; } else if (_code == g_lang_spanish) { _name = "Español"; _isoCode = "spa"; + _locale = "es.UTF-8"; } else if (_code == g_lang_russian) { _name = "Русский"; _isoCode = "rus"; + _locale = "ru.UTF-8"; } else if (_code == g_lang_french) { _name = "Français"; _isoCode = "fra"; + _locale = "fr.UTF-8"; } } @@ -260,26 +265,31 @@ namespace boss { _name = "English"; _isoCode = "eng"; _code = g_lang_english; + _locale = "en.UTF-8"; } else if (nameOrISOCode == "Español" || nameOrISOCode == "spa") { _name = "Español"; _isoCode = "spa"; - _code = g_lang_english; + _code = g_lang_spanish; + _locale = "es.UTF-8"; } else if (nameOrISOCode == "Русский" || nameOrISOCode == "rus") { _name = "Русский"; _isoCode = "rus"; - _code = g_lang_english; + _code = g_lang_russian; + _locale = "ru.UTF-8"; } else if (nameOrISOCode == "Français" || nameOrISOCode == "fra") { _name = "Français"; _isoCode = "fra"; _code = g_lang_french; + _locale = "fr.UTF-8"; } else { - _name = "None Specified"; + _name = boost::locale::translate("None Specified"); _isoCode = ""; _code = g_lang_any; + _locale = "en.UTF-8"; } } @@ -295,6 +305,9 @@ namespace boss { return _isoCode; } + std::string Language::Locale() const { + return _locale; + } ////////////////////////////// // Version Class Functions diff --git a/src/backend/helpers.h b/src/backend/helpers.h index b188a973..728467b8 100644 --- a/src/backend/helpers.h +++ b/src/backend/helpers.h @@ -74,10 +74,12 @@ namespace boss { unsigned int Code() const; std::string Name() const; std::string ISOCode() const; + std::string Locale() const; private: unsigned int _code; std::string _isoCode; std::string _name; + std::string _locale; }; //Version class for more robust version comparisons. diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 5efea6b1..75a67dd6 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -233,27 +233,20 @@ bool BossGUI::OnInit() { //Set the locale to get encoding and language conversions working correctly. BOOST_LOG_TRIVIAL(debug) << "Initialising language settings."; //Defaults in case language string is empty or setting is missing. - string localeId = "en.UTF-8"; - wxLanguage lang = wxLANGUAGE_ENGLISH; + string localeId = boss::Language(boss::g_lang_any).Locale(); + wxLanguage wxLang = wxLANGUAGE_ENGLISH; if (_settings["Language"]) { - if (_settings["Language"].as() == "eng") { - BOOST_LOG_TRIVIAL(debug) << "Selected language: English."; - localeId = "en.UTF-8"; - lang = wxLANGUAGE_ENGLISH; - } else if (_settings["Language"].as() == "spa") { - BOOST_LOG_TRIVIAL(debug) << "Selected language: Spanish."; - localeId = "es.UTF-8"; - lang = wxLANGUAGE_SPANISH; - } else if (_settings["Language"].as() == "rus") { - BOOST_LOG_TRIVIAL(debug) << "Selected language: Russian."; - localeId = "ru.UTF-8"; - lang = wxLANGUAGE_RUSSIAN; - } - else if (_settings["Language"].as() == "fra") { - BOOST_LOG_TRIVIAL(debug) << "Selected language: French."; - localeId = "fr.UTF-8"; - lang = wxLANGUAGE_FRENCH; - } + boss::Language lang(_settings["Language"].as()); + BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lang.Name(); + localeId = lang.Locale(); + if (lang.Code() == boss::g_lang_english) + wxLang = wxLANGUAGE_ENGLISH; + else if (lang.Code() == boss::g_lang_spanish) + wxLang = wxLANGUAGE_SPANISH; + else if (lang.Code() == boss::g_lang_russian) + wxLang = wxLANGUAGE_RUSSIAN; + else if (lang.Code() == boss::g_lang_french) + wxLang = wxLANGUAGE_FRENCH; } //Boost.Locale initialisation: Specify location of language dictionaries. @@ -267,9 +260,9 @@ bool BossGUI::OnInit() { boost::filesystem::path::imbue(locale()); //wxWidgets initalisation. - if (wxLocale::IsAvailable(lang)) { + if (wxLocale::IsAvailable(wxLang)) { BOOST_LOG_TRIVIAL(trace) << "Selected language is available, setting language file paths."; - wxLoc = new wxLocale(lang); + wxLoc = new wxLocale(wxLang); wxLocale::AddCatalogLookupPathPrefix(g_path_l10n.string().c_str());