Add a vgettext overload and macro.

This allows the usage of the vgettext function when the msgid isn't in
the default domain. This is needed for some vgettext calls in the lobby.

Post 1.8 some more polishing needs to be done, added a todo for it.
This commit is contained in:
Mark de Wever 2010-03-07 20:02:56 +00:00
parent 21d6b17e0c
commit 0ba3d05204
2 changed files with 27 additions and 1 deletions

View File

@ -212,6 +212,14 @@ std::string vgettext(const char *msgid, const utils::string_map& symbols)
return msg;
}
std::string vgettext(const char *domain
, const char *msgid
, const utils::string_map& symbols)
{
const std::string orig(dgettext(domain, msgid));
const std::string msg = utils::interpolate_variables_into_string(orig, &symbols);
return msg;
}
std::string vngettext(const char* sing, const char* plur, int n, const utils::string_map& symbols)
{
const std::string orig(_n(sing, plur, n));

View File

@ -31,7 +31,25 @@ std::string interpolate_variables_into_string(const std::string &str, const vari
}
/** Handy wrappers around interpolate_variables_into_string and gettext. */
std::string vgettext(const char*, const utils::string_map&);
std::string vgettext(const char* msgid, const utils::string_map& symbols);
std::string vgettext(const char* domain
, const char* msgid
, const utils::string_map& symbols);
std::string vngettext(const char*, const char*, int, const utils::string_map&);
/**
* @todo Convert all functions.
*
* All function in this file should have an overloaded version with a domain
* and probably convert all callers to use the macro instead of directly calling
* the function.
*/
#ifdef GETTEXT_DOMAIN
#define VGETTEXT(msgid, symbols) vgettext(GETTEXT_DOMAIN, msgid, symbols)
#else
#define VGETTEXT(msgid, symbols) vgettext(msgid, symbols)
#endif
#endif