Allow translating in UTF8
This commit is contained in:
parent
3a6038fc67
commit
4bc85a6179
@ -567,6 +567,38 @@ irr::core::stringw Translations::w_gettext(const char* original, const char* con
|
||||
|
||||
} // w_gettext
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/**
|
||||
* \param original Message to translate
|
||||
* \param context Optional, can be set to differentiate 2 strings that are identical
|
||||
* in English but could be different in other languages
|
||||
*/
|
||||
std::string Translations::gettext(const char* original, const char* context)
|
||||
{
|
||||
|
||||
#ifdef SERVER_ONLY
|
||||
return "";
|
||||
#else
|
||||
|
||||
if (original[0] == '\0') return "";
|
||||
|
||||
#if TRANSLATE_VERBOSE
|
||||
Log::info("Translations", "Translating %s", original);
|
||||
#endif
|
||||
|
||||
const std::string& original_t = (context == NULL ?
|
||||
m_dictionary->translate(original) :
|
||||
m_dictionary->translate_ctxt(context, original));
|
||||
|
||||
#if TRANSLATE_VERBOSE
|
||||
std::cout << " translation : " << original_t << std::endl;
|
||||
#endif
|
||||
|
||||
return original_t;
|
||||
#endif
|
||||
|
||||
} // gettext
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/**
|
||||
* \param singular Message to translate in singular form
|
||||
@ -614,6 +646,34 @@ irr::core::stringw Translations::w_ngettext(const char* singular, const char* pl
|
||||
|
||||
} // w_ngettext
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/**
|
||||
* \param singular Message to translate in singular form
|
||||
* \param plural Message to translate in plural form (can be the same as the singular form)
|
||||
* \param num Count used to obtain the correct plural form.
|
||||
* \param context Optional, can be set to differentiate 2 strings that are identical
|
||||
* in English but could be different in other languages
|
||||
*/
|
||||
std::string Translations::ngettext(const char* singular, const char* plural, int num, const char* context)
|
||||
{
|
||||
#ifdef SERVER_ONLY
|
||||
return "";
|
||||
|
||||
#else
|
||||
|
||||
const std::string& res = (context == NULL ?
|
||||
m_dictionary->translate_plural(singular, plural, num) :
|
||||
m_dictionary->translate_ctxt_plural(context, singular, plural, num));
|
||||
|
||||
#if TRANSLATE_VERBOSE
|
||||
std::cout << " translation: " << res << std::endl;
|
||||
#endif
|
||||
|
||||
return res;
|
||||
#endif
|
||||
|
||||
} // ngettext
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef SERVER_ONLY
|
||||
std::set<unsigned int> Translations::getCurrentAllChar()
|
||||
|
@ -31,12 +31,20 @@
|
||||
#include "tinygettext/tinygettext.hpp"
|
||||
#endif
|
||||
|
||||
# define _(String, ...) (StringUtils::insertValues(translations->w_gettext(String), ##__VA_ARGS__))
|
||||
#ifdef STK_UTF8_GETTEXT
|
||||
#define STK_GETTEXT gettext
|
||||
#define STK_NGETTEXT ngettext
|
||||
#else
|
||||
#define STK_GETTEXT w_gettext
|
||||
#define STK_NGETTEXT w_ngettext
|
||||
#endif
|
||||
|
||||
# define _(String, ...) (StringUtils::insertValues(translations->STK_GETTEXT(String), ##__VA_ARGS__))
|
||||
#undef _C
|
||||
#undef _P
|
||||
# define _C(Ctx, String, ...) (StringUtils::insertValues(translations->w_gettext(String, Ctx), ##__VA_ARGS__))
|
||||
# define _P(Singular, Plural, Num, ...) (StringUtils::insertValues(translations->w_ngettext(Singular, Plural, Num), Num, ##__VA_ARGS__))
|
||||
# define _CP(Ctx, Singular, Plural, Num, ...) (StringUtils::insertValues(translations->w_ngettext(Singular, Plural, Num, Ctx), Num, ##__VA_ARGS__))
|
||||
# define _C(Ctx, String, ...) (StringUtils::insertValues(translations->STK_GETTEXT(String, Ctx), ##__VA_ARGS__))
|
||||
# define _P(Singular, Plural, Num, ...) (StringUtils::insertValues(translations->STK_NGETTEXT(Singular, Plural, Num), Num, ##__VA_ARGS__))
|
||||
# define _CP(Ctx, Singular, Plural, Num, ...) (StringUtils::insertValues(translations->STK_NGETTEXT(Singular, Plural, Num, Ctx), Num, ##__VA_ARGS__))
|
||||
# define gettext_noop(String) (String)
|
||||
# define N_(String) (gettext_noop (String))
|
||||
// libintl defines its own fprintf, which doesn't work properly
|
||||
@ -64,9 +72,11 @@ public:
|
||||
|
||||
irr::core::stringw w_gettext(const wchar_t* original, const char* context=NULL);
|
||||
irr::core::stringw w_gettext(const char* original, const char* context=NULL);
|
||||
std::string gettext(const char* original, const char* context=NULL);
|
||||
|
||||
irr::core::stringw w_ngettext(const wchar_t* singular, const wchar_t* plural, int num, const char* context=NULL);
|
||||
irr::core::stringw w_ngettext(const char* singular, const char* plural, int num, const char* context=NULL);
|
||||
std::string ngettext(const char* singular, const char* plural, int num, const char* context=NULL);
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
const std::vector<std::string>* getLanguageList() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user