Change intllib for v5 minetest.get_translator

This commit is contained in:
Olivier Dragon 2020-08-30 23:47:57 -04:00 committed by Buckaroo Banzai
parent 979516c13d
commit 4dc9a81ec2
12 changed files with 11 additions and 61 deletions

@ -4,7 +4,6 @@ unused_args = false
globals = { globals = {
"wieldview", "wieldview",
"armor", "armor",
"armor_i18n",
"inventory_plus" "inventory_plus"
} }
@ -21,7 +20,6 @@ read_globals = {
"default", "default",
"minetest", "minetest",
"unified_inventory", "unified_inventory",
"intllib",
"wardrobe", "wardrobe",
"player_monoids", "player_monoids",
"armor_monoid", "armor_monoid",

@ -1,5 +1,5 @@
-- support for i18n -- support for i18n
local S = armor_i18n.gettext local S = armor.get_translator
local skin_previews = {} local skin_previews = {}
local use_player_monoids = minetest.global_exists("player_monoids") local use_player_monoids = minetest.global_exists("player_monoids")

@ -1,5 +1,5 @@
-- support for i18n -- support for i18n
local S = armor_i18n.gettext local S = armor.get_translator
armor:register_armor("3d_armor:helmet_admin", { armor:register_armor("3d_armor:helmet_admin", {
description = S("Admin Helmet"), description = S("Admin Helmet"),

@ -5,4 +5,3 @@ pova?
fire? fire?
ethereal? ethereal?
bakedclay? bakedclay?
intllib?

@ -5,14 +5,12 @@ local last_punch_time = {}
local pending_players = {} local pending_players = {}
local timer = 0 local timer = 0
-- support for i18n
armor_i18n = { }
armor_i18n.gettext, armor_i18n.ngettext = dofile(modpath.."/intllib.lua")
-- local functions -- local functions
local S = armor_i18n.gettext local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape local F = minetest.formspec_escape
armor.get_translator = S
dofile(modpath.."/api.lua") dofile(modpath.."/api.lua")
-- integration test -- integration test

@ -1,45 +0,0 @@
-- 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

@ -1,4 +1,4 @@
name = 3d_armor name = 3d_armor
depends = default depends = default
optional_depends = player_monoids, armor_monoid, pova, fire, ethereal, bakedclay, intllib optional_depends = player_monoids, armor_monoid, pova, fire, ethereal, bakedclay
description = Adds craftable armor that is visible to other players. description = Adds craftable armor that is visible to other players.

@ -1,5 +1,5 @@
-- support for i18n -- support for i18n
local S = armor_i18n.gettext local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape local F = minetest.formspec_escape
if not minetest.global_exists("inventory_plus") then if not minetest.global_exists("inventory_plus") then

@ -1,5 +1,5 @@
-- support for i18n -- support for i18n
local S = armor_i18n.gettext local S = minetest.get_translator(minetest.get_current_modname())
if not minetest.global_exists("sfinv") then if not minetest.global_exists("sfinv") then
minetest.log("warning", S("3d_armor_sfinv: Mod loaded but unused.")) minetest.log("warning", S("3d_armor_sfinv: Mod loaded but unused."))

@ -1,5 +1,5 @@
-- support for i18n -- support for i18n
local S = armor_i18n.gettext local S = minetest.get_translator(minetest.get_current_modname())
local armor_stand_formspec = "size[8,7]" .. local armor_stand_formspec = "size[8,7]" ..
default.gui_bg .. default.gui_bg ..

@ -1,5 +1,5 @@
-- support for i18n -- support for i18n
local S = armor_i18n.gettext local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape local F = minetest.formspec_escape
local has_technic = minetest.get_modpath("technic") ~= nil local has_technic = minetest.get_modpath("technic") ~= nil

@ -1,5 +1,5 @@
-- support for i18n -- support for i18n
local S = armor_i18n.gettext local S = minetest.get_translator(minetest.get_current_modname())
local disable_sounds = minetest.settings:get_bool("shields_disable_sounds") local disable_sounds = minetest.settings:get_bool("shields_disable_sounds")
local function play_sound_effect(player, name) local function play_sound_effect(player, name)