Update intllib support to avoid using deprecated functions

This commit is contained in:
Hugo Locurcio 2019-03-03 20:02:40 +01:00
parent e43e4a1911
commit 76a00a5365
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
8 changed files with 57 additions and 17 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased] ## [Unreleased]
### Changed
- Update intllib support to avoid using deprecated functions.
### Fixed ### Fixed
- Node rotation now works correctly when placing Stairs+ nodes. - Node rotation now works correctly when placing Stairs+ nodes.

View File

@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio, Sokomine and contributors.
Licensed under the zlib license. See LICENSE.md for more information. Licensed under the zlib license. See LICENSE.md for more information.
--]] --]]
local S = moreblocks.intllib local S = moreblocks.S
circular_saw = {} circular_saw = {}

View File

@ -10,20 +10,12 @@ Licensed under the zlib license. See LICENSE.md for more information.
moreblocks = {} 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 modpath = minetest.get_modpath("moreblocks")
local S, NS = dofile(modpath .. "/intllib.lua")
moreblocks.S = S
moreblocks.NS = NS
dofile(modpath .. "/config.lua") dofile(modpath .. "/config.lua")
dofile(modpath .. "/circular_saw.lua") dofile(modpath .. "/circular_saw.lua")
dofile(modpath .. "/stairsplus/init.lua") dofile(modpath .. "/stairsplus/init.lua")

44
intllib.lua Normal file
View File

@ -0,0 +1,44 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- 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

View File

@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information. 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_dirt = default.node_sound_dirt_defaults()
local sound_wood = default.node_sound_wood_defaults() local sound_wood = default.node_sound_wood_defaults()

View File

@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information. 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) function moreblocks.node_is_owned(pos, placer)
local ownername = false local ownername = false

View File

@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information. 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) stairsplus.register_single = function(category, alternate, info, modname, subname, recipeitem, fields)

View File

@ -5,7 +5,7 @@ Copyright © 2011-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information. Licensed under the zlib license. See LICENSE.md for more information.
--]] --]]
local S = moreblocks.intllib local S = moreblocks.S
-- Node will be called <modname>:slab_<subname> -- Node will be called <modname>:slab_<subname>