bugfix for translations for techtree

This commit is contained in:
Mark Vejvoda 2013-10-29 20:24:23 +00:00
parent dea351095c
commit 958872cacf
3 changed files with 67 additions and 2 deletions

View File

@ -276,6 +276,8 @@ void Lang::loadScenarioStrings(string scenarioDir, string scenarioName, bool isT
void Lang::loadTechTreeStrings(string techTree,bool forceLoad) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] techTree = [%s]\n",__FILE__,__FUNCTION__,__LINE__,techTree.c_str());
//printf("Line: %d techTree = %s forceLoad = %d\n",__LINE__,techTree.c_str(),forceLoad);
if(forceLoad == false && techTree == techNameLoaded) {
return;
}
@ -302,13 +304,22 @@ void Lang::loadTechTreeStrings(string techTree,bool forceLoad) {
//techTreeStrings.clear();
//techTreeStringsDefault.clear();
//printf("Line: %d techTree = %s this->language = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),this->language.c_str(),forceLoad,path.c_str());
//try to load the current language first
if(fileExists(path)) {
if(forceLoad == true ||
path != techTreeStringsAllLanguages[techTree][this->language].getpath()) {
//printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str());
techTreeStringsAllLanguages[techTree][this->language].load(path);
techNameLoaded = techTree;
}
else if(path == techTreeStringsAllLanguages[techTree][this->language].getpath() &&
techTree != techNameLoaded) {
techNameLoaded = techTree;
}
}
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());
@ -318,22 +329,39 @@ void Lang::loadTechTreeStrings(string techTree,bool forceLoad) {
path = techTreeFolder + "lang/" + techTree + "_" + default_language + ".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());
//printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str());
if(fileExists(path)) {
if(forceLoad == true ||
path != techTreeStringsAllLanguages[techTree][default_language].getpath()) {
//printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str());
techTreeStringsAllLanguages[techTree][default_language].load(path);
techNameLoaded = techTree;
}
else if(path == techTreeStringsAllLanguages[techTree][default_language].getpath() &&
techTree != techNameLoaded) {
techNameLoaded = techTree;
}
}
}
if(fileExists(pathDefault)) {
string default_language = "default";
//printf("Line: %d techTree = %s forceLoad = %d default_language = %s\n",__LINE__,techTree.c_str(),forceLoad,default_language.c_str());
if(forceLoad == true ||
pathDefault != techTreeStringsAllLanguages[techTree][default_language].getpath()) {
//printf("Line: %d techTree = %s forceLoad = %d pathDefault = %s\n",__LINE__,techTree.c_str(),forceLoad,pathDefault.c_str());
techTreeStringsAllLanguages[techTree][default_language].load(pathDefault);
techNameLoaded = techTree;
}
else if(pathDefault == techTreeStringsAllLanguages[techTree][default_language].getpath() &&
techTree != techNameLoaded) {
techNameLoaded = techTree;
}
}
}
@ -504,19 +532,30 @@ string Lang::getTechTreeString(const string &s,const char *defaultValue) {
string default_language = "default";
string result = "";
//printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str());
if(allowNativeLanguageTechtree == true &&
(techTreeStringsAllLanguages[techNameLoaded][this->language].hasString(s) == true ||
defaultValue == NULL)) {
if(techTreeStringsAllLanguages[techNameLoaded][this->language].hasString(s) == false &&
techTreeStringsAllLanguages[techNameLoaded][default_language].hasString(s) == true) {
//printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str());
result = techTreeStringsAllLanguages[techNameLoaded][default_language].getString(s);
}
else {
//printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str());
result = techTreeStringsAllLanguages[techNameLoaded][this->language].getString(s);
}
}
else if(allowNativeLanguageTechtree == true &&
techTreeStringsAllLanguages[techNameLoaded][default_language].hasString(s) == true) {
//printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str());
result = techTreeStringsAllLanguages[techNameLoaded][default_language].getString(s);
}
else if(defaultValue != NULL) {

View File

@ -57,6 +57,7 @@ private:
public:
static Lang &getInstance();
string getTechNameLoaded() const { return techNameLoaded; }
bool getAllowNativeLanguageTechtree() const { return allowNativeLanguageTechtree; }
void setAllowNativeLanguageTechtree(bool value) { allowNativeLanguageTechtree = value; }

View File

@ -51,12 +51,21 @@ string TechTree::getName(bool translatedValue) const {
if(translatedValue == false) return name;
Lang &lang = Lang::getInstance();
if(lang.getTechNameLoaded() != name) {
//printf("Line: %d Tech [%s]\n",__LINE__,name.c_str());
lang.loadTechTreeStrings(name,false);
//translatedTechFactionNames.erase(name);
}
return lang.getTechTreeString("TechTreeName",name.c_str());
}
string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTechtreeActiveFile) {
string result = techName;
//printf("Line: %d Tech [%s] forceLoad = %d forceTechtreeActiveFile = %d\n",__LINE__,techName.c_str(),forceLoad,forceTechtreeActiveFile);
if(forceTechtreeActiveFile == false &&
translatedTechNames.find(techName) != translatedTechNames.end()) {
result = translatedTechNames[techName];
@ -73,6 +82,8 @@ string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTe
Lang &lang = Lang::getInstance();
lang.loadTechTreeStrings(name,forceLoad);
translatedTechFactionNames.erase(name);
result = getName(true);
translatedTechNames[techName] = result;
@ -83,19 +94,33 @@ string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTe
}
string TechTree::getTranslatedFactionName(string techName, string factionName) {
//printf("Line: %d Tech [%s] name [%s] factionName [%s]\n",__LINE__,techName.c_str(),name.c_str(),factionName.c_str());
Lang &lang = Lang::getInstance();
if(lang.getTechNameLoaded() != techName) {
//printf("Line: %d Tech [%s] name [%s] lang.getTechNameLoaded() [%s] factionName [%s]\n",__LINE__,techName.c_str(),name.c_str(),lang.getTechNameLoaded().c_str(),factionName.c_str());
lang.loadTechTreeStrings(techName,false);
translatedTechFactionNames.erase(techName);
}
std::map<string,std::map<string,string> >::iterator iterMap = translatedTechFactionNames.find(techName);
if(iterMap != translatedTechFactionNames.end()) {
if(iterMap->second.find(factionName) != iterMap->second.end()) {
//printf("Line: %d Tech [%s] factionName [%s]\n",__LINE__,techName.c_str(),factionName.c_str());
return iterMap->second.find(factionName)->second;
}
}
//printf("Line: %d Tech [%s] factionName [%s]\n",__LINE__,techName.c_str(),factionName.c_str());
getTranslatedName(techName,false,true);
Lang &lang = Lang::getInstance();
string result = lang.getTechTreeString("FactionName_" + factionName,factionName.c_str());
translatedTechFactionNames[techName][factionName] = result;
//printf("Translated faction for Tech [%s] faction [%s] result [%s]\n",techName.c_str(),factionName.c_str(),result.c_str());
//printf("Line: %d Translated faction for Tech [%s] faction [%s] result [%s]\n",__LINE__,techName.c_str(),factionName.c_str(),result.c_str());
return result;
}