From e1baf9c2c0e337798325bf01596194fb159fa0ff Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 8 Sep 2020 20:05:11 +0200 Subject: [PATCH] Add 0.4 compability layer (translator) --- init.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index b01160f..7a5b8be 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,30 @@ -local S = minetest.get_translator("teleports") +local S +if minetest.translate then + S = minetest.get_translator("teleports") +else + -- Compability translator code to support MT 0.4, which doesn't support + -- translations for mods. + + local function translate(textdomain, str, ...) + local arg = {n=select('#', ...), ...} + return str:gsub("@(.)", function(matched) + local c = string.byte(matched) + if string.byte("1") <= c and c <= string.byte("9") then + return arg[c - string.byte("0")] + else + return matched + end + end) + end + + S = function(textdomain) + return function(str, ...) + return translate(textdomain or "", str, ...) + end + end +end + + local F = minetest.formspec_escape teleports = {}