diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index 9bd6506c..fec8b42b 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -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 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 diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index 03e91d7b..b46d780e 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -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); diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index 01f2b78f..e837c414 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -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]);