22#include "../utils/stringtools.hpp"
65 map<string,string> mLangFileContent;
75 return mLangFileContent;
79 while (!fFile_in.eof())
81 getline(fFile_in, sLine);
89 if (sLine.front() ==
'#')
94 for (
size_t i = 0; i < sLine.length(); i++)
102 for (
unsigned int i = 1; i < sLine.find(
'='); i++)
112 while (sLine.find(
"%%TAB%%") != string::npos)
113 sLine.replace(sLine.find(
"%%TAB%%"), 7,
"\t");
116 while (sLine.find(
"%%LINEBREAK%%") != string::npos)
117 sLine.replace(sLine.find(
"%%LINEBREAK%%"), 13,
"\n");
120 while (sLine.find(
"%%ITEMIZE%%") != string::npos)
121 sLine.replace(sLine.find(
"%%ITEMIZE%%"), 11,
"\n - ");
124 while (sLine.find(
"%%ITEMIZE_END%%") != string::npos)
125 sLine.replace(sLine.find(
"%%ITEMIZE_END%%"), 15,
"\n ");
128 mLangFileContent[sLine.substr(0, sLine.find(
'='))] = sLine.substr(sLine.find_first_not_of(
' ', sLine.find(
'=')+1));
131 return mLangFileContent;
149 for (
auto iter = mLangFileContent.begin(); iter != mLangFileContent.end(); ++iter)
167 map<string,string> mLangFileContent;
175 mLangStrings.insert(mLangFileContent.begin(), mLangFileContent.end());
204 if ((iter->second).length() < 5)
210 for (
size_t i = 0; i < (iter->second).length()-3; i++)
212 if ((iter->second).substr(i, 2) ==
"%%" && isalpha((iter->second)[i+3]) && (iter->second).find(
"%%", i+3) != string::npos)
214 sLine = (iter->second).substr(i+2, (iter->second).find(
"%%", i+3)-i-2);
217 (iter->second).replace(i, (iter->second).find(
"%%", i+3)-i+2,
mLangStrings[sLine]);
240 for (
auto iter = _langstrings.begin(); iter != _langstrings.end(); ++iter)
259 string sKey = sMessage;
262 if (sKey.find(
'*') != string::npos)
264 sKey.erase(sKey.find(
'*'));
269 if ((iter->first).substr(0, sKey.length()) == sKey)
292string Language::get(
const string& sMessage,
const vector<string>& vTokens)
const
297 string sLangString = sMessage;
300 if (sLangString.find(
'*') != string::npos)
302 sLangString.erase(sLangString.find(
'*'));
308 if ((iter->first).substr(0,sLangString.length()) == sLangString)
309 sLangString = iter->second;
312 if (sMessage.substr(0, sLangString.length()) == sLangString)
323 for (
size_t i = 0; i < vTokens.size(); i++)
325 sToken =
"%%" +
toString(i+1) +
"%%";
329 while ((pos = sLangString.find(sToken, pos)) != string::npos)
331 sLangString.replace(pos, sToken.length(), vTokens[i]);
332 pos += vTokens[i].length();
351 vector<string> vListResults;
352 string sPrefix = sMessageScheme.substr(0, sMessageScheme.find(
'*'));
357 if (sPrefix.find(
'[') != string::npos)
359 sPrefix.erase(sPrefix.find(
'['));
360 sType = sMessageScheme.substr(sMessageScheme.find(
'[')+1, sMessageScheme.find(
']')-sMessageScheme.find(
'[')-1);
362 else if (sMessageScheme.find(
'[') != string::npos)
363 sType = sMessageScheme.substr(sMessageScheme.find(
'[')+1, sMessageScheme.find(
']')-sMessageScheme.find(
'[')-1);
367 if ((iter->first).substr(0, sPrefix.length()) != sPrefix)
372 if (sType.length() && (iter->first).find(
'[') != string::npos)
374 string sCurrentType = (iter->first).substr((iter->first).find(
'['), (iter->first).find(
']')+1-(iter->first).find(
'['));
376 if (sCurrentType.find(sType) == string::npos)
381 vListResults.push_back(iter->second);
This class implements the basic input/ output file system and provides functionalities to work with f...
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
This class handles the internal language system and returns the language strings of the selected lang...
void addToLanguage(const std::map< std::string, std::string > &_langstrings)
This member function adds the contents of the passed language file into the internal map.
Language()
Contructor of the language class.
void loadStrings(bool bloadUserFiles=true)
This member function loads the language files to the internal map and replaces the named tokens with ...
std::string getKey(const std::string &sMessage) const
This member function searches the internal language map for an identifier, which starts similar with ...
void loadAndInsert(const std::string &sLanguageFileName)
This private member function is a simple helper for Language::loadStrings().
std::vector< std::string > getList(const std::string &sMessageScheme) const
This member function returns a vector of language strings matching to the passed identifier containin...
std::map< std::string, std::string > mLangStrings
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
std::map< std::string, std::string > getLangFileContent(const std::string &sFile) const
This private member function decodes a single language file into a map and returns it.
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
std::string toString(int)
Converts an integer to a string without the Settings bloat.