mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2024-11-15 23:10:18 +01:00
implement original intllib helper
This commit is contained in:
parent
fc114ded8c
commit
5e441b03fa
35
init.lua
35
init.lua
|
@ -9,29 +9,24 @@ Licensed under the zlib license. See LICENSE.md for more information.
|
|||
--]]
|
||||
|
||||
moreblocks = {}
|
||||
moreblocks.modname = minetest.get_current_modname()
|
||||
moreblocks.modpath = minetest.get_modpath(moreblocks.modname)
|
||||
|
||||
-- Load support for intllib.
|
||||
local MP = moreblocks.modpath
|
||||
local S = dofile(MP .. "/intllib.lua")
|
||||
|
||||
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")
|
||||
|
||||
dofile(modpath .. "/config.lua")
|
||||
dofile(modpath .. "/circular_saw.lua")
|
||||
dofile(modpath .. "/stairsplus/init.lua")
|
||||
dofile(modpath .. "/nodes.lua")
|
||||
dofile(modpath .. "/redefinitions.lua")
|
||||
dofile(modpath .. "/crafting.lua")
|
||||
dofile(modpath .. "/aliases.lua")
|
||||
-- Load mod's modules
|
||||
dofile(MP .. "/config.lua")
|
||||
dofile(MP .. "/circular_saw.lua")
|
||||
dofile(MP .. "/stairsplus/init.lua")
|
||||
dofile(MP .. "/nodes.lua")
|
||||
dofile(MP .. "/redefinitions.lua")
|
||||
dofile(MP .. "/crafting.lua")
|
||||
dofile(MP .. "/aliases.lua")
|
||||
|
||||
if minetest.settings:get_bool("log_mods") then
|
||||
minetest.log("action", S("[moreblocks] loaded."))
|
||||
minetest.log("action", S("[MOD] moreblocks loaded."))
|
||||
end
|
||||
|
|
45
intllib.lua
Normal file
45
intllib.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
-- 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
|
Loading…
Reference in New Issue
Block a user