HatchKeeper  0.90
The Free Open-Source Egg Incubation Software
HK_Language.cpp
Go to the documentation of this file.
1 /*******************************************************************/
9 #include "../headers/Language.h"
10 
12 
18 HK_Language::HK_Language(std::string Path) {SetPath(Path);}
19 
25 void HK_Language::SetPath(std::string Path) {
26  //reset
27  LangPath = "";
28  Language = "English";
29  BaseLang.clear();
30  Translated.clear();
31 
32  doc.LoadFile(Path.c_str());
33 
34  if(doc.ErrorID() != 0) {
35  Error = doc.ErrorID();
36  return;
37  }
38 
39  tinyxml2::XMLNode * root = doc.FirstChildElement("HatchKeeperLanguage");
40 
41  if(root == nullptr) {
42  Error = doc.ErrorID();
43  return;
44  }
45 
46  tinyxml2::XMLElement * lang = root->FirstChildElement("Language");
47  Language = lang->GetText();
48  LangPath = Path;
49 
50  tinyxml2::XMLElement * strs = root->FirstChildElement("Strings");
51 
52  for( tinyxml2::XMLElement* str = strs->FirstChildElement(); str != NULL; str = str->NextSiblingElement())
53  Add(str->Attribute("value"),str->GetText());
54 }
55 
56 
63 void HK_Language::Add(std::string Base, std::string Translate) {
64  BaseLang.push_back(Base);
65  Translated.push_back(Translate);
66 }
67 
69 int HK_Language::Count() { return BaseLang.size();}
71 int HK_Language::Errors(){return Error;}
73 std::string HK_Language::GetLanguage(){return Language;}
75 std::string HK_Language::GetPath(){return LangPath;}
76 
83 std::string HK_Language::Translate(std::string Text) {
84  for(int a = 0; a < Count();a++) {
85  if(BaseLang[a] == Text)
86  return Translated[a];
87  }
88 
89  return Text;
90 }
int Errors()
Returns Error Code.
Definition: HK_Language.cpp:71
std::vector< std::string > BaseLang
Definition: Language.h:29
tinyxml2::XMLDocument doc
Definition: Language.h:25
std::vector< std::string > Translated
Definition: Language.h:30
std::string GetLanguage()
Returns What The Translated Language Is.
Definition: HK_Language.cpp:73
std::string LangPath
Definition: Language.h:28
void Add(std::string Base, std::string Translate)
Adds Values To The Arrays This function is used internally only.
Definition: HK_Language.cpp:63
int Error
Definition: Language.h:26
int Count()
Returns The Number Of Strings Stored In The Arrays.
Definition: HK_Language.cpp:69
void SetPath(std::string Path)
Sets/Loads Path Opens the xml language file and reads it into two arrays.
Definition: HK_Language.cpp:25
std::string GetPath()
Returns The Path For The Language File.
Definition: HK_Language.cpp:75
std::string Translate(std::string Text)
The Actual Translate Function This function checks Text against the base languages strings,...
Definition: HK_Language.cpp:83
std::string Language
Definition: Language.h:27