- all languages now define their sio639-1 code and the commandline option can take it now:
--use-language=en
This commit is contained in:
parent
cd6b961a3b
commit
5bb270fe41
|
@ -46,8 +46,11 @@ Lang &Lang::getInstance() {
|
||||||
return lang;
|
return lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lang::loadStrings(const string &uselanguage, bool loadFonts,
|
void Lang::loadStrings(string uselanguage, bool loadFonts,
|
||||||
bool fallbackToDefault) {
|
bool fallbackToDefault) {
|
||||||
|
if(uselanguage.length() == 2) {
|
||||||
|
uselanguage = getLanguageFile(uselanguage);
|
||||||
|
}
|
||||||
bool languageChanged = (uselanguage != this->language);
|
bool languageChanged = (uselanguage != this->language);
|
||||||
this->language= uselanguage;
|
this->language= uselanguage;
|
||||||
loadStrings(uselanguage, strings, true, fallbackToDefault);
|
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) {
|
bool fallbackToDefault) {
|
||||||
properties.clear();
|
properties.clear();
|
||||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||||
|
@ -187,7 +190,7 @@ bool Lang::isUTF8Language() const {
|
||||||
return is_utf8_language;
|
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());
|
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;
|
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
|
}}//end namespace
|
||||||
|
|
|
@ -37,13 +37,15 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Lang();
|
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:
|
public:
|
||||||
static Lang &getInstance();
|
static Lang &getInstance();
|
||||||
|
|
||||||
void loadStrings(const string &uselanguage, bool loadFonts=true, bool fallbackToDefault=false);
|
void loadStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false);
|
||||||
void loadScenarioStrings(const string &scenarioDir, const string &scenarioName);
|
void loadScenarioStrings(string scenarioDir, string scenarioName);
|
||||||
|
|
||||||
string get(const string &s,string uselanguage="", bool fallbackToDefault=false);
|
string get(const string &s,string uselanguage="", bool fallbackToDefault=false);
|
||||||
bool hasString(const string &s, string uselanguage="", bool fallbackToDefault=false);
|
bool hasString(const string &s, string uselanguage="", bool fallbackToDefault=false);
|
||||||
|
|
|
@ -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 \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%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=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]);
|
printf("\n%s=x\t\tshow the calculated CRC for the map named x.",GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user