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:
parent
3b842a7e02
commit
24b66dede0
5 changed files with 35 additions and 38 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue