mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Gettext and plural support for client-side translations (#14726)
--------- Co-authored-by: Ekdohibs <nathanael.courant@laposte.net> Co-authored-by: y5nw <y5nw@protonmail.com> Co-authored-by: rubenwardy <rw@rubenwardy.com>
This commit is contained in:
parent
dbbe0ca065
commit
e3aa79cffb
28 changed files with 1360 additions and 74 deletions
|
@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cctype>
|
||||
#include <cwctype>
|
||||
#include <unordered_map>
|
||||
|
||||
class Translations;
|
||||
|
@ -87,6 +88,8 @@ struct FlagDesc {
|
|||
std::wstring utf8_to_wide(std::string_view input);
|
||||
std::string wide_to_utf8(std::wstring_view input);
|
||||
|
||||
void wide_add_codepoint(std::wstring &result, char32_t codepoint);
|
||||
|
||||
std::string urlencode(std::string_view str);
|
||||
std::string urldecode(std::string_view str);
|
||||
|
||||
|
@ -325,19 +328,30 @@ inline std::string lowercase(std::string_view str)
|
|||
}
|
||||
|
||||
|
||||
inline bool my_isspace(const char c)
|
||||
{
|
||||
return std::isspace(c);
|
||||
}
|
||||
|
||||
inline bool my_isspace(const wchar_t c)
|
||||
{
|
||||
return std::iswspace(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param str
|
||||
* @return A view of \p str with leading and trailing whitespace removed.
|
||||
*/
|
||||
inline std::string_view trim(std::string_view str)
|
||||
template<typename T>
|
||||
inline std::basic_string_view<T> trim(const std::basic_string_view<T> &str)
|
||||
{
|
||||
size_t front = 0;
|
||||
size_t back = str.size();
|
||||
|
||||
while (front < back && std::isspace(str[front]))
|
||||
while (front < back && my_isspace(str[front]))
|
||||
++front;
|
||||
|
||||
while (back > front && std::isspace(str[back - 1]))
|
||||
while (back > front && my_isspace(str[back - 1]))
|
||||
--back;
|
||||
|
||||
return str.substr(front, back - front);
|
||||
|
@ -351,16 +365,24 @@ inline std::string_view trim(std::string_view str)
|
|||
* @param str
|
||||
* @return A copy of \p str with leading and trailing whitespace removed.
|
||||
*/
|
||||
inline std::string trim(std::string &&str)
|
||||
template<typename T>
|
||||
inline std::basic_string<T> trim(std::basic_string<T> &&str)
|
||||
{
|
||||
std::string ret(trim(std::string_view(str)));
|
||||
std::basic_string<T> ret(trim(std::basic_string_view<T>(str)));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// The above declaration causes ambiguity with char pointers so we have to fix that:
|
||||
inline std::string_view trim(const char *str)
|
||||
template<typename T>
|
||||
inline std::basic_string_view<T> trim(const std::basic_string<T> &str)
|
||||
{
|
||||
return trim(std::string_view(str));
|
||||
return trim(std::basic_string_view<T>(str));
|
||||
}
|
||||
|
||||
// The above declaration causes ambiguity with char pointers so we have to fix that:
|
||||
template<typename T>
|
||||
inline std::basic_string_view<T> trim(const T *str)
|
||||
{
|
||||
return trim(std::basic_string_view<T>(str));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue