ManaPlus
Functions
LanguageDb Namespace Reference

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
const std::string & getIcon (const int id)
 
const std::string & getPo (const int id)
 

Function Documentation

◆ getIcon()

const std::string & LanguageDb::getIcon ( const int  id)

Definition at line 111 of file languagedb.cpp.

112 {
113  std::map<int, std::string>::const_iterator it = mIcons.find(id);
114  if (it == mIcons.end())
115  return mDefaultIcon;
116  return (*it).second;
117 }
std::map< int, std::string > mIcons
Definition: languagedb.cpp:36

References anonymous_namespace{languagedb.cpp}::mDefaultIcon, and anonymous_namespace{languagedb.cpp}::mIcons.

Referenced by SpellManager::save(), and Being::setLanguageId().

◆ getPo()

const std::string & LanguageDb::getPo ( const int  id)

Definition at line 119 of file languagedb.cpp.

120 {
121  std::map<int, std::string>::const_iterator it = mPo.find(id);
122  if (it == mPo.end())
123  return mDefaultPo;
124  return (*it).second;
125 }
std::map< int, std::string > mPo
Definition: languagedb.cpp:37

References anonymous_namespace{languagedb.cpp}::mDefaultPo, and anonymous_namespace{languagedb.cpp}::mPo.

Referenced by getServerLang().

◆ load()

void LanguageDb::load ( )

Definition at line 40 of file languagedb.cpp.

41 {
42  unload();
43  logger->log1("Initializing languages database...");
45  loadXmlFile(paths.getStringValue("languagesPatchFile"), SkipError_true);
46  loadXmlDir("languagesPatchDir", loadXmlFile)
47 }
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:43
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

void LanguageDb::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 49 of file languagedb.cpp.

51 {
54  skipError);
55  XmlNodeConstPtrConst root = doc->rootNode();
56 
57  if ((root == nullptr) || !xmlNameEqual(root, "languages"))
58  {
59  delete doc;
60  return;
61  }
62 
63  for_each_xml_child_node(node, root)
64  {
65  if (xmlNameEqual(node, "include"))
66  {
67  const std::string name = XML::getProperty(node, "name", "");
68  if (!name.empty())
69  loadXmlFile(name, skipError);
70  continue;
71  }
72  else if (xmlNameEqual(node, "lang"))
73  {
74  const int id = XML::getProperty(node, "id", -1);
75  if (id < 0)
76  {
77  reportAlways("Missing lang id")
78  continue;
79  }
80  const std::string icon = XML::getProperty(node, "icon", "");
81  const std::string po = XML::getProperty(node, "po", "");
82  if (icon.empty())
83  {
84  reportAlways("LanguageDb: empty icon field")
85  }
86  else
87  {
88  mIcons[id] = icon;
89  }
90  if (po.empty())
91  {
92  reportAlways("LanguageDb: empty po field")
93  }
94  else
95  {
96  mPo[id] = po;
97  }
98  }
99  }
100 
101  delete doc;
102 }
#define reportAlways(...)
Definition: checkutils.h:253
xmlNodePtr rootNode()
Definition: libxml.cpp:169
if(!vert) return
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
Definition: libxml.cpp:86
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string empty
Definition: podict.cpp:26
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References fileName, for_each_xml_child_node, XML::getProperty(), loadXmlFile(), anonymous_namespace{languagedb.cpp}::mIcons, anonymous_namespace{languagedb.cpp}::mPo, reportAlways, XML::Document::rootNode(), and UseVirtFs_true.

◆ unload()

void LanguageDb::unload ( )

Definition at line 104 of file languagedb.cpp.

105 {
106  logger->log1("Unloading languages database...");
107  mIcons.clear();
108  mPo.clear();
109 }

References Logger::log1(), logger, anonymous_namespace{languagedb.cpp}::mIcons, and anonymous_namespace{languagedb.cpp}::mPo.

Referenced by DbManager::unloadDb().