1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Add fwgettext util function

This commit is contained in:
rubenwardy 2021-08-19 19:13:25 +01:00 committed by GitHub
parent 3b842a7e02
commit 24b66dede0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 38 deletions

View file

@ -59,3 +59,21 @@ inline std::string strgettext(const std::string &text)
{
return text.empty() ? "" : gettext(text.c_str());
}
/**
* Returns translated string with format args applied
*
* @tparam Args Template parameter for format args
* @param src Translation source string
* @param args Variable format args
* @return translated string
*/
template <typename ...Args>
inline std::wstring fwgettext(const char *src, Args&&... args)
{
wchar_t buf[255];
const wchar_t* str = wgettext(src);
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, std::forward<Args>(args)...);
delete[] str;
return std::wstring(buf);
}