diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d949aa..46f5db2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- Update intllib support to avoid using deprecated functions. + ### Fixed - Node rotation now works correctly when placing Stairs+ nodes. diff --git a/circular_saw.lua b/circular_saw.lua index 4d1a3d9..1dce479 100644 --- a/circular_saw.lua +++ b/circular_saw.lua @@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio, Sokomine and contributors. Licensed under the zlib license. See LICENSE.md for more information. --]] -local S = moreblocks.intllib +local S = moreblocks.S circular_saw = {} diff --git a/init.lua b/init.lua index ad5ad25..7627f7d 100644 --- a/init.lua +++ b/init.lua @@ -10,20 +10,12 @@ Licensed under the zlib license. See LICENSE.md for more information. moreblocks = {} -local S -if minetest.global_exists("intllib") then - if intllib.make_gettext_pair then - S = intllib.make_gettext_pair() - else - S = intllib.Getter() - end -else - S = function(s) return s end -end -moreblocks.intllib = S - local modpath = minetest.get_modpath("moreblocks") +local S, NS = dofile(modpath .. "/intllib.lua") +moreblocks.S = S +moreblocks.NS = NS + dofile(modpath .. "/config.lua") dofile(modpath .. "/circular_saw.lua") dofile(modpath .. "/stairsplus/init.lua") diff --git a/intllib.lua b/intllib.lua new file mode 100644 index 0000000..c7af2c2 --- /dev/null +++ b/intllib.lua @@ -0,0 +1,44 @@ +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + 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 +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/nodes.lua b/nodes.lua index 5bcab6c..047f59e 100644 --- a/nodes.lua +++ b/nodes.lua @@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors. Licensed under the zlib license. See LICENSE.md for more information. --]] -local S = moreblocks.intllib +local S = moreblocks.S local sound_dirt = default.node_sound_dirt_defaults() local sound_wood = default.node_sound_wood_defaults() diff --git a/ownership.lua b/ownership.lua index 34bcffa..20f0fe1 100644 --- a/ownership.lua +++ b/ownership.lua @@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors. Licensed under the zlib license. See LICENSE.md for more information. --]] -local S = moreblocks.gettext +local S = moreblocks.S function moreblocks.node_is_owned(pos, placer) local ownername = false diff --git a/stairsplus/common.lua b/stairsplus/common.lua index 6ec5101..7b86fad 100644 --- a/stairsplus/common.lua +++ b/stairsplus/common.lua @@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors. Licensed under the zlib license. See LICENSE.md for more information. --]] -local S = moreblocks.intllib +local S = moreblocks.S stairsplus.register_single = function(category, alternate, info, modname, subname, recipeitem, fields) diff --git a/stairsplus/slabs.lua b/stairsplus/slabs.lua index c41b2e3..8c23599 100644 --- a/stairsplus/slabs.lua +++ b/stairsplus/slabs.lua @@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors. Licensed under the zlib license. See LICENSE.md for more information. --]] -local S = moreblocks.intllib +local S = moreblocks.S -- Node will be called :slab_