From 519c2796e52ea933f6de5a490aee1f1ab826ea5e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 2 Jan 2016 22:54:36 +0300 Subject: 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) --- configure.ac | 11 +++++++++++ data/translations/manaplus/README | 3 +++ src/Makefile.am | 5 +++++ src/client.cpp | 4 ++++ src/dyetool/client.cpp | 3 +++ src/utils/gettext.h | 14 ++++++++++++-- src/utils/gettexthelper.cpp | 8 ++++++-- src/utils/translation/podict.cpp | 3 +++ src/utils/translation/podict.h | 3 +++ src/utils/translation/translationmanager.cpp | 8 ++++++++ src/utils/translation/translationmanager.h | 4 ++++ 11 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 data/translations/manaplus/README diff --git a/configure.ac b/configure.ac index e6857f0f7..a27b69c19 100755 --- a/configure.ac +++ b/configure.ac @@ -409,6 +409,17 @@ esac],[checkplugin_enabled=false]) AM_CONDITIONAL(ENABLE_CHECKPLUGIN, test x$checkplugin_enabled = xtrue) +# Enable custom NLS +AC_ARG_ENABLE(customnls, +[ --enable-customnls Turn on build in translation system (NLS)], +[case "${enableval}" in + yes) customnls_enabled=true ;; + no) customnls_enabled=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-customnls) ;; +esac],[customnls_enabled=false]) + +AM_CONDITIONAL(ENABLE_CUSTOMNLS, test x$customnls_enabled = xtrue) + if test "x$naclbuild_enabled" == "xtrue"; then AC_CHECK_SDL() fi diff --git a/data/translations/manaplus/README b/data/translations/manaplus/README new file mode 100644 index 000000000..202548517 --- /dev/null +++ b/data/translations/manaplus/README @@ -0,0 +1,3 @@ +Put here manaplus po files if you want use custom NLS. + +See configure flag --enable-customnls \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am index 183e7730c..cf4280eca 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,11 @@ dyecmd_CXXFLAGS += -DENABLE_PORTABLE manaplus_CXXFLAGS += -DENABLE_PORTABLE endif +if ENABLE_CUSTOMNLS +dyecmd_CXXFLAGS += -DENABLE_CUSTOMNLS +manaplus_CXXFLAGS += -DENABLE_CUSTOMNLS +endif + if ENABLE_CHECKPLUGIN dyecmd_CXXFLAGS += -DENABLE_CHECKPLUGIN -fplugin=../build/checkplugin.so -fplugin-arg-checkplugin-command=detectnullpointers manaplus_CXXFLAGS += -DENABLE_CHECKPLUGIN -fplugin=../build/checkplugin.so -fplugin-arg-checkplugin-command=detectnullpointers diff --git a/src/client.cpp b/src/client.cpp index 04262b45c..6506c9241 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -246,6 +246,7 @@ void Client::testsInit() Dirs::initLocalDataDir(); Dirs::initTempDir(); Dirs::initConfigDir(); + GettextHelper::initLang(); } } @@ -376,6 +377,9 @@ void Client::gameInit() // Add the local data directory to PhysicsFS search path resourceManager->addToSearchPath(settings.localDataDir, Append_false); TranslationManager::loadCurrentLang(); +#ifdef ENABLE_CUSTOMNLS + TranslationManager::loadGettextLang(); +#endif WindowManager::initTitle(); diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp index d6d918662..8812b770b 100644 --- a/src/dyetool/client.cpp +++ b/src/dyetool/client.cpp @@ -255,6 +255,9 @@ void Client::gameInit() // Add the local data directory to PhysicsFS search path resourceManager->addToSearchPath(settings.localDataDir, Append_false); TranslationManager::loadCurrentLang(); +#ifdef ENABLE_CUSTOMNLS + TranslationManager::loadGettextLang(); +#endif WindowManager::initTitle(); 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 (gettext(s))) #define N_(s) (const_cast (s)) -#else +#elif defined(ENABLE_CUSTOMNLS) // ENABLE_NLS + +#include "utils/translation/podict.h" + +#define gettext(s) const_cast (mainTranslator->getChar(s)) +#define _(s) const_cast (mainTranslator->getChar(s)) +#define N_(s) (const_cast (s)) +#define ngettext(s1, s2, i1) const_cast (mainTranslator->getChar(s1)) + +#else // ENABLE_NLS + #define gettext(s) (const_cast (s)) #define _(s) (const_cast (s)) #define N_(s) (const_cast (s)) #define ngettext(s1, s2, i1) (const_cast (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 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); -- cgit v1.2.3-60-g2f50