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