1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-09 16:02:47 +00:00

Multi-language patch by Henrik Holst

This commit is contained in:
fgenesis 2012-05-21 04:05:44 +02:00
commit 2278e55d0c
7 changed files with 132 additions and 18 deletions

View file

@ -33,6 +33,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <windows.h>
#endif
#ifdef BBGE_BUILD_UNIX
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
void UserSettings::save()
{
@ -53,6 +58,14 @@ void UserSettings::save()
xml_debugLog.SetAttribute("on", system.debugLogOn);
}
xml_system.InsertEndChild(xml_debugLog);
if (!system.isSystemLocale) {
TiXmlElement xml_locale("Locale");
{
xml_locale.SetAttribute("name", system.locale);
}
xml_system.InsertEndChild(xml_locale);
}
}
doc.InsertEndChild(xml_system);
@ -347,6 +360,12 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
{
xml_debugLog->Attribute("on", &system.debugLogOn);
}
TiXmlElement *xml_locale = xml_system->FirstChildElement("Locale");
if (xml_locale)
{
system.locale = xml_locale->Attribute("name");
}
}
TiXmlElement *xml_audio = doc.FirstChildElement("Audio");
@ -485,6 +504,11 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
readIntAtt(xml_data, "lastSelectedMod", &data.lastSelectedMod);
}
if (system.locale.empty())
getSystemLocale();
else
debugLog("use user config locale: " + system.locale);
//clearInputCodeMap();
if (doApply)
@ -526,3 +550,66 @@ void UserSettings::apply()
#endif
}
std::string UserSettings::localisePath(const std::string &path, const std::string &modpath)
{
if (system.locale.empty())
return path;
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/" + system.locale + "/" + fname;
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 = system.locale.find('_');
/* hmm, seems like we didn't have a full locale name anyway, use original path */
if (found == string::npos)
return path;
localisedPath = modpath + "locales/" + system.locale.substr(0,found) + "/" + fname;
/* 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;
}
void UserSettings::getSystemLocale()
{
system.isSystemLocale = true;
#ifdef BBGE_BUILD_WINDOWS
LCID lcid = GetThreadLocale();
char buf[100];
char ctry[100];
if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, sizeof buf) != 0)
{
system.locale = buf;
if (GetLocaleInfo(lcid, LOCALE_SISO3166CTRYNAME, ctry, sizeof ctry) != 0)
{
system.locale += "_";
system.locale += ctry;
}
}
#else
system.locale = getenv("LANG");
size_t found = system.locale.find('.');
if (found != string::npos)
system.locale.resize(found);
#endif
if (system.locale.empty())
debugLog("could not establish system locale");
else
debugLog("use system locale: " + system.locale);
}