ManaPlus
Static Public Member Functions | Static Private Member Functions
GettextHelper Class Reference

#include <gettexthelper.h>

Static Public Member Functions

static void initLang ()
 

Static Private Member Functions

static void bindTextDomain (const char *const path)
 

Detailed Description

Definition at line 31 of file gettexthelper.h.

Member Function Documentation

◆ bindTextDomain()

void GettextHelper::bindTextDomain ( const char *const  path)
staticprivate

Definition at line 142 of file gettexthelper.cpp.

143 {
144  const char *const dir = bindtextdomain("manaplus", path);
145  if (dir)
146  logger->log("bindtextdomain: %s", dir);
147  else
148  logger->log("bindtextdomain failed");
149 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References Logger::log(), and logger.

Referenced by initLang().

◆ initLang()

void GettextHelper::initLang ( )
static

Definition at line 87 of file gettexthelper.cpp.

88 {
89 #ifdef ENABLE_NLS
90  const std::string lang = setLangEnv();
91 #ifdef WIN32
92  // mingw doesn't like LOCALEDIR to be defined for some reason
93  if (lang != "C")
94  bindTextDomain("translations/");
95 #else // WIN32
96 #ifdef ANDROID
97 #ifdef USE_SDL2
98  bindTextDomain((std::string(getenv("APPDIR")).append("/locale")).c_str());
99 #else // USE_SDL2
100 
101  bindTextDomain((std::string(VirtFs::getBaseDir()).append(
102  "/locale")).c_str());
103 #endif // USE_SDL2
104 #else // ANDROID
105 #ifdef ENABLE_PORTABLE
106  bindTextDomain((std::string(VirtFs::getBaseDir()).append(
107  "../locale/")).c_str());
108 #else // ENABLE_PORTABLE
109 #ifdef __APPLE__
110  bindTextDomain((std::string(VirtFs::getBaseDir())
111  .append("ManaPlus.app/Contents/Resources/locale/")).c_str());
112 #else // __APPLE__
113 
114  bindTextDomain(LOCALEDIR);
115 #endif // __APPLE__
116 #endif // ENABLE_PORTABLE
117 #endif // ANDROID
118 #endif // WIN32
119 
120  char *locale = setlocale(LC_MESSAGES, lang.c_str());
121  if (locale)
122  {
123  logger->log("locale: %s", locale);
124  }
125  else
126  {
127  locale = setlocale(LC_MESSAGES, (lang + ".utf8").c_str());
128  if (locale)
129  logger->log("locale: %s", locale);
130  else
131  logger->log("locale empty");
132  }
133  bind_textdomain_codeset("manaplus", "UTF-8");
134  textdomain("manaplus");
135 #elif defined(ENABLE_CUSTOMNLS)
136  mainTranslator = new PoDict("en");
137  setLangEnv();
138 #endif // ENABLE_NLS
139 }
static void bindTextDomain(const char *const path)
Definition: podict.h:33
static std::string setLangEnv()
const char * getBaseDir()
Definition: fs.cpp:79

References bindTextDomain(), VirtFs::getBaseDir(), Logger::log(), logger, and setLangEnv().

Referenced by Client::gameInit().


The documentation for this class was generated from the following files: