- modders can now override land and air field names using lng specific files for a tileset (follows same principle as techtree lng files). Currently supported translatable strings:

FieldLandName=Land
FieldAirName=Air
This commit is contained in:
Mark Vejvoda 2012-05-11 05:49:47 +00:00
parent 394efbcbc0
commit bf3e5a15bf
4 changed files with 108 additions and 13 deletions

View File

@ -287,6 +287,54 @@ void Lang::loadTechTreeStrings(string techTree) {
} }
} }
void Lang::loadTilesetStrings(string tileset) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tileset = [%s]\n",__FILE__,__FUNCTION__,__LINE__,tileset.c_str());
string currentPath = "";
Config &config = Config::getInstance();
vector<string> tilesetPaths = config.getPathListForType(ptTilesets);
for(int idx = 0; idx < tilesetPaths.size(); idx++) {
string &tilesetPath = tilesetPaths[idx];
endPathWithSlash(tilesetPath);
//printf("tilesetPath [%s]\n",tilesetPath.c_str());
if(folderExists(tilesetPath + tileset) == true) {
currentPath = tilesetPath;
endPathWithSlash(currentPath);
break;
}
}
string tilesetFolder = currentPath + tileset + "/";
string path = tilesetFolder + "lang/" + tileset + "_" + language + ".lng";
string pathDefault = tilesetFolder + "lang/" + tileset + "_default.lng";
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] pathDefault = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),pathDefault.c_str());
tilesetStrings.clear();
tilesetStringsDefault.clear();
//try to load the current language first
if(fileExists(path)) {
tilesetStrings.load(path);
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path not found [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
//try english otherwise
path = tilesetFolder + "lang/" + tileset + "_english.lng";
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
if(fileExists(path)) {
tilesetStrings.load(path);
}
}
if(fileExists(pathDefault)) {
tilesetStringsDefault.load(pathDefault);
}
}
bool Lang::hasString(const string &s, string uselanguage, bool fallbackToDefault) { bool Lang::hasString(const string &s, string uselanguage, bool fallbackToDefault) {
bool result = false; bool result = false;
try { try {
@ -411,6 +459,35 @@ string Lang::getTechTreeString(const string &s,const char *defaultValue) {
} }
} }
string Lang::getTilesetString(const string &s,const char *defaultValue) {
try{
string result = "";
if(tilesetStrings.hasString(s) == true || defaultValue == NULL) {
if(tilesetStrings.hasString(s) == false && tilesetStringsDefault.hasString(s) == true) {
result = tilesetStringsDefault.getString(s);
}
else {
result = tilesetStrings.getString(s);
}
}
else if(tilesetStringsDefault.hasString(s) == true) {
result = tilesetStringsDefault.getString(s);
}
else if(defaultValue != NULL) {
result = defaultValue;
}
replaceAll(result, "\\n", "\n");
return result;
}
catch(exception &ex) {
if(tilesetStrings.getpath() != "") {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
}
return "???" + s + "???";
}
}
bool Lang::fileMatchesISO630Code(string uselanguage, string testLanguageFile) { bool Lang::fileMatchesISO630Code(string uselanguage, string testLanguageFile) {
bool result = false; bool result = false;
Properties stringsTest; Properties stringsTest;

View File

@ -39,6 +39,8 @@ private:
Properties scenarioStrings; Properties scenarioStrings;
Properties techTreeStrings; Properties techTreeStrings;
Properties techTreeStringsDefault; Properties techTreeStringsDefault;
Properties tilesetStrings;
Properties tilesetStringsDefault;
std::map<string,Properties> otherLanguageStrings; std::map<string,Properties> otherLanguageStrings;
@ -57,11 +59,13 @@ public:
void loadStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false); void loadStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false);
void loadScenarioStrings(string scenarioDir, string scenarioName); void loadScenarioStrings(string scenarioDir, string scenarioName);
void loadTechTreeStrings(string techTree); void loadTechTreeStrings(string techTree);
void loadTilesetStrings(string tileset);
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);
string getScenarioString(const string &s); string getScenarioString(const string &s);
string getTechTreeString(const string &s, const char *defaultValue=NULL); string getTechTreeString(const string &s, const char *defaultValue=NULL);
string getTilesetString(const string &s, const char *defaultValue=NULL);
string getLanguage() const { return language; } string getLanguage() const { return language; }
bool isLanguageLocal(string compareLanguage) const; bool isLanguageLocal(string compareLanguage) const;

View File

@ -581,20 +581,31 @@ string SkillType::skillClassToStr(SkillClass skillClass) {
string SkillType::fieldToStr(Field field) { string SkillType::fieldToStr(Field field) {
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
string fieldName = "";
switch(field) { switch(field) {
case fLand: case fLand:
if(lang.hasString("FieldLand") == true) { if(lang.hasString("FieldLand") == true) {
return lang.get("FieldLand"); fieldName = lang.get("FieldLand");
} }
return "Land"; else {
case fAir: fieldName = "Land";
if(lang.hasString("FieldAir") == true) { }
return lang.get("FieldAir"); //return "Land";
} return lang.getTilesetString("FieldLandName",fieldName.c_str());
return "Air";
default: case fAir:
assert(false); if(lang.hasString("FieldAir") == true) {
return ""; fieldName = lang.get("FieldAir");
}
else {
fieldName = "Air";
}
//return "Air";
return lang.getTilesetString("FieldAirName",fieldName.c_str());
default:
assert(false);
return "";
}; };
} }

View File

@ -361,6 +361,9 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw megaglest_runtime_error("Error: " + path + "\n" + e.what()); throw megaglest_runtime_error("Error: " + path + "\n" + e.what());
} }
Lang &lang = Lang::getInstance();
lang.loadTilesetStrings(name);
} }
Tileset::~Tileset() { Tileset::~Tileset() {