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

View file

@ -2537,8 +2537,8 @@ bool Server::addMediaFile(const std::string &filename,
".png", ".jpg", ".bmp", ".tga",
".ogg",
".x", ".b3d", ".obj", ".gltf", ".glb",
// Custom translation file format
".tr",
// Translation file formats
".tr", ".po", ".mo",
NULL
};
if (removeStringEnd(filename, supported_ext).empty()) {
@ -2621,14 +2621,20 @@ void Server::fillMediaCache()
void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_code)
{
std::string lang_suffix = ".";
lang_suffix.append(lang_code).append(".tr");
std::string translation_formats[3] = { ".tr", ".po", ".mo" };
std::string lang_suffixes[3];
for (size_t i = 0; i < 3; i++) {
lang_suffixes[i].append(".").append(lang_code).append(translation_formats[i]);
}
auto include = [&] (const std::string &name, const MediaInfo &info) -> bool {
auto include = [&] (const std::string &name, const MediaInfo &info) -> bool {
if (info.no_announce)
return false;
if (str_ends_with(name, ".tr") && !str_ends_with(name, lang_suffix))
return false;
for (size_t j = 0; j < 3; j++) {
if (str_ends_with(name, translation_formats[j]) && !str_ends_with(name, lang_suffixes[j])) {
return false;
}
}
return true;
};
@ -4167,12 +4173,11 @@ Translations *Server::getTranslationLanguage(const std::string &lang_code)
// [] will create an entry
auto *translations = &server_translations[lang_code];
std::string suffix = "." + lang_code + ".tr";
for (const auto &i : m_media) {
if (str_ends_with(i.first, suffix)) {
if (Translations::getFileLanguage(i.first) == lang_code) {
std::string data;
if (fs::ReadFile(i.second.path, data, true)) {
translations->loadTranslation(data);
translations->loadTranslation(i.first, data);
}
}
}