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

@ -0,0 +1,26 @@
local S, NS = minetest.get_translator("testtranslations")
local function send_compare(name, text)
core.chat_send_player(name, ("%s | %s | %s"):format(
core.get_translated_string("", text), text, core.get_translated_string("fr", text)))
end
minetest.register_chatcommand("testtranslations", {
params = "",
description = "Test translations",
privs = {},
func = function(name, param)
core.chat_send_player(name, "Please ensure your locale is set to \"fr\"")
core.chat_send_player(name, "Untranslated | Client-side translation | Server-side translation (fr)")
send_compare(name, S("Testing .tr files: untranslated"))
send_compare(name, S("Testing .po files: untranslated"))
send_compare(name, S("Testing .mo files: untranslated"))
send_compare(name, S("Testing fuzzy .po entry: untranslated (expected)"))
send_compare(name, core.translate("translation_po", "Testing .po without context: untranslated"))
send_compare(name, core.translate("translation_mo", "Testing .mo without context: untranslated"))
for i = 0,4 do
send_compare(name, NS("@1: .po singular", "@1: .po plural", i, tostring(i)))
send_compare(name, NS("@1: .mo singular", "@1: .mo plural", i, tostring(i)))
end
end
})

View file

@ -0,0 +1,9 @@
# Dummy entry. This is a test to make sure that a parser error is not thrown
# if the following line is msgctxt.
msgctxt "testtranslations"
msgid "Dummy entry"
msgstr "Dummy result"
# Used for translating the mod title
msgid "Test translations"
msgstr "Test translations (French)"

View file

@ -0,0 +1,22 @@
# Test Plural-Forms parsing
msgid ""
msgstr ""
"Plural-Forms: nplurals=2; plural= (n-1+1)<=1 ? n||1?0:1 : 1?(!!2):2;"
msgctxt "testtranslations"
msgid "Testing .po files: untranslated"
msgstr "Testing .po files: translated"
msgctxt "testtranslations"
msgid "@1: .po singular"
msgid_plural "@1: .po plural"
msgstr[0] "@1: .po 0 and 1 (French singular)"
msgstr[1] "@1: .po >1 (French plural)"
#, foo bar fuzzy
msgctxt "testtranslations"
msgid "Testing fuzzy .po entry: untranslated (expected)"
msgstr "Testing fuzzy .po entry: translated (wrong)"
msgid "Testing .po without context: untranslated"
msgstr "Testing .po without context: translated"

View file

@ -0,0 +1,2 @@
# textdomain: testtranslations
Testing .tr files: untranslated=Testing .tr files: translated

View file

@ -0,0 +1,3 @@
name = testtranslations
title = Test translations
description = Test mod to test translations.

View file

@ -0,0 +1,4 @@
The translation files in this directory intentionally include errors (which
would be reported when someone starts the devtest game in the de locale). This
allows the unittest to check that the translation file reader also handles
files that include errors.

View file

@ -0,0 +1,42 @@
# This file is used by the C++ unittest for testing the parser
msgid ""
msgstr "\n\n\n"
"Plural-Forms: nplurals=2; plural=n!=1;"
"\n\n\n"
msgid "foo"
msgstr "bar"
msgid "Untranslated"
msgstr ""
#, fuzzy
msgid "Fuzzy entry"
msgstr "Wrong"
msgid "Multi\\""line\n"
"string"
msgstr "Multi\\\"" "li\\ne\nresult"
msgctxt "Something" in "between"
msgctxt "String does not end
msgstr "Lost string"
msgid "Wrong order"
msgid "Singular form"
msgid_plural "Plural form"
msgstr[0] "Singular result"
msgstr[1] "Plural result"
msgid "Not enough value"
msgid_plural "Not enough values"
msgstr[0] "Result"
msgid "Partial translation"
msgid_plural "Partial translations"
msgstr[0] "Partially translated"
msgstr[1] ""
msgctxt "context"
msgid "With context"
msgstr "Has context"

View file

@ -0,0 +1,26 @@
msgid ""
msgstr "Plural-Forms: nplurals=2; plural= n != 1;"
msgctxt "context"
msgid "With context"
msgstr "Has context"
msgctxt "context"
msgid "Singular form"
msgid_plural "Plural form"
msgstr[0] "Singular result"
msgstr[1] "Plural result"
# Replace plural form delimiter in the msgstr
msgid "Corrupt singular"
msgid_plural "Corrupt plural"
msgstr[0] "Corrupt singular result"
msgstr[1] "Corrupt plural result"
# Replace terminating NUL in the MO file
msgid "Corrupt entry"
msgstr "Corrupted result"
# Change the address of this entry to something invalid
msgid "Removed entry"
msgstr "Removed result"

View file

@ -0,0 +1,18 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n>1;"
msgctxt "testtranslations"
msgid "Testing .mo files: untranslated"
msgstr "Testing .mo files: translated"
msgid "Testing .mo without context: untranslated"
msgstr "Testing .mo without context: translated"
msgctxt "testtranslations"
msgid "@1: .mo singular"
msgid_plural "@1: .mo plural"
msgstr[0] "@1: .mo 0 and 1 (French singular)"
msgstr[1] "@1: .mo >1 (French plural)"