From 5e441b03fa7729a5f4d3127879e849b454bb5ff9 Mon Sep 17 00:00:00 2001 From: codexp Date: Fri, 13 Jul 2018 12:52:11 +0200 Subject: [PATCH] implement original intllib helper --- init.lua | 35 +++++++++++++++-------------------- intllib.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 intllib.lua diff --git a/init.lua b/init.lua index c12f5e0..eae7c93 100644 --- a/init.lua +++ b/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 diff --git a/intllib.lua b/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/intllib.lua @@ -0,0 +1,45 @@ + +-- 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