mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +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
33
src/gettext_plural_form.h
Normal file
33
src/gettext_plural_form.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Minetest
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
#include <memory>
|
||||
|
||||
// Note that this only implements a subset of C expressions. See:
|
||||
// https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y
|
||||
class GettextPluralForm
|
||||
{
|
||||
public:
|
||||
using NumT = unsigned long;
|
||||
using Ptr = std::shared_ptr<GettextPluralForm>;
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return nplurals;
|
||||
};
|
||||
virtual NumT operator()(const NumT) const = 0;
|
||||
virtual operator bool() const
|
||||
{
|
||||
return size() > 0;
|
||||
}
|
||||
virtual ~GettextPluralForm() {};
|
||||
|
||||
static GettextPluralForm::Ptr parse(const size_t nplurals, const std::wstring_view &str);
|
||||
static GettextPluralForm::Ptr parseHeaderLine(const std::wstring_view &str);
|
||||
protected:
|
||||
GettextPluralForm(size_t nplurals): nplurals(nplurals) {};
|
||||
private:
|
||||
const size_t nplurals;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue