Further language support refactoring.

This commit is contained in:
WrinklyNinja
2014-02-04 19:19:40 +00:00
parent ebb2606de6
commit af961477ad
3 changed files with 33 additions and 25 deletions
+16 -3
View File
@@ -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
+2
View File
@@ -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.
+15 -22
View File
@@ -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<string>() == "eng") {
BOOST_LOG_TRIVIAL(debug) << "Selected language: English.";
localeId = "en.UTF-8";
lang = wxLANGUAGE_ENGLISH;
} else if (_settings["Language"].as<string>() == "spa") {
BOOST_LOG_TRIVIAL(debug) << "Selected language: Spanish.";
localeId = "es.UTF-8";
lang = wxLANGUAGE_SPANISH;
} else if (_settings["Language"].as<string>() == "rus") {
BOOST_LOG_TRIVIAL(debug) << "Selected language: Russian.";
localeId = "ru.UTF-8";
lang = wxLANGUAGE_RUSSIAN;
}
else if (_settings["Language"].as<string>() == "fra") {
BOOST_LOG_TRIVIAL(debug) << "Selected language: French.";
localeId = "fr.UTF-8";
lang = wxLANGUAGE_FRENCH;
}
boss::Language lang(_settings["Language"].as<string>());
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());