From d1e5b2418cbfbc85e69e0867a90087895f42a62b Mon Sep 17 00:00:00 2001 From: y5nw <37980625+y5nw@users.noreply.github.com> Date: Tue, 5 Mar 2024 13:49:28 +0100 Subject: [PATCH] Add unittests for server-side translations --- games/devtest/mods/unittests/init.lua | 1 + games/devtest/mods/unittests/locale/unittests.de.tr | 5 +++++ games/devtest/mods/unittests/locale/unittests.fr.tr | 5 +++++ games/devtest/mods/unittests/translations.lua | 13 +++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 games/devtest/mods/unittests/locale/unittests.de.tr create mode 100644 games/devtest/mods/unittests/locale/unittests.fr.tr create mode 100644 games/devtest/mods/unittests/translations.lua diff --git a/games/devtest/mods/unittests/init.lua b/games/devtest/mods/unittests/init.lua index edba2c3d2a8aa..f3738c41c8a78 100644 --- a/games/devtest/mods/unittests/init.lua +++ b/games/devtest/mods/unittests/init.lua @@ -182,6 +182,7 @@ dofile(modpath .. "/get_version.lua") dofile(modpath .. "/itemstack_equals.lua") dofile(modpath .. "/content_ids.lua") dofile(modpath .. "/metadata.lua") +dofile(modpath .. "/translations.lua") -------------- diff --git a/games/devtest/mods/unittests/locale/unittests.de.tr b/games/devtest/mods/unittests/locale/unittests.de.tr new file mode 100644 index 0000000000000..e79e5feefee7c --- /dev/null +++ b/games/devtest/mods/unittests/locale/unittests.de.tr @@ -0,0 +1,5 @@ +# textdomain: unittests +# Note that the "translations" here are only for testing; it is not necessary +# to actually translate any text here. +Only in primary language.=Result in primary language. +Available in both languages.=Result in primary language. diff --git a/games/devtest/mods/unittests/locale/unittests.fr.tr b/games/devtest/mods/unittests/locale/unittests.fr.tr new file mode 100644 index 0000000000000..efde0ab6ef777 --- /dev/null +++ b/games/devtest/mods/unittests/locale/unittests.fr.tr @@ -0,0 +1,5 @@ +# textdomain: unittests +# Note that the "translations" here are only for testing; it is not necessary +# to actually translate any text here. +Only in secondary language.=Result in secondary language. +Available in both languages.=Result in secondary language. diff --git a/games/devtest/mods/unittests/translations.lua b/games/devtest/mods/unittests/translations.lua new file mode 100644 index 0000000000000..8bcfdf70a11f3 --- /dev/null +++ b/games/devtest/mods/unittests/translations.lua @@ -0,0 +1,13 @@ +local S = core.get_translator("unittests") + +local function test_server_translation() + local function translate(str) + return core.get_translated_string("de:fr", S(str)) + end + local RESULT_PRIMARY = "Result in primary language." + local RESULT_SECONDARY = "Result in secondary language." + assert(translate("Only in primary language.") == RESULT_PRIMARY, "missing translation for primary language") + assert(translate("Only in secondary language.") == RESULT_SECONDARY, "missing translation for secondary language") + assert(translate("Available in both languages.") == RESULT_PRIMARY, "incorrect translation priority list applied") +end +unittests.register("test_server_translation", test_server_translation)