mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2024-11-26 09:13:55 +01:00
Update to new intllib API.
This commit is contained in:
parent
7fd56ac3d0
commit
1049280eeb
11
api.lua
11
api.lua
@ -14,10 +14,8 @@
|
|||||||
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
--
|
--
|
||||||
|
|
||||||
-- The global award namespace
|
local S = awards.gettext
|
||||||
awards = {
|
|
||||||
show_mode = "hud"
|
|
||||||
}
|
|
||||||
dofile(minetest.get_modpath("awards").."/api_helpers.lua")
|
dofile(minetest.get_modpath("awards").."/api_helpers.lua")
|
||||||
|
|
||||||
-- Table Save Load Functions
|
-- Table Save Load Functions
|
||||||
@ -29,11 +27,6 @@ function awards.save()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local S = function(s) return s end
|
|
||||||
function awards.set_intllib(locale)
|
|
||||||
S = locale
|
|
||||||
end
|
|
||||||
|
|
||||||
function awards.init()
|
function awards.init()
|
||||||
awards.players = awards.load()
|
awards.players = awards.load()
|
||||||
awards.def = {}
|
awards.def = {}
|
||||||
|
@ -14,12 +14,7 @@
|
|||||||
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
--
|
--
|
||||||
|
|
||||||
local S
|
local S = awards.gettext
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
S = function ( s ) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_chatcommand("awards", {
|
minetest.register_chatcommand("awards", {
|
||||||
params = S("[c|clear|disable|enable]"),
|
params = S("[c|clear|disable|enable]"),
|
||||||
|
17
init.lua
17
init.lua
@ -14,20 +14,21 @@
|
|||||||
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
--
|
--
|
||||||
|
|
||||||
|
-- The global award namespace
|
||||||
|
awards = {
|
||||||
|
show_mode = "hud"
|
||||||
|
}
|
||||||
|
|
||||||
local S
|
-- Internationalization support.
|
||||||
if minetest.get_modpath("intllib") then
|
local S, NS = dofile(minetest.get_modpath("awards").."/intllib.lua")
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
awards.gettext, awards.ngettext = S, NS
|
||||||
S = function ( s ) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
dofile(minetest.get_modpath("awards").."/api.lua")
|
dofile(minetest.get_modpath("awards").."/api.lua")
|
||||||
dofile(minetest.get_modpath("awards").."/chat_commands.lua")
|
dofile(minetest.get_modpath("awards").."/chat_commands.lua")
|
||||||
dofile(minetest.get_modpath("awards").."/sfinv.lua")
|
dofile(minetest.get_modpath("awards").."/sfinv.lua")
|
||||||
dofile(minetest.get_modpath("awards").."/unified_inventory.lua")
|
dofile(minetest.get_modpath("awards").."/unified_inventory.lua")
|
||||||
dofile(minetest.get_modpath("awards").."/triggers.lua")
|
dofile(minetest.get_modpath("awards").."/triggers.lua")
|
||||||
awards.set_intllib(S)
|
|
||||||
|
|
||||||
-- Saint-Maclou
|
-- Saint-Maclou
|
||||||
if minetest.get_modpath("moreblocks") then
|
if minetest.get_modpath("moreblocks") then
|
||||||
@ -712,7 +713,7 @@ end
|
|||||||
|
|
||||||
if minetest.get_modpath("farming") then
|
if minetest.get_modpath("farming") then
|
||||||
awards.register_achievement("awards_farmer", {
|
awards.register_achievement("awards_farmer", {
|
||||||
title = S("Farming Skills Aquired"),
|
title = S("Farming Skills Acquired"),
|
||||||
description = S("Harvest a fully grown wheat plant."),
|
description = S("Harvest a fully grown wheat plant."),
|
||||||
icon = "farming_wheat_8.png^awards_level1.png",
|
icon = "farming_wheat_8.png^awards_level1.png",
|
||||||
trigger = {
|
trigger = {
|
||||||
|
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
|
@ -1,10 +1,5 @@
|
|||||||
if minetest.get_modpath("sfinv") then
|
if minetest.get_modpath("sfinv") then
|
||||||
local S
|
local S = awards.gettext
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
S = function ( s ) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
sfinv.register_page("awards:awards", {
|
sfinv.register_page("awards:awards", {
|
||||||
title = S("Awards"),
|
title = S("Awards"),
|
||||||
|
82
triggers.lua
82
triggers.lua
@ -14,12 +14,7 @@
|
|||||||
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
--
|
--
|
||||||
|
|
||||||
local S
|
local S, NS = awards.gettext, awards.ngettext
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
S = function ( s ) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
awards.register_trigger("dig", function(def)
|
awards.register_trigger("dig", function(def)
|
||||||
local tmp = {
|
local tmp = {
|
||||||
@ -37,22 +32,20 @@ awards.register_trigger("dig", function(def)
|
|||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
perc = itemcount / tmp.target,
|
perc = itemcount / tmp.target,
|
||||||
label = string.format(S("%d/%d dug"), itemcount, tmp.target)
|
label = S("@1/@2 dug", itemcount, tmp.target),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def.getDefaultDescription = function(self)
|
def.getDefaultDescription = function(self)
|
||||||
|
local n = self.trigger.target
|
||||||
if self.trigger.node then
|
if self.trigger.node then
|
||||||
local nname = minetest.registered_nodes[self.trigger.node].description
|
local nname = minetest.registered_nodes[self.trigger.node].description
|
||||||
if nname == nil then
|
if nname == nil then
|
||||||
nname = self.trigger.node
|
nname = self.trigger.node
|
||||||
end
|
end
|
||||||
if self.trigger.target ~= 1 then
|
-- Translators: @1 is count, @2 is description.
|
||||||
return string.format(S("Mine blocks: %d×%s"), self.trigger.target, nname)
|
return NS("Mine: @2", "Mine: @1×@2", n, n, nname)
|
||||||
else
|
|
||||||
return string.format(S("Mine a block: %s"), nname)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return string.format(S("Mine %d block(s)."), self.trigger.target)
|
return NS("Mine @1 block.", "Mine @1 blocks.", n, n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -73,22 +66,20 @@ awards.register_trigger("place", function(def)
|
|||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
perc = itemcount / tmp.target,
|
perc = itemcount / tmp.target,
|
||||||
label = string.format(S("%d/%d placed"), itemcount, tmp.target)
|
label = S("@1/@2 placed", itemcount, tmp.target),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def.getDefaultDescription = function(self)
|
def.getDefaultDescription = function(self)
|
||||||
|
local n = self.trigger.target
|
||||||
if self.trigger.node then
|
if self.trigger.node then
|
||||||
local nname = minetest.registered_nodes[self.trigger.node].description
|
local nname = minetest.registered_nodes[self.trigger.node].description
|
||||||
if nname == nil then
|
if nname == nil then
|
||||||
nname = self.trigger.node
|
nname = self.trigger.node
|
||||||
end
|
end
|
||||||
if self.trigger.target ~= 1 then
|
-- Translators: @1 is count, @2 is description.
|
||||||
return string.format(S("Place blocks: %d×%s"), self.trigger.target, nname)
|
return NS("Place: @2", "Place: @1×@2", n, n, nname)
|
||||||
else
|
|
||||||
return string.format(S("Place a block: %s"), nname)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return string.format(S("Place %d block(s)."), self.trigger.target)
|
return NS("Place a block.", "Place @1 blocks.", n, n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -109,22 +100,20 @@ awards.register_trigger("eat", function(def)
|
|||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
perc = itemcount / tmp.target,
|
perc = itemcount / tmp.target,
|
||||||
label = string.format(S("%d/%d eaten"), itemcount, tmp.target)
|
label = S("@1/@2 eaten", itemcount, tmp.target),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def.getDefaultDescription = function(self)
|
def.getDefaultDescription = function(self)
|
||||||
|
local n = self.trigger.target
|
||||||
if self.trigger.item then
|
if self.trigger.item then
|
||||||
local iname = minetest.registered_items[self.trigger.item].description
|
local iname = minetest.registered_items[self.trigger.item].description
|
||||||
if iname == nil then
|
if iname == nil then
|
||||||
iname = self.trigger.iode
|
iname = self.trigger.iode
|
||||||
end
|
end
|
||||||
if self.trigger.target ~= 1 then
|
-- Translators: @1 is count, @2 is description.
|
||||||
return string.format(S("Eat: %d×%s"), self.trigger.target, iname)
|
return NS("Eat: @2", "Eat: @1×@2", n, n, iname)
|
||||||
else
|
|
||||||
return string.format(S("Eat: %s"), iname)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return string.format(S("Eat %d item(s)."), self.trigger.target)
|
return NS("Eat an item.", "Eat @1 items.", n, n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -139,15 +128,12 @@ awards.register_trigger("death", function(def)
|
|||||||
local itemcount = data.deaths or 0
|
local itemcount = data.deaths or 0
|
||||||
return {
|
return {
|
||||||
perc = itemcount / tmp.target,
|
perc = itemcount / tmp.target,
|
||||||
label = string.format(S("%d/%d deaths"), itemcount, tmp.target)
|
label = S("@1/@2 deaths", itemcount, tmp.target),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def.getDefaultDescription = function(self)
|
def.getDefaultDescription = function(self)
|
||||||
if self.trigger.target ~= 1 then
|
local n = self.trigger.target
|
||||||
return string.format(S("Die %d times."), self.trigger.target)
|
return NS("Die.", "Die @1 times.", n, n)
|
||||||
else
|
|
||||||
return S("Die.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -161,15 +147,12 @@ awards.register_trigger("chat", function(def)
|
|||||||
local itemcount = data.chats or 0
|
local itemcount = data.chats or 0
|
||||||
return {
|
return {
|
||||||
perc = itemcount / tmp.target,
|
perc = itemcount / tmp.target,
|
||||||
label = string.format(S("%d/%d chat messages"), itemcount, tmp.target)
|
label = S("@1/@2 chat messages", itemcount, tmp.target),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def.getDefaultDescription = function(self)
|
def.getDefaultDescription = function(self)
|
||||||
if self.trigger.target ~= 1 then
|
local n = self.trigger.target
|
||||||
return string.format(S("Write %d chat messages."), self.trigger.target)
|
return NS("Write something in chat.", "Write @1 chat messages.", n, n)
|
||||||
else
|
|
||||||
return S("Write something in chat.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -183,15 +166,12 @@ awards.register_trigger("join", function(def)
|
|||||||
local itemcount = data.joins or 0
|
local itemcount = data.joins or 0
|
||||||
return {
|
return {
|
||||||
perc = itemcount / tmp.target,
|
perc = itemcount / tmp.target,
|
||||||
label = string.format(S("%d/%d game joins"), itemcount, tmp.target)
|
label = S("@1/@2 game joins", itemcount, tmp.target),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def.getDefaultDescription = function(self)
|
def.getDefaultDescription = function(self)
|
||||||
if self.trigger.target ~= 1 then
|
local n = self.trigger.target
|
||||||
return string.format(S("Join the game %d times."), self.trigger.target)
|
return NS("Join the game.", "Join the game @1 times.", n, n)
|
||||||
else
|
|
||||||
return S("Join the game.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -211,22 +191,20 @@ awards.register_trigger("craft", function(def)
|
|||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
perc = itemcount / tmp.target,
|
perc = itemcount / tmp.target,
|
||||||
label = string.format(S("%d/%d crafted"), itemcount, tmp.target)
|
label = S("@1/@2 crafted", itemcount, tmp.target),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def.getDefaultDescription = function(self)
|
def.getDefaultDescription = function(self)
|
||||||
|
local n = self.trigger.target
|
||||||
if self.trigger.item then
|
if self.trigger.item then
|
||||||
local iname = minetest.registered_items[self.trigger.item].description
|
local iname = minetest.registered_items[self.trigger.item].description
|
||||||
if iname == nil then
|
if iname == nil then
|
||||||
iname = self.trigger.item
|
iname = self.trigger.item
|
||||||
end
|
end
|
||||||
if self.trigger.target ~= 1 then
|
-- Translators: @1 is count, @2 is description.
|
||||||
return string.format(S("Craft: %d×%s"), self.trigger.target, iname)
|
return NS("Craft: @2", "Craft: @1×@2", n, n, iname)
|
||||||
else
|
|
||||||
return string.format(S("Craft: %s"), iname)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return string.format(S("Craft %d item(s)."), self.trigger.target)
|
return NS("Craft an item.", "Craft @1 items.", n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
if minetest.get_modpath("unified_inventory") ~= nil then
|
if minetest.get_modpath("unified_inventory") ~= nil then
|
||||||
local S
|
local S = awards.gettext
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
S = function ( s ) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
unified_inventory.register_button("awards", {
|
unified_inventory.register_button("awards", {
|
||||||
type = "image",
|
type = "image",
|
||||||
|
Loading…
Reference in New Issue
Block a user