Fix 0.4 compatibility (#16)

* added minetest 0.4 compatibility due the trasnlation missing support

* if translation is not supported use english on compat/mtg.lua
* improved the code of translation of the already init.lua
* this solves: closes https://github.com/minetest-mods/lavastuff/issues/13
* this solves: closes https://codeberg.org/minenux/lavastuff/issues/1
* close https://codeberg.org/minenux/lavastuff/issues/1

* real fix for compatibility later trasnlations

* real fix for https://github.com/minetest-mods/lavastuff/issues/13
* use native translator or intlib property as must be, but mock if both fails

* fix modname and use intlib depennds only in older engines

* autodetect mod name from minetest api
* added only intllib in depends.txt for older 0.4.X, mod.conf its for 5+
  so due 5+ has built in internationalization its not necesary in that file

* added the depends only when necesary for intllib

* Update init.lua usage or MODNAME and MODPATH

Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com>

* puff also uage ot the MODNAME in get translator

* update luacheck as suggested by lonewolf

i dont know how to avoid the usage of those variables.. but he suggested to just put those .. https://github.com/minetest-mods/lavastuff/pull/16#issuecomment-1036497969

* move intllib to others to do not fail in checks agains moderns engine

also added ',' at the en of the line

Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com>
master
Герхард PICCORO Lenz McKAY 2022-02-24 01:13:38 -04:00 committed by GitHub
parent 94d6bd9b44
commit 3eacc17e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View File

@ -23,7 +23,7 @@ read_globals = {
"nodecore",
-- Other mods
"stairsplus", "toolranks",
"stairsplus", "toolranks", "gettext", "intllib",
}
exclude_files = {

View File

@ -6,6 +6,7 @@ mobs_monster?
3d_armor?
toolranks?
moreblocks?
intllib?
vessels?
nc_fire?
mcl_armor?

View File

@ -1,15 +1,41 @@
lavastuff = {}
local MODPATH = minetest.get_modpath("lavastuff")
local MODNAME = minetest.get_current_modname()
local MODPATH = minetest.get_modpath(MODNAME)
local COOLDOWN = dofile(MODPATH.."/cooldowns.lua")
local S
if minetest.get_translator ~= nil then
S = minetest.get_translator(minetest.get_current_modname())
S = minetest.get_translator(MODNAME)
else
S = function(str)
return(str)
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(MODNAME)
end
end
@ -524,4 +550,4 @@ else
end
end
minetest.log("action", "[lavastuff]: Mod Loaded!")
minetest.log("action", "[lavastuff]: Mod Loaded!")