diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-02 22:54:36 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-03 00:46:28 +0300 |
commit | 519c2796e52ea933f6de5a490aee1f1ab826ea5e (patch) | |
tree | 01205558a568663d1c1ff67fda39ee84ce4051ec /src/utils | |
parent | 2d2bbb2fe5a0dc55cbf5b9616a78500704b6ea65 (diff) | |
download | plus-519c2796e52ea933f6de5a490aee1f1ab826ea5e.tar.gz plus-519c2796e52ea933f6de5a490aee1f1ab826ea5e.tar.bz2 plus-519c2796e52ea933f6de5a490aee1f1ab826ea5e.tar.xz plus-519c2796e52ea933f6de5a490aee1f1ab826ea5e.zip |
Add support for custom NLS (without gettext).
Add configure flag --enable-customnls
Add empty directory in data/translations/manaplus for suctom translations
(po files from /po directory)
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/gettext.h | 14 | ||||
-rw-r--r-- | src/utils/gettexthelper.cpp | 8 | ||||
-rw-r--r-- | src/utils/translation/podict.cpp | 3 | ||||
-rw-r--r-- | src/utils/translation/podict.h | 3 | ||||
-rw-r--r-- | src/utils/translation/translationmanager.cpp | 8 | ||||
-rw-r--r-- | src/utils/translation/translationmanager.h | 4 |
6 files changed, 36 insertions, 4 deletions
diff --git a/src/utils/gettext.h b/src/utils/gettext.h index 392980fe8..d4b8938b5 100644 --- a/src/utils/gettext.h +++ b/src/utils/gettext.h @@ -34,12 +34,22 @@ #define _(s) (const_cast <char*>(gettext(s))) #define N_(s) (const_cast <char*>(s)) -#else +#elif defined(ENABLE_CUSTOMNLS) // ENABLE_NLS + +#include "utils/translation/podict.h" + +#define gettext(s) const_cast <char*>(mainTranslator->getChar(s)) +#define _(s) const_cast <char*>(mainTranslator->getChar(s)) +#define N_(s) (const_cast <char*>(s)) +#define ngettext(s1, s2, i1) const_cast <char*>(mainTranslator->getChar(s1)) + +#else // ENABLE_NLS + #define gettext(s) (const_cast <char*>(s)) #define _(s) (const_cast <char*>(s)) #define N_(s) (const_cast <char*>(s)) #define ngettext(s1, s2, i1) (const_cast <char*>(s1)) -#endif +#endif // ENABLE_NLS #endif // UTILS_GETTEXT_H diff --git a/src/utils/gettexthelper.cpp b/src/utils/gettexthelper.cpp index c93e0d97d..336cd3307 100644 --- a/src/utils/gettexthelper.cpp +++ b/src/utils/gettexthelper.cpp @@ -33,8 +33,10 @@ #ifdef WIN32 #include <string> extern "C" char const *_nl_locale_name_default(void); -#endif -#endif +#endif // WIN32 +#elif defined(ENABLE_CUSTOMNLS) +#include "utils/translation/podict.h" +#endif // ENABLE_NLS #include "debug.h" @@ -97,6 +99,8 @@ void GettextHelper::initLang() } bind_textdomain_codeset("manaplus", "UTF-8"); textdomain("manaplus"); +#elif defined(ENABLE_CUSTOMNLS) + mainTranslator = new PoDict("en"); #endif // ENABLE_NLS } diff --git a/src/utils/translation/podict.cpp b/src/utils/translation/podict.cpp index 8aca50880..ba199a6d6 100644 --- a/src/utils/translation/podict.cpp +++ b/src/utils/translation/podict.cpp @@ -25,6 +25,9 @@ std::string empty; PoDict *translator = nullptr; +#ifdef ENABLE_CUSTOMNLS +PoDict *mainTranslator = nullptr; +#endif PoDict::PoDict(std::string lang) : mPoLines(), diff --git a/src/utils/translation/podict.h b/src/utils/translation/podict.h index 4153835bd..73948aeb4 100644 --- a/src/utils/translation/podict.h +++ b/src/utils/translation/podict.h @@ -61,5 +61,8 @@ class PoDict final }; extern PoDict *translator; +#ifdef ENABLE_CUSTOMNLS +extern PoDict *mainTranslator; +#endif #endif // UTILS_TRANSLATION_PODICT_H diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp index 01f38e57f..4fa233990 100644 --- a/src/utils/translation/translationmanager.cpp +++ b/src/utils/translation/translationmanager.cpp @@ -44,6 +44,14 @@ void TranslationManager::loadCurrentLang() translator = loadLang(getLang(), "help/", translator); } +#ifdef ENABLE_CUSTOMNLS +void TranslationManager::loadGettextLang() +{ + delete mainTranslator; + mainTranslator = loadLang(getLang(), "manaplus/"); +} +#endif + void TranslationManager::close() { delete2(translator); diff --git a/src/utils/translation/translationmanager.h b/src/utils/translation/translationmanager.h index e6e56dd4a..e228b1e75 100644 --- a/src/utils/translation/translationmanager.h +++ b/src/utils/translation/translationmanager.h @@ -41,6 +41,10 @@ class TranslationManager final static void loadCurrentLang(); +#ifdef ENABLE_CUSTOMNLS + static void loadGettextLang(); +#endif + static bool translateFile(const std::string &fileName, PoDict *const dict, StringVect &lines); |