- all languages now define their sio639-1 code and the commandline option can take it now:

--use-language=en
This commit is contained in:
Mark Vejvoda 2011-11-19 03:33:01 +00:00
parent cd6b961a3b
commit 5bb270fe41
3 changed files with 60 additions and 7 deletions

View File

@ -46,8 +46,11 @@ Lang &Lang::getInstance() {
return lang;
}
void Lang::loadStrings(const string &uselanguage, bool loadFonts,
void Lang::loadStrings(string uselanguage, bool loadFonts,
bool fallbackToDefault) {
if(uselanguage.length() == 2) {
uselanguage = getLanguageFile(uselanguage);
}
bool languageChanged = (uselanguage != this->language);
this->language= uselanguage;
loadStrings(uselanguage, strings, true, fallbackToDefault);
@ -163,7 +166,7 @@ void Lang::loadStrings(const string &uselanguage, bool loadFonts,
}
}
void Lang::loadStrings(const string &uselanguage, Properties &properties, bool fileMustExist,
void Lang::loadStrings(string uselanguage, Properties &properties, bool fileMustExist,
bool fallbackToDefault) {
properties.clear();
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
@ -187,7 +190,7 @@ bool Lang::isUTF8Language() const {
return is_utf8_language;
}
void Lang::loadScenarioStrings(const string &scenarioDir, const string &scenarioName){
void Lang::loadScenarioStrings(string scenarioDir, string scenarioName){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scenarioDir = [%s] scenarioName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioDir.c_str(),scenarioName.c_str());
string currentPath = scenarioDir;
@ -302,4 +305,51 @@ string Lang::getScenarioString(const string &s) {
}
}
bool Lang::fileMatchesISO630Code(string uselanguage, string testLanguageFile) {
bool result = false;
Properties stringsTest;
stringsTest.load(testLanguageFile);
try {
string iso639 = stringsTest.getString("ISO639-1");
if(iso639 == uselanguage) {
result = true;
}
}
catch(exception &ex) {
}
return result;
}
string Lang::getLanguageFile(string uselanguage) {
bool foundMatch = false;
string result = uselanguage;
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
vector<string> langResults;
string userDataPath = getGameCustomCoreDataPath(data_path, "");
findAll(userDataPath + "data/lang/*.lng", langResults, true, false);
for(unsigned int i = 0; i < langResults.size() && foundMatch == false ; ++i) {
string testLanguageFile = userDataPath + "data/lang/" + langResults[i] + ".lng";
foundMatch = fileMatchesISO630Code(uselanguage, testLanguageFile);
if(foundMatch == true) {
result = langResults[i];
}
}
if(foundMatch == false) {
langResults.clear();
findAll(data_path + "data/lang/*.lng", langResults, true);
for(unsigned int i = 0; i < langResults.size() && foundMatch == false ; ++i) {
string testLanguageFile = data_path + "data/lang/" + langResults[i] + ".lng";
foundMatch = fileMatchesISO630Code(uselanguage, testLanguageFile);
if(foundMatch == true) {
result = langResults[i];
}
}
}
return result;
}
}}//end namespace

View File

@ -37,13 +37,15 @@ private:
private:
Lang();
void loadStrings(const string &language, Properties &properties, bool fileMustExist,bool fallbackToDefault=false);
void loadStrings(string language, Properties &properties, bool fileMustExist,bool fallbackToDefault=false);
string getLanguageFile(string uselanguage);
bool fileMatchesISO630Code(string uselanguage, string testLanguageFile);
public:
static Lang &getInstance();
void loadStrings(const string &uselanguage, bool loadFonts=true, bool fallbackToDefault=false);
void loadScenarioStrings(const string &scenarioDir, const string &scenarioName);
void loadStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false);
void loadScenarioStrings(string scenarioDir, string scenarioName);
string get(const string &s,string uselanguage="", bool fallbackToDefault=false);
bool hasString(const string &s, string uselanguage="", bool fallbackToDefault=false);

View File

@ -182,8 +182,9 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
printf("\n \t\texample: %s %s=techs/megapack/factions/tech/units/castle/models/castle.g3d=png=keepsmallest",argv0,GAME_ARGS[GAME_ARG_CONVERT_MODELS]);
printf("\n%s=x\t\tforce the language to be the language specified by x.",GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
printf("\n \t\tWhere x is a supported language (such as english).");
printf("\n \t\tWhere x is a supported language filename or ISO639-1 code.");
printf("\n \t\texample: %s %s=english",argv0,GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
printf("\n \t\texample: %s %s=en",argv0,GAME_ARGS[GAME_ARG_USE_LANGUAGE]);
printf("\n%s=x\t\tshow the calculated CRC for the map named x.",GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]);