- now display native language name in options menu

This commit is contained in:
Mark Vejvoda 2011-11-30 23:35:54 +00:00
parent cd2daf09dc
commit 6937785f22
5 changed files with 100 additions and 19 deletions

View File

@ -23,6 +23,7 @@
#include "gl_wrap.h"
#include "core_data.h"
#include "renderer.h"
#include <algorithm>
#include "leak_dumper.h"
using namespace std;
@ -352,4 +353,70 @@ string Lang::getLanguageFile(string uselanguage) {
return result;
}
string Lang::getNativeLanguageName(string uselanguage, string testLanguageFile) {
string result = uselanguage;
Properties stringsTest;
stringsTest.load(testLanguageFile);
try {
result = stringsTest.getString("NativeLanguageName");
}
catch(exception &ex) {
}
return result;
}
pair<string,string> Lang::getNavtiveNameFromLanguageName(string langName) {
pair<string,string> result;
//printf("looking for language [%s]\n",langName.c_str());
map<string,string> nativeList = Lang::getDiscoveredLanguageList();
for(map<string,string>::iterator iterMap = nativeList.begin();
iterMap != nativeList.end(); ++iterMap) {
//printf("language [%s][%s]\n",iterMap->second.c_str(), iterMap->first.c_str());
if(iterMap->second == langName) {
result = make_pair(iterMap->first,iterMap->second);
break;
}
}
return result;
}
map<string,string> Lang::getDiscoveredLanguageList() {
map<string,string> result;
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
string userDataPath = getGameCustomCoreDataPath(data_path, "");
vector<string> langResults;
findAll(userDataPath + "data/lang/*.lng", langResults, true, false);
for(unsigned int i = 0; i < langResults.size(); ++i) {
string testLanguage = langResults[i];
string testLanguageFile = userDataPath + "data/lang/" + testLanguage + ".lng";
string nativeName = getNativeLanguageName(testLanguage, testLanguageFile);
result[nativeName] = testLanguage;
}
vector<string> langResults2;
findAll(data_path + "data/lang/*.lng", langResults2, true);
if(langResults2.empty() && langResults.empty()) {
throw runtime_error("There are no lang files");
}
for(unsigned int i = 0; i < langResults2.size(); ++i) {
string testLanguage = langResults2[i];
if(std::find(langResults.begin(),langResults.end(),testLanguage) == langResults.end()) {
langResults.push_back(testLanguage);
string testLanguageFile = data_path + "data/lang/" + testLanguage + ".lng";
string nativeName = getNativeLanguageName(testLanguage, testLanguageFile);
result[nativeName] = testLanguage;
}
}
return result;
}
}}//end namespace

View File

@ -40,6 +40,7 @@ private:
void loadStrings(string language, Properties &properties, bool fileMustExist,bool fallbackToDefault=false);
string getLanguageFile(string uselanguage);
bool fileMatchesISO630Code(string uselanguage, string testLanguageFile);
string getNativeLanguageName(string uselanguage, string testLanguageFile);
public:
static Lang &getInstance();
@ -54,6 +55,8 @@ public:
string getLanguage() const { return language; }
bool isLanguageLocal(string compareLanguage) const;
bool isUTF8Language() const;
map<string,string> getDiscoveredLanguageList();
pair<string,string> getNavtiveNameFromLanguageName(string langName);
};
}}//end namespace

View File

@ -887,7 +887,7 @@ void MainWindow::showLanguages() {
menuItems.push_back(testLanguage);
}
}
menuItems.push_back(lang.get("ExitGame?"));
menuItems.push_back(lang.get("Exit"));
cancelLanguageSelection = menuItems.size()-1;
popupMenu.setW(100);

View File

@ -289,28 +289,35 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelLang.setText(lang.get("Language"));
listBoxLang.registerGraphicComponent(containerName,"listBoxLang");
listBoxLang.init(currentColumnStart, currentLine, 170);
listBoxLang.init(currentColumnStart, currentLine, 260);
vector<string> langResults;
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
string userDataPath = getGameCustomCoreDataPath(data_path, "");
findAll(userDataPath + "data/lang/*.lng", langResults, true, false);
vector<string> langResults2;
findAll(data_path + "data/lang/*.lng", langResults2, true);
if(langResults2.empty() && langResults.empty()) {
throw runtime_error("There are no lang files");
}
for(unsigned int i = 0; i < langResults2.size(); ++i) {
string testLanguage = langResults2[i];
if(std::find(langResults.begin(),langResults.end(),testLanguage) == langResults.end()) {
langResults.push_back(testLanguage);
}
// string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
//
// string userDataPath = getGameCustomCoreDataPath(data_path, "");
// findAll(userDataPath + "data/lang/*.lng", langResults, true, false);
//
// vector<string> langResults2;
// findAll(data_path + "data/lang/*.lng", langResults2, true);
// if(langResults2.empty() && langResults.empty()) {
// throw runtime_error("There are no lang files");
// }
// for(unsigned int i = 0; i < langResults2.size(); ++i) {
// string testLanguage = langResults2[i];
// if(std::find(langResults.begin(),langResults.end(),testLanguage) == langResults.end()) {
// langResults.push_back(testLanguage);
// }
// }
languageList = Lang::getInstance().getDiscoveredLanguageList();
for(map<string,string>::iterator iterMap = languageList.begin();
iterMap != languageList.end(); ++iterMap) {
langResults.push_back(iterMap->second + "-" + iterMap->first);
}
listBoxLang.setItems(langResults);
listBoxLang.setSelectedItem(config.getString("Lang"));
pair<string,string> defaultLang = Lang::getInstance().getNavtiveNameFromLanguageName(config.getString("Lang"));
listBoxLang.setSelectedItem(defaultLang.second + "-" + defaultLang.first);
currentLine-=lineOffset;
//playerName
@ -995,7 +1002,10 @@ void MenuStateOptions::saveConfig(){
config.setString("NetPlayerName", labelPlayerName.getText());
}
//Copy values
config.setString("Lang", listBoxLang.getSelectedItem());
map<string,string>::iterator iterMap = languageList.begin();
std::advance(iterMap, listBoxLang.getSelectedItemIndex());
config.setString("Lang", iterMap->second);
lang.loadStrings(config.getString("Lang"));
int index= listBoxShadows.getSelectedItemIndex();

View File

@ -123,6 +123,7 @@ private:
GraphicLabel labelRainEffect;
GraphicCheckBox checkBoxRainEffect;
map<string,string> languageList;
public:
MenuStateOptions(Program *program, MainMenu *mainMenu);