- now display native language name in options menu
This commit is contained in:
parent
cd2daf09dc
commit
6937785f22
|
@ -23,6 +23,7 @@
|
||||||
#include "gl_wrap.h"
|
#include "gl_wrap.h"
|
||||||
#include "core_data.h"
|
#include "core_data.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
#include <algorithm>
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -352,4 +353,70 @@ string Lang::getLanguageFile(string uselanguage) {
|
||||||
return result;
|
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
|
}}//end namespace
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
void loadStrings(string language, Properties &properties, bool fileMustExist,bool fallbackToDefault=false);
|
void loadStrings(string language, Properties &properties, bool fileMustExist,bool fallbackToDefault=false);
|
||||||
string getLanguageFile(string uselanguage);
|
string getLanguageFile(string uselanguage);
|
||||||
bool fileMatchesISO630Code(string uselanguage, string testLanguageFile);
|
bool fileMatchesISO630Code(string uselanguage, string testLanguageFile);
|
||||||
|
string getNativeLanguageName(string uselanguage, string testLanguageFile);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Lang &getInstance();
|
static Lang &getInstance();
|
||||||
|
@ -54,6 +55,8 @@ public:
|
||||||
string getLanguage() const { return language; }
|
string getLanguage() const { return language; }
|
||||||
bool isLanguageLocal(string compareLanguage) const;
|
bool isLanguageLocal(string compareLanguage) const;
|
||||||
bool isUTF8Language() const;
|
bool isUTF8Language() const;
|
||||||
|
map<string,string> getDiscoveredLanguageList();
|
||||||
|
pair<string,string> getNavtiveNameFromLanguageName(string langName);
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -887,7 +887,7 @@ void MainWindow::showLanguages() {
|
||||||
menuItems.push_back(testLanguage);
|
menuItems.push_back(testLanguage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuItems.push_back(lang.get("ExitGame?"));
|
menuItems.push_back(lang.get("Exit"));
|
||||||
cancelLanguageSelection = menuItems.size()-1;
|
cancelLanguageSelection = menuItems.size()-1;
|
||||||
|
|
||||||
popupMenu.setW(100);
|
popupMenu.setW(100);
|
||||||
|
|
|
@ -289,28 +289,35 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
|
||||||
labelLang.setText(lang.get("Language"));
|
labelLang.setText(lang.get("Language"));
|
||||||
|
|
||||||
listBoxLang.registerGraphicComponent(containerName,"listBoxLang");
|
listBoxLang.registerGraphicComponent(containerName,"listBoxLang");
|
||||||
listBoxLang.init(currentColumnStart, currentLine, 170);
|
listBoxLang.init(currentColumnStart, currentLine, 260);
|
||||||
vector<string> langResults;
|
vector<string> langResults;
|
||||||
|
|
||||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
// string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||||
|
//
|
||||||
string userDataPath = getGameCustomCoreDataPath(data_path, "");
|
// string userDataPath = getGameCustomCoreDataPath(data_path, "");
|
||||||
findAll(userDataPath + "data/lang/*.lng", langResults, true, false);
|
// findAll(userDataPath + "data/lang/*.lng", langResults, true, false);
|
||||||
|
//
|
||||||
vector<string> langResults2;
|
// vector<string> langResults2;
|
||||||
findAll(data_path + "data/lang/*.lng", langResults2, true);
|
// findAll(data_path + "data/lang/*.lng", langResults2, true);
|
||||||
if(langResults2.empty() && langResults.empty()) {
|
// if(langResults2.empty() && langResults.empty()) {
|
||||||
throw runtime_error("There are no lang files");
|
// throw runtime_error("There are no lang files");
|
||||||
}
|
// }
|
||||||
for(unsigned int i = 0; i < langResults2.size(); ++i) {
|
// for(unsigned int i = 0; i < langResults2.size(); ++i) {
|
||||||
string testLanguage = langResults2[i];
|
// string testLanguage = langResults2[i];
|
||||||
if(std::find(langResults.begin(),langResults.end(),testLanguage) == langResults.end()) {
|
// if(std::find(langResults.begin(),langResults.end(),testLanguage) == langResults.end()) {
|
||||||
langResults.push_back(testLanguage);
|
// 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.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;
|
currentLine-=lineOffset;
|
||||||
|
|
||||||
//playerName
|
//playerName
|
||||||
|
@ -995,7 +1002,10 @@ void MenuStateOptions::saveConfig(){
|
||||||
config.setString("NetPlayerName", labelPlayerName.getText());
|
config.setString("NetPlayerName", labelPlayerName.getText());
|
||||||
}
|
}
|
||||||
//Copy values
|
//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"));
|
lang.loadStrings(config.getString("Lang"));
|
||||||
|
|
||||||
int index= listBoxShadows.getSelectedItemIndex();
|
int index= listBoxShadows.getSelectedItemIndex();
|
||||||
|
|
|
@ -123,6 +123,7 @@ private:
|
||||||
GraphicLabel labelRainEffect;
|
GraphicLabel labelRainEffect;
|
||||||
GraphicCheckBox checkBoxRainEffect;
|
GraphicCheckBox checkBoxRainEffect;
|
||||||
|
|
||||||
|
map<string,string> languageList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateOptions(Program *program, MainMenu *mainMenu);
|
MenuStateOptions(Program *program, MainMenu *mainMenu);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user