mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
Localize error messages in mainmenu (#11495)
Co-authored-by: sfan5 <sfan5@live.de> Co-authored-by: rubenwardy <rw@rubenwardy.com>
This commit is contained in:
parent
6910c8d920
commit
693f98373b
8 changed files with 97 additions and 46 deletions
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "config.h" // for USE_GETTEXT
|
||||
#include <string>
|
||||
#include "porting.h"
|
||||
|
||||
#if USE_GETTEXT
|
||||
#include <libintl.h>
|
||||
|
@ -77,3 +78,31 @@ inline std::wstring fwgettext(const char *src, Args&&... args)
|
|||
delete[] str;
|
||||
return std::wstring(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns translated string with format args applied
|
||||
*
|
||||
* @tparam Args Template parameter for format args
|
||||
* @param format Translation source string
|
||||
* @param args Variable format args
|
||||
* @return translated string.
|
||||
*/
|
||||
template <typename ...Args>
|
||||
inline std::string fmtgettext(const char *format, Args&&... args)
|
||||
{
|
||||
std::string buf;
|
||||
std::size_t buf_size = 256;
|
||||
buf.resize(buf_size);
|
||||
|
||||
format = gettext(format);
|
||||
|
||||
int len = porting::mt_snprintf(&buf[0], buf_size, format, std::forward<Args>(args)...);
|
||||
if (len <= 0) throw std::runtime_error("gettext format error: " + std::string(format));
|
||||
if ((size_t)len >= buf.size()) {
|
||||
buf.resize(len+1); // extra null byte
|
||||
porting::mt_snprintf(&buf[0], buf.size(), format, std::forward<Args>(args)...);
|
||||
}
|
||||
buf.resize(len); // remove null bytes
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue