Skip to content

Commit

Permalink
Add unittests for server-side translations
Browse files Browse the repository at this point in the history
  • Loading branch information
y5nw committed Mar 5, 2024
1 parent 705cd41 commit d1e5b24
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions games/devtest/mods/unittests/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

--------------

Expand Down
5 changes: 5 additions & 0 deletions games/devtest/mods/unittests/locale/unittests.de.tr
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions games/devtest/mods/unittests/locale/unittests.fr.tr
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions games/devtest/mods/unittests/translations.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d1e5b24

Please sign in to comment.