mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-08-07 06:40:22 +00:00
Multi-language patch by Henrik Holst
This commit is contained in:
parent
0fbd5d81ae
commit
2278e55d0c
7 changed files with 132 additions and 18 deletions
|
@ -3209,15 +3209,20 @@ void Continuity::reset()
|
||||||
ingredientData.clear();
|
ingredientData.clear();
|
||||||
recipes.clear();
|
recipes.clear();
|
||||||
|
|
||||||
|
std::string fname;
|
||||||
|
|
||||||
if(dsq->mod.isActive())
|
if(dsq->mod.isActive())
|
||||||
{
|
{
|
||||||
//load mod ingredients
|
//load mod ingredients
|
||||||
loadIngredientData(dsq->mod.getPath() + "ingredients.txt");
|
fname = dsq->user.localisePath(dsq->mod.getPath() + "ingredients.txt", dsq->mod.getPath());
|
||||||
|
loadIngredientData(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
//load ingredients for the main game
|
//load ingredients for the main game
|
||||||
if(ingredientData.empty() && recipes.empty())
|
if(ingredientData.empty() && recipes.empty()) {
|
||||||
loadIngredientData("data/ingredients.txt");
|
fname = dsq->user.localisePath("data/ingredients.txt");
|
||||||
|
loadIngredientData(fname);
|
||||||
|
}
|
||||||
|
|
||||||
loadPetData();
|
loadPetData();
|
||||||
|
|
||||||
|
|
|
@ -8010,21 +8010,30 @@ void Game::toggleHelpScreen(bool on, const std::string &label)
|
||||||
|
|
||||||
// These say "Mac" but we use them on Linux, too.
|
// These say "Mac" but we use them on Linux, too.
|
||||||
#if defined(BBGE_BUILD_UNIX)
|
#if defined(BBGE_BUILD_UNIX)
|
||||||
appendFileToString(data, "data/help_header_mac.txt");
|
std::string fname = dsq->user.localisePath("data/help_header_mac.txt");
|
||||||
|
appendFileToString(data, fname);
|
||||||
#else
|
#else
|
||||||
appendFileToString(data, "data/help_header.txt");
|
std::string fname = dsq->user.localisePath("data/help_header.txt");
|
||||||
|
appendFileToString(data, fname);
|
||||||
#endif
|
#endif
|
||||||
if (dsq->continuity.hasSong(SONG_BIND))
|
if (dsq->continuity.hasSong(SONG_BIND)) {
|
||||||
appendFileToString(data, "data/help_bindsong.txt");
|
fname = dsq->user.localisePath("data/help_bindsong.txt");
|
||||||
if (dsq->continuity.hasSong(SONG_ENERGYFORM))
|
appendFileToString(data, fname);
|
||||||
appendFileToString(data, "data/help_energyform.txt");
|
}
|
||||||
appendFileToString(data, "data/help_start.txt");
|
if (dsq->continuity.hasSong(SONG_ENERGYFORM)) {
|
||||||
|
fname = dsq->user.localisePath("data/help_energyform.txt");
|
||||||
|
appendFileToString(data, fname);
|
||||||
|
}
|
||||||
|
fname = dsq->user.localisePath("data/help_start.txt");
|
||||||
|
appendFileToString(data, fname);
|
||||||
|
|
||||||
// These say "Mac" but we use them on Linux, too.
|
// These say "Mac" but we use them on Linux, too.
|
||||||
#if defined(BBGE_BUILD_UNIX)
|
#if defined(BBGE_BUILD_UNIX)
|
||||||
appendFileToString(data, "data/help_end_mac.txt");
|
fname = dsq->user.localisePath("data/help_end_mac.txt");
|
||||||
|
appendFileToString(data, fname);
|
||||||
#else
|
#else
|
||||||
appendFileToString(data, "data/help_end.txt");
|
fname = dsq->user.localisePath("data/help_end.txt");
|
||||||
|
appendFileToString(data, fname);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// !!! FIXME: this is such a hack.
|
// !!! FIXME: this is such a hack.
|
||||||
|
|
|
@ -174,7 +174,8 @@ void StatsAndAchievements::RunFrame()
|
||||||
FILE *io = NULL;
|
FILE *io = NULL;
|
||||||
|
|
||||||
// Get generic achievement data...
|
// Get generic achievement data...
|
||||||
io = fopen("data/achievements.txt", "r");
|
std::string fname = dsq->user.localisePath("data/achievements.txt");
|
||||||
|
io = fopen(fname.c_str(), "r");
|
||||||
char line[1024];
|
char line[1024];
|
||||||
for (size_t i = 0; i < max_achievements; i++)
|
for (size_t i = 0; i < max_achievements; i++)
|
||||||
{
|
{
|
||||||
|
@ -209,7 +210,7 @@ void StatsAndAchievements::RunFrame()
|
||||||
|
|
||||||
unsigned char *buf = new unsigned char[max_achievements];
|
unsigned char *buf = new unsigned char[max_achievements];
|
||||||
size_t br = 0;
|
size_t br = 0;
|
||||||
const std::string fname(core->getUserDataFolder() + "/achievements.bin");
|
fname = (core->getUserDataFolder() + "/achievements.bin");
|
||||||
io = fopen(fname.c_str(), "rb");
|
io = fopen(fname.c_str(), "rb");
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
statsValid = true; // nothing to report.
|
statsValid = true; // nothing to report.
|
||||||
|
|
|
@ -28,9 +28,13 @@ void StringBank::load()
|
||||||
{
|
{
|
||||||
stringMap.clear();
|
stringMap.clear();
|
||||||
|
|
||||||
_load("data/stringbank.txt");
|
std::string fname = dsq->user.localisePath("data/stringbank.txt");
|
||||||
if (dsq->mod.isActive())
|
_load(fname);
|
||||||
_load(dsq->mod.getPath() + "stringbank.txt");
|
|
||||||
|
if (dsq->mod.isActive()) {
|
||||||
|
fname = dsq->user.localisePath(dsq->mod.getPath() + "stringbank.txt", dsq->mod.getPath());
|
||||||
|
_load(fname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBank::_load(const std::string &file)
|
void StringBank::_load(const std::string &file)
|
||||||
|
|
|
@ -46,6 +46,7 @@ void SubtitlePlayer::go(const std::string &subs)
|
||||||
if (dsq->mod.isActive())
|
if (dsq->mod.isActive())
|
||||||
{
|
{
|
||||||
f = dsq->mod.getPath() + "audio/" + subs + ".txt";
|
f = dsq->mod.getPath() + "audio/" + subs + ".txt";
|
||||||
|
f = dsq->user.localisePath(f, dsq->mod.getPath());
|
||||||
f = core->adjustFilenameCase(f);
|
f = core->adjustFilenameCase(f);
|
||||||
if (exists(f))
|
if (exists(f))
|
||||||
checkAfter = false;
|
checkAfter = false;
|
||||||
|
@ -54,6 +55,7 @@ void SubtitlePlayer::go(const std::string &subs)
|
||||||
if (checkAfter)
|
if (checkAfter)
|
||||||
{
|
{
|
||||||
f = "scripts/vox/" + subs + ".txt";
|
f = "scripts/vox/" + subs + ".txt";
|
||||||
|
f = dsq->user.localisePath(f);
|
||||||
f = core->adjustFilenameCase(f);
|
f = core->adjustFilenameCase(f);
|
||||||
if (!exists(f))
|
if (!exists(f))
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BBGE_BUILD_UNIX
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void UserSettings::save()
|
void UserSettings::save()
|
||||||
{
|
{
|
||||||
|
@ -53,6 +58,14 @@ void UserSettings::save()
|
||||||
xml_debugLog.SetAttribute("on", system.debugLogOn);
|
xml_debugLog.SetAttribute("on", system.debugLogOn);
|
||||||
}
|
}
|
||||||
xml_system.InsertEndChild(xml_debugLog);
|
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);
|
doc.InsertEndChild(xml_system);
|
||||||
|
|
||||||
|
@ -347,6 +360,12 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
|
||||||
{
|
{
|
||||||
xml_debugLog->Attribute("on", &system.debugLogOn);
|
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");
|
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);
|
readIntAtt(xml_data, "lastSelectedMod", &data.lastSelectedMod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (system.locale.empty())
|
||||||
|
getSystemLocale();
|
||||||
|
else
|
||||||
|
debugLog("use user config locale: " + system.locale);
|
||||||
|
|
||||||
//clearInputCodeMap();
|
//clearInputCodeMap();
|
||||||
|
|
||||||
if (doApply)
|
if (doApply)
|
||||||
|
@ -526,3 +550,66 @@ void UserSettings::apply()
|
||||||
#endif
|
#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);
|
||||||
|
}
|
||||||
|
|
|
@ -77,8 +77,10 @@ class UserSettings
|
||||||
public:
|
public:
|
||||||
struct System
|
struct System
|
||||||
{
|
{
|
||||||
System() { debugLogOn = 0; }
|
System() { debugLogOn = 0; isSystemLocale = false; }
|
||||||
int debugLogOn;
|
int debugLogOn;
|
||||||
|
bool isSystemLocale;
|
||||||
|
std::string locale;
|
||||||
} system;
|
} system;
|
||||||
|
|
||||||
struct Audio
|
struct Audio
|
||||||
|
@ -175,4 +177,8 @@ public:
|
||||||
void load(bool doApply=true, const std::string &overrideFile="");
|
void load(bool doApply=true, const std::string &overrideFile="");
|
||||||
void save();
|
void save();
|
||||||
void apply();
|
void apply();
|
||||||
|
std::string localisePath(const std::string &path, const std::string &modpath="");
|
||||||
|
|
||||||
|
private:
|
||||||
|
void getSystemLocale();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue