1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-05 23:45:13 +00:00

Fix locale related oversights

This commit is contained in:
fgenesis 2012-07-11 04:50:19 +02:00
parent 459a41e1f6
commit 345ff6063b
3 changed files with 61 additions and 64 deletions

View file

@ -49,13 +49,11 @@ void UserSettings::save()
} }
xml_system.InsertEndChild(xml_debugLog); xml_system.InsertEndChild(xml_debugLog);
if (!system.isSystemLocale) { TiXmlElement xml_locale("Locale");
TiXmlElement xml_locale("Locale"); {
{ xml_locale.SetAttribute("name", system.locale);
xml_locale.SetAttribute("name", system.locale);
}
xml_system.InsertEndChild(xml_locale);
} }
xml_system.InsertEndChild(xml_locale);
} }
doc.InsertEndChild(xml_system); doc.InsertEndChild(xml_system);

View file

@ -77,9 +77,8 @@ class UserSettings
public: public:
struct System struct System
{ {
System() { debugLogOn = 0; isSystemLocale = false; } System() { debugLogOn = 0; }
int debugLogOn; int debugLogOn;
bool isSystemLocale;
std::string locale; std::string locale;
} system; } system;

View file

@ -19,9 +19,9 @@
// veeery clunky. // veeery clunky.
static std::string _CFToStdString(CFStringRef cs) static std::string _CFToStdString(CFStringRef cs)
{ {
char buf[1024]; char buf[1024];
CFStringGetCString(cs, &buf[0], 2048, kCFStringEncodingUTF8); CFStringGetCString(cs, &buf[0], 1024, kCFStringEncodingUTF8);
return &buf[0]; return &buf[0];
} }
#endif #endif
@ -34,87 +34,87 @@ void setUsedLocale(const std::string& s)
std::string localisePath(const std::string &path, const std::string &modpath /* = "" */) std::string localisePath(const std::string &path, const std::string &modpath /* = "" */)
{ {
if (s_locale.empty()) if (s_locale.empty())
return path; 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/" */ /* we first try with complete locale name, i.e "locales/en_US/" */
std::string localisedPath = modpath + "locales/" + s_locale + "/" + fname; std::string localisedPath = modpath + "locales/" + s_locale + "/" + fname;
if (exists(localisedPath.c_str())) if (exists(localisedPath.c_str()))
return localisedPath; return localisedPath;
/* ok didn't work, let's retry with only language part of locale name, i.e "locales/en/" */ /* 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('_'); 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) 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! */ /* hooray we found a file! */
if (exists(localisedPath.c_str())) if (exists(localisedPath.c_str()))
return localisedPath; return localisedPath;
/* seems like we don't have a localized version of the file available, use original path */ /* seems like we don't have a localized version of the file available, use original path */
return path; return path;
} }
std::string getSystemLocale() std::string getSystemLocale()
{ {
std::string localeStr; std::string localeStr;
#ifdef BBGE_BUILD_WINDOWS #ifdef BBGE_BUILD_WINDOWS
LCID lcid = GetThreadLocale(); LCID lcid = GetThreadLocale();
char buf[100]; char buf[100];
char ctry[100]; char ctry[100];
if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, sizeof buf) != 0) if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, sizeof buf) != 0)
{ {
localeStr = buf; localeStr = buf;
if (GetLocaleInfo(lcid, LOCALE_SISO3166CTRYNAME, ctry, sizeof ctry) != 0) if (GetLocaleInfo(lcid, LOCALE_SISO3166CTRYNAME, ctry, sizeof ctry) != 0)
{ {
localeStr += "_"; localeStr += "_";
localeStr += ctry; localeStr += ctry;
} }
} }
#elif BBGE_BUILD_MACOSX #elif BBGE_BUILD_MACOSX
CFLocaleRef locale = CFLocaleCopyCurrent(); CFLocaleRef locale = CFLocaleCopyCurrent();
CFStringRef buf; CFStringRef buf;
if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleLanguageCode)) != NULL) if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleLanguageCode)) != NULL)
{ {
localeStr = _CFToStdString(buf); localeStr = _CFToStdString(buf);
CFRelease(buf); CFRelease(buf);
if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleCountryCode)) != NULL) if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleCountryCode)) != NULL)
{ {
system.locale += "_"; localeStr += "_";
system.locale += _CFToStdString(buf); localeStr += _CFToStdString(buf);
CFRelease(buf); CFRelease(buf);
} }
} }
CFRelease(locale); CFRelease(locale);
#else #else
const char *lang = (const char *)getenv("LANG"); const char *lang = (const char *)getenv("LANG");
if (lang && *lang) if (lang && *lang)
{ {
localeStr = lang; localeStr = lang;
size_t found = system.locale.find('.'); size_t found = localeStr.find('.');
if (found != string::npos) if (found != string::npos)
localeStr.resize(found); localeStr.resize(found);
} }
#endif #endif
return localeStr; return localeStr;
} }