mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-15 05:59:16 +00:00
Fix locale related oversights
This commit is contained in:
parent
459a41e1f6
commit
345ff6063b
3 changed files with 61 additions and 64 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue