1
0
Fork 0
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:
y5nw 2024-10-13 11:29:08 +02:00 committed by GitHub
parent dbbe0ca065
commit e3aa79cffb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 1360 additions and 74 deletions

33
src/gettext_plural_form.h Normal file
View 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;
};