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
This commit is contained in:
parent
2fb7bf2c66
commit
4c0d19ee2d
36
api.lua
36
api.lua
@ -1,7 +1,39 @@
|
|||||||
-- Load support for intllib.
|
-- Load support for intllib.
|
||||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local S = minetest.get_translator and minetest.get_translator("mobs") or
|
local S
|
||||||
dofile(MP .. "/intllib.lua")
|
|
||||||
|
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
|
-- CMI support check
|
||||||
local use_cmi = minetest.global_exists("cmi")
|
local use_cmi = minetest.global_exists("cmi")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user