From 4c0d19ee2d9d0167550f9be13b3f359d79766eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D1=85=D0=B0=D1=80=D0=B4=20PICCORO=20Len?= =?UTF-8?q?z=20McKAY?= Date: Wed, 19 Jan 2022 15:29:08 -0400 Subject: [PATCH] fix translation for older versions of engine * the intlib is working but not as proposed * if there no translation provided do a mock for translations * this made compatiblity for any version of the engine --- api.lua | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/api.lua b/api.lua index 66c7f42..4392c93 100644 --- a/api.lua +++ b/api.lua @@ -1,7 +1,39 @@ -- Load support for intllib. local MP = minetest.get_modpath(minetest.get_current_modname()) -local S = minetest.get_translator and minetest.get_translator("mobs") or - dofile(MP .. "/intllib.lua") +local S + +if minetest.get_translator ~= nil then + S = minetest.get_translator("mobs") +else + if minetest.get_modpath("intllib") then + dofile(minetest.get_modpath("intllib").."/init.lua") + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end + S = gettext + else + -- mock the translator function for MT 0.4 + function minetest.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 + function minetest.get_translator(textdomain) + return function(str, ...) return minetest.translate(textdomain or "", str, ...) end + end + S = minetest.get_translator("mobs") + end +end -- CMI support check local use_cmi = minetest.global_exists("cmi")