From 345ff6063b1b54bee97e38cf792daaa8ffcd696d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 11 Jul 2012 04:50:19 +0200 Subject: [PATCH] Fix locale related oversights --- Aquaria/UserSettings.cpp | 10 ++-- Aquaria/UserSettings.h | 3 +- BBGE/Localization.cpp | 112 +++++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 64 deletions(-) diff --git a/Aquaria/UserSettings.cpp b/Aquaria/UserSettings.cpp index 487abd7..f90af3c 100644 --- a/Aquaria/UserSettings.cpp +++ b/Aquaria/UserSettings.cpp @@ -49,13 +49,11 @@ void UserSettings::save() } xml_system.InsertEndChild(xml_debugLog); - if (!system.isSystemLocale) { - TiXmlElement xml_locale("Locale"); - { - xml_locale.SetAttribute("name", system.locale); - } - xml_system.InsertEndChild(xml_locale); + TiXmlElement xml_locale("Locale"); + { + xml_locale.SetAttribute("name", system.locale); } + xml_system.InsertEndChild(xml_locale); } doc.InsertEndChild(xml_system); diff --git a/Aquaria/UserSettings.h b/Aquaria/UserSettings.h index 6088f88..e152033 100644 --- a/Aquaria/UserSettings.h +++ b/Aquaria/UserSettings.h @@ -77,9 +77,8 @@ class UserSettings public: struct System { - System() { debugLogOn = 0; isSystemLocale = false; } + System() { debugLogOn = 0; } int debugLogOn; - bool isSystemLocale; std::string locale; } system; diff --git a/BBGE/Localization.cpp b/BBGE/Localization.cpp index 0e8e494..5558e3b 100644 --- a/BBGE/Localization.cpp +++ b/BBGE/Localization.cpp @@ -19,9 +19,9 @@ // veeery clunky. static std::string _CFToStdString(CFStringRef cs) { - char buf[1024]; - CFStringGetCString(cs, &buf[0], 2048, kCFStringEncodingUTF8); - return &buf[0]; + char buf[1024]; + CFStringGetCString(cs, &buf[0], 1024, kCFStringEncodingUTF8); + return &buf[0]; } #endif @@ -34,87 +34,87 @@ void setUsedLocale(const std::string& s) std::string localisePath(const std::string &path, const std::string &modpath /* = "" */) { - if (s_locale.empty()) - return path; + if (s_locale.empty()) + return path; - const std::string fname = path.substr(modpath.length()); + const std::string fname = path.substr(modpath.length()); - /* we first try with complete locale name, i.e "locales/en_US/" */ - std::string localisedPath = modpath + "locales/" + s_locale + "/" + fname; + /* we first try with complete locale name, i.e "locales/en_US/" */ + std::string localisedPath = modpath + "locales/" + s_locale + "/" + fname; - if (exists(localisedPath.c_str())) - return localisedPath; + if (exists(localisedPath.c_str())) + return localisedPath; - /* ok didn't work, let's retry with only language part of locale name, i.e "locales/en/" */ - const size_t found = s_locale.find('_'); + /* ok didn't work, let's retry with only language part of locale name, i.e "locales/en/" */ + const size_t found = s_locale.find('_'); - /* hmm, seems like we didn't have a full locale name anyway, use original path */ + /* hmm, seems like we didn't have a full locale name anyway, use original path */ if (found == std::string::npos) - return path; + return path; - localisedPath = modpath + "locales/" + s_locale.substr(0,found) + "/" + fname; + localisedPath = modpath + "locales/" + s_locale.substr(0,found) + "/" + fname; - /* hooray we found a file! */ - if (exists(localisedPath.c_str())) - return localisedPath; + /* hooray we found a file! */ + if (exists(localisedPath.c_str())) + return localisedPath; - /* seems like we don't have a localized version of the file available, use original path */ - return path; + /* seems like we don't have a localized version of the file available, use original path */ + return path; } std::string getSystemLocale() { - std::string localeStr; + std::string localeStr; #ifdef BBGE_BUILD_WINDOWS - LCID lcid = GetThreadLocale(); + LCID lcid = GetThreadLocale(); - char buf[100]; - char ctry[100]; + char buf[100]; + char ctry[100]; - if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, sizeof buf) != 0) - { - localeStr = buf; + if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, sizeof buf) != 0) + { + localeStr = buf; - if (GetLocaleInfo(lcid, LOCALE_SISO3166CTRYNAME, ctry, sizeof ctry) != 0) - { - localeStr += "_"; - localeStr += ctry; - } - } + if (GetLocaleInfo(lcid, LOCALE_SISO3166CTRYNAME, ctry, sizeof ctry) != 0) + { + localeStr += "_"; + localeStr += ctry; + } + } #elif BBGE_BUILD_MACOSX - CFLocaleRef locale = CFLocaleCopyCurrent(); - CFStringRef buf; + CFLocaleRef locale = CFLocaleCopyCurrent(); + CFStringRef buf; - if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleLanguageCode)) != NULL) - { - localeStr = _CFToStdString(buf); - CFRelease(buf); + if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleLanguageCode)) != NULL) + { + localeStr = _CFToStdString(buf); + CFRelease(buf); - if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleCountryCode)) != NULL) - { - system.locale += "_"; - system.locale += _CFToStdString(buf); - CFRelease(buf); - } - } + if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleCountryCode)) != NULL) + { + localeStr += "_"; + localeStr += _CFToStdString(buf); + CFRelease(buf); + } + } - CFRelease(locale); + CFRelease(locale); #else - const char *lang = (const char *)getenv("LANG"); + const char *lang = (const char *)getenv("LANG"); - if (lang && *lang) - { - localeStr = lang; + if (lang && *lang) + { + localeStr = lang; - size_t found = system.locale.find('.'); + size_t found = localeStr.find('.'); - if (found != string::npos) - localeStr.resize(found); - } + if (found != string::npos) + localeStr.resize(found); + } #endif - return localeStr; + return localeStr; }