Skip to content

Commit

Permalink
Made vgettext/vngetext internals harder to use accidentally (resolves #…
Browse files Browse the repository at this point in the history
…2716)

Also removed the two implementation function overloads that did not take a textdomain.

(cherry-picked from commit aad64d7)
  • Loading branch information
Vultraz committed Oct 7, 2018
1 parent adaa115 commit b239ac4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
23 changes: 7 additions & 16 deletions src/formula/string_utils.cpp
Expand Up @@ -281,31 +281,22 @@ std::string format_disjunct_list(const t_string& empty, const std::vector<t_stri

}

std::string vgettext(const char *msgid, const utils::string_map& symbols)
{
const std::string orig(_(msgid));
const std::string msg = utils::interpolate_variables_into_string(orig, &symbols);
return msg;
}

std::string vgettext(const char *domain
std::string vgettext_impl(const char *domain
, const char *msgid
, const utils::string_map& symbols)
{
const std::string orig(translation::dsgettext(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));
const std::string msg = utils::interpolate_variables_into_string(orig, &symbols);
return msg;
}

std::string vngettext(const char *domain, const char *sing, const char* plur, int n, const utils::string_map& symbols)
std::string vngettext_impl(const char* domain,
const char* singular,
const char* plural,
int count,
const utils::string_map& symbols)
{
const std::string orig(translation::dsngettext(domain, sing, plur, n));
const std::string orig(translation::dsngettext(domain, singular, plural, count));
const std::string msg = utils::interpolate_variables_into_string(orig, &symbols);
return msg;
}
35 changes: 22 additions & 13 deletions src/formula/string_utils.hpp
Expand Up @@ -76,23 +76,32 @@ std::string format_disjunct_list(const t_string& empty, const std::vector<t_stri

}

/** Handy wrappers around interpolate_variables_into_string and gettext. */
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);
/**
* Implementation functions for the VGETTEXT and VNGETTEXT macros.
*
* DO NOT USE DIRECTLY unless you really know what you're doing.
* See https://github.com/wesnoth/wesnoth/issues/2716 for more info.
*/

std::string vngettext(const char*, const char*, int, const utils::string_map&);
std::string vgettext_impl(const char* domain, const char* msgid, const utils::string_map& symbols);

std::string vngettext(const char*, const char*, const char*, int, const utils::string_map&);
std::string vngettext_impl(const char* domain,
const char* singular,
const char* plural,
int count,
const utils::string_map& symbols);

/**
* @todo Convert all functions.
* Handy wrappers around interpolate_variables_into_string and gettext.
*
* 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.
* These should cover most usecases. If you're not sure whether you want
* these macros or their implementation functions, use these. The only time
* you should need to use the implementation functions directly is to pass a
* different textdomain than the current value of GETTEXT_DOMAIN.
*/

#define VGETTEXT(msgid, ...) vgettext(GETTEXT_DOMAIN, msgid, __VA_ARGS__)
#define VNGETTEXT(msgid, msgid_plural, count, ...) vngettext(GETTEXT_DOMAIN, msgid, msgid_plural, count, __VA_ARGS__)
#define VGETTEXT(msgid, ...) \
vgettext_impl(GETTEXT_DOMAIN, msgid, __VA_ARGS__)

#define VNGETTEXT(msgid, msgid_plural, count, ...) \
vngettext_impl(GETTEXT_DOMAIN, msgid, msgid_plural, count, __VA_ARGS__)

0 comments on commit b239ac4

Please sign in to comment.