summaryrefslogtreecommitdiff
path: root/src/utils/gettexthelper.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-03 14:42:53 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-03 14:42:53 +0300
commite8b094fae57ac2257751e573bb8e7eb1bef35d5b (patch)
tree38416f310faf71797a3e2ca5c6d3627b33f8a2ab /src/utils/gettexthelper.cpp
parent519c2796e52ea933f6de5a490aee1f1ab826ea5e (diff)
downloadmanaplus-e8b094fae57ac2257751e573bb8e7eb1bef35d5b.tar.gz
manaplus-e8b094fae57ac2257751e573bb8e7eb1bef35d5b.tar.bz2
manaplus-e8b094fae57ac2257751e573bb8e7eb1bef35d5b.tar.xz
manaplus-e8b094fae57ac2257751e573bb8e7eb1bef35d5b.zip
Auto set default language from chrome ui (nacl).
Diffstat (limited to 'src/utils/gettexthelper.cpp')
-rw-r--r--src/utils/gettexthelper.cpp60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/utils/gettexthelper.cpp b/src/utils/gettexthelper.cpp
index 336cd3307..3d70ae3dd 100644
--- a/src/utils/gettexthelper.cpp
+++ b/src/utils/gettexthelper.cpp
@@ -20,12 +20,12 @@
#include "utils/gettexthelper.h"
+#include "configuration.h"
+
#ifdef ENABLE_NLS
#include "client.h"
-#include "configuration.h"
#include "logger.h"
-#include "utils/env.h"
#include "utils/physfstools.h"
#include <libintl.h>
@@ -36,30 +36,63 @@ extern "C" char const *_nl_locale_name_default(void);
#endif // WIN32
#elif defined(ENABLE_CUSTOMNLS)
#include "utils/translation/podict.h"
+#ifdef __native_client__
+#include "utils/naclmessages.h"
+#endif // __native_client__
#endif // ENABLE_NLS
+#if defined(ENABLE_NLS) || defined(ENABLE_CUSTOMNLS) && !defined(WIN32)
+#include "utils/env.h"
+#endif // defined(ENABLE_NLS) || defined(ENABLE_CUSTOMNLS) && !defined(WIN32)
+
#include "debug.h"
-void GettextHelper::initLang()
+static std::string setLangEnv()
{
-#ifdef ENABLE_NLS
std::string lang = config.getStringValue("lang");
-#ifdef WIN32
+#if defined(ENABLE_NLS) && defined(WIN32)
if (lang.empty())
lang = std::string(_nl_locale_name_default());
+#elif defined(ENABLE_CUSTOMNLS) && defined(__native_client__)
+ if (lang.empty())
+ {
+ NaclMessageHandle *handle = naclRegisterMessageHandler(
+ "get-uilanguage");
+ naclPostMessage("get-uilanguage", "");
+ lang = naclWaitForMessage(handle);
+ }
+#endif // defined(ENABLE_NLS) && defined(WIN32)
- putenv(const_cast<char*>(("LANG=" + lang).c_str()));
- putenv(const_cast<char*>(("LANGUAGE=" + lang).c_str()));
+#if defined(ENABLE_NLS) || defined(ENABLE_CUSTOMNLS)
+ if (!lang.empty())
+ {
+#ifdef WIN32
+ putenv(const_cast<char*>(("LANG=" + lang).c_str()));
+ putenv(const_cast<char*>(("LANGUAGE=" + lang).c_str()));
+#else // WIN32
+
+ if (!lang.empty())
+ {
+ setEnv("LANG", lang.c_str());
+ setEnv("LANGUAGE", lang.c_str());
+ }
+#endif // WIN32
+
+ }
+#endif // defined(ENABLE_NLS) || defined(ENABLE_CUSTOMNLS)
+
+ return lang;
+}
+
+void GettextHelper::initLang()
+{
+#ifdef ENABLE_NLS
+ const std::string lang = setLangEnv();
+#ifdef WIN32
// mingw doesn't like LOCALEDIR to be defined for some reason
if (lang != "C")
bindTextDomain("translations/");
#else // WIN32
-
- if (!lang.empty())
- {
- setEnv("LANG", lang.c_str());
- setEnv("LANGUAGE", lang.c_str());
- }
#ifdef ANDROID
#ifdef USE_SDL2
bindTextDomain((std::string(getenv("APPDIR")).append("/locale")).c_str());
@@ -101,6 +134,7 @@ void GettextHelper::initLang()
textdomain("manaplus");
#elif defined(ENABLE_CUSTOMNLS)
mainTranslator = new PoDict("en");
+ setLangEnv();
#endif // ENABLE_NLS
}