ManaPlus
Typedefs | Functions
langs.h File Reference

(986a3bf)

#include "utils/vector.h"
#include <string>
#include "localconsts.h"

Go to the source code of this file.

Typedefs

typedef std::vector< std::string > LangVect
 
typedef LangVect::const_iterator LangIter
 

Functions

LangVect getLang ()
 
LangVect getServerLang ()
 
std::string getLangSimple ()
 
std::string getLangShort ()
 

Typedef Documentation

◆ LangIter

typedef LangVect::const_iterator LangIter

Definition at line 32 of file langs.h.

◆ LangVect

typedef std::vector<std::string> LangVect

Definition at line 31 of file langs.h.

Function Documentation

◆ getLang()

LangVect getLang ( )

Definition at line 42 of file langs.cpp.

43 {
44  LangVect langs;
45  std::string lang = config.getStringValue("lang");
46  if (lang.empty())
47  {
48  const char *const lng = getLangName();
49  if (lng == nullptr)
50  return langs;
51  lang = lng;
52  }
53  else if (lang.size() > 1000)
54  {
55  return langs;
56  }
57 
58  size_t dot = lang.find('.');
59  if (dot != std::string::npos)
60  lang = lang.substr(0, dot);
61  langs.push_back(lang);
62  dot = lang.find('_');
63  if (dot != std::string::npos)
64  langs.push_back(lang.substr(0, dot));
65  return langs;
66 }
std::string getStringValue(const std::string &key) const
Configuration config
static const char * getLangName()
Definition: langs.cpp:34
std::vector< std::string > LangVect
Definition: langs.h:31

References config, getLangName(), and Configuration::getStringValue().

Referenced by TranslationManager::loadCurrentLang(), and Gui::postInit().

◆ getLangShort()

std::string getLangShort ( )

Definition at line 102 of file langs.cpp.

103 {
104  std::string lang = config.getStringValue("lang");
105  if (lang.empty())
106  {
107  const char *const lng = getLangName();
108  if (lng == nullptr)
109  return "";
110  lang = lng;
111  }
112  else if (lang.size() > 1000)
113  {
114  return "";
115  }
116 
117  size_t dot = lang.find('.');
118  if (dot != std::string::npos)
119  lang = lang.substr(0, dot);
120  dot = lang.find('_');
121  if (dot != std::string::npos)
122  return lang.substr(0, dot);
123  return lang;
124 }

References config, getLangName(), and Configuration::getStringValue().

Referenced by ServerDialog::loadServers().

◆ getLangSimple()

std::string getLangSimple ( )

Definition at line 85 of file langs.cpp.

86 {
87  const std::string lang = config.getStringValue("lang");
88  if (lang.empty())
89  {
90  const char *const lng = getLangName();
91  if (lng == nullptr)
92  return "";
93  return lng;
94  }
95  else if (lang.size() > 1000)
96  {
97  return "";
98  }
99  return lang;
100 }

References config, getLangName(), and Configuration::getStringValue().

Referenced by Ea::NpcRecv::processNpcStrInput().

◆ getServerLang()

LangVect getServerLang ( )

Definition at line 68 of file langs.cpp.

69 {
70  LangVect langs;
71 #ifndef DYECMD
72  const int id = PlayerInfo::getServerLanguage();
73  const std::string &lang = LanguageDb::getPo(id);
74  if (lang.empty())
75  return langs;
76  langs.push_back(lang);
77  const size_t idx = lang.find('_');
78  if (idx != std::string::npos)
79  langs.push_back(lang.substr(0, idx));
80 #endif // DYECMD
81 
82  return langs;
83 }
const std::string & getPo(const int id)
Definition: languagedb.cpp:119
int getServerLanguage()
Definition: playerinfo.cpp:677

References LanguageDb::getPo(), and PlayerInfo::getServerLanguage().

Referenced by TranslationManager::loadDictionaryLang().