homebrewfilter/source/Tools/translate.cpp

108 lines
2.4 KiB
C++
Raw Normal View History

2011-09-27 21:52:55 +02:00
#include <dirent.h>
#include <string>
#include <vector>
#include <fstream>
#include "main.h"
#include "menu.h"
#include "Tools/save.h"
using namespace std;
std::vector<string> quelltext;
void ini_Open(string filename)
{
quelltext.clear();
string line;
ifstream in(filename.c_str());
while(getline(in, line))
{
while((signed)line.find("\r") != -1)
line.erase(line.find("\r"), 1);
quelltext.push_back(line);
}
}
string ini_GetString(string key)
{
string value;
int i = 0;
for (i = 0; i < (signed)quelltext.size(); i++)
{
if((signed)quelltext[i].find(key) != -1)
{
// leerzeichen vor dem ersten buchstaben l<>schen
while(quelltext[i].substr(0, 1) == " ")
quelltext[i].erase(0, 1);
// leerzeichen nach dem letzen buchstaben l<>schen
while(quelltext[i].substr(quelltext[i].find("=") -1, 1) == " ")
quelltext[i].erase(quelltext[i].find("=") -1, 1);
// <20>berpr<70>fen, ob vorhandener key und gesuchter key <20>bereinstimmen
if(key == quelltext[i].substr(0, quelltext[i].find("=")))
break;
}
}
if((signed)quelltext.size() != i)
{
value = quelltext[i].substr(quelltext[i].find("=") +1);
while(value.substr(0, 1) == " ")
value.erase(0, 1);
}
return value;
}
const char* tr(string translate)
{
string GetString = ini_GetString(translate);
if(GetString != "")
translate = GetString;
return translate.c_str();
}
void translate()
{
if(CONF_GetLanguage() == JAPANESE)
2012-03-04 21:01:11 +01:00
ini_Open(check_path(Settings.device_dat + ":/config/HBF/languages/") + "japanese.lang");
2011-09-27 21:52:55 +02:00
else if(CONF_GetLanguage() == ENGLISH)
2012-03-04 21:01:11 +01:00
ini_Open(check_path(Settings.device_dat + ":/config/HBF/languages/") + "english.lang");
2011-09-27 21:52:55 +02:00
else if(CONF_GetLanguage() == GERMAN)
2012-03-04 21:01:11 +01:00
ini_Open(check_path(Settings.device_dat + ":/config/HBF/languages/") + "german.lang");
2011-09-27 21:52:55 +02:00
else if(CONF_GetLanguage() == FRENCH)
2012-03-04 21:01:11 +01:00
ini_Open(check_path(Settings.device_dat + ":/config/HBF/languages/") + "french.lang");
2011-09-27 21:52:55 +02:00
else if(CONF_GetLanguage() == SPANISH)
2012-03-04 21:01:11 +01:00
ini_Open(check_path(Settings.device_dat + ":/config/HBF/languages/") + "spanish.lang");
2011-09-27 21:52:55 +02:00
}
bool language_folder_exists()
{
// font speicher ordner erstellen
if(folder_exists())
{
DIR *pDir;
2012-03-04 21:01:11 +01:00
pDir = opendir(check_path(Settings.device_dat + ":/config/HBF/Languages").c_str());
2011-09-27 21:52:55 +02:00
if(pDir != NULL)
{
closedir (pDir);
return true;
}
else
{
2012-03-04 21:01:11 +01:00
if (mkdir((Settings.device_dat + ":/config/HBF/Languages").c_str(), 0777) != -1)
2011-09-27 21:52:55 +02:00
{
closedir (pDir);
return true;
}
}
closedir (pDir);
}
return false;
2011-09-25 19:47:02 +02:00
}