- Added translation mechanism, and basic french translation as an example
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-05-16 15:23:26 +00:00
parent 94bebd795c
commit f94df3862b
23 changed files with 242 additions and 60 deletions

View File

@@ -0,0 +1,51 @@
#include "../include/Translate.h"
#include "../include/config.h"
#include <JGE.h>
#include <fstream>
#include <iostream>
Translator * Translator::mInstance = NULL;
Translator * Translator::GetInstance(){
if (!mInstance) mInstance = NEW Translator();
return mInstance;
}
void Translator::EndInstance(){
SAFE_DELETE(mInstance);
}
int Translator::Add(string from, string to){
values[from] = to;
return 1;
}
string Translator::translate(string value){
map<string,string>::iterator it = values.find(value);
if (it != values.end()) return it->second;
return value;
}
Translator::Translator(){
std::ifstream file("Res/lang/_lang.txt");
std::string s;
if(file){
while(std::getline(file,s)){
if (!s.size()) continue;
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
size_t found = s.find('=');
if (found == string::npos) continue;
string s1 = s.substr(0,found);
string s2 = s.substr(found+1);
Add(s1,s2);
}
file.close();
}
}
string _(string toTranslate){
Translator * t = Translator::GetInstance();
return t->translate(toTranslate);
}