From 6937785f2256c6b7497deaebd8d9664d5ffa4de6 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 30 Nov 2011 23:35:54 +0000 Subject: [PATCH] - now display native language name in options menu --- source/glest_game/global/lang.cpp | 67 +++++++++++++++++++ source/glest_game/global/lang.h | 3 + source/glest_game/main/main.cpp | 2 +- source/glest_game/menu/menu_state_options.cpp | 46 ++++++++----- source/glest_game/menu/menu_state_options.h | 1 + 5 files changed, 100 insertions(+), 19 deletions(-) diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index fec8b42b..1f051452 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -23,6 +23,7 @@ #include "gl_wrap.h" #include "core_data.h" #include "renderer.h" +#include #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 Lang::getNavtiveNameFromLanguageName(string langName) { + pair result; + + //printf("looking for language [%s]\n",langName.c_str()); + + map nativeList = Lang::getDiscoveredLanguageList(); + for(map::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 Lang::getDiscoveredLanguageList() { + map result; + + string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + string userDataPath = getGameCustomCoreDataPath(data_path, ""); + + vector 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 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 diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index b46d780e..30c7776c 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -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 getDiscoveredLanguageList(); + pair getNavtiveNameFromLanguageName(string langName); }; }}//end namespace diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 845a9104..bcd6f630 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -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); diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index dc8fc2c5..a607d63c 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -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 langResults; - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - - string userDataPath = getGameCustomCoreDataPath(data_path, ""); - findAll(userDataPath + "data/lang/*.lng", langResults, true, false); - - vector 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 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::iterator iterMap = languageList.begin(); + iterMap != languageList.end(); ++iterMap) { + langResults.push_back(iterMap->second + "-" + iterMap->first); } listBoxLang.setItems(langResults); - listBoxLang.setSelectedItem(config.getString("Lang")); + + pair 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::iterator iterMap = languageList.begin(); + std::advance(iterMap, listBoxLang.getSelectedItemIndex()); + + config.setString("Lang", iterMap->second); lang.loadStrings(config.getString("Lang")); int index= listBoxShadows.getSelectedItemIndex(); diff --git a/source/glest_game/menu/menu_state_options.h b/source/glest_game/menu/menu_state_options.h index cca35306..726dce45 100644 --- a/source/glest_game/menu/menu_state_options.h +++ b/source/glest_game/menu/menu_state_options.h @@ -123,6 +123,7 @@ private: GraphicLabel labelRainEffect; GraphicCheckBox checkBoxRainEffect; + map languageList; public: MenuStateOptions(Program *program, MainMenu *mainMenu);