summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Martínez <kaeza@users.noreply.github.com>2017-02-21 04:45:45 -0300
committerrubenwardy <rubenwardy@gmail.com>2017-02-23 22:48:13 +0000
commit1049280eeba4d78fed1fdc15a89a5e3d2ecd7357 (patch)
treeb2a95f5ad8ef98c81cd48faa7dfaa5610d910a7c
parent7fd56ac3d0730482ea9af086c0e8630ac3426af7 (diff)
Update to new intllib API.
-rw-r--r--api.lua11
-rw-r--r--chat_commands.lua7
-rw-r--r--init.lua17
-rw-r--r--intllib.lua45
-rw-r--r--sfinv.lua7
-rw-r--r--triggers.lua82
-rw-r--r--unified_inventory.lua7
7 files changed, 89 insertions, 87 deletions
diff --git a/api.lua b/api.lua
index 4043f79..af5e405 100644
--- a/api.lua
+++ b/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 = {}
diff --git a/chat_commands.lua b/chat_commands.lua
index c386c19..3f4ed68 100644
--- a/chat_commands.lua
+++ b/chat_commands.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 = awards.gettext
minetest.register_chatcommand("awards", {
params = S("[c|clear|disable|enable]"),
diff --git a/init.lua b/init.lua
index e841603..2e38db2 100644
--- a/init.lua
+++ b/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 = {
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 <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
diff --git a/sfinv.lua b/sfinv.lua
index de85998..e2b6eb4 100644
--- a/sfinv.lua
+++ b/sfinv.lua
@@ -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"),
diff --git a/triggers.lua b/triggers.lua
index 88a952f..594974a 100644
--- a/triggers.lua
+++ b/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)
- else
- return string.format(S("Mine a block: %s"), nname)
- end
+ -- Translators: @1 is count, @2 is description.
+ return NS("Mine: @2", "Mine: @1×@2", n, n, nname)
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)
- else
- return string.format(S("Place a block: %s"), nname)
- end
+ -- Translators: @1 is count, @2 is description.
+ return NS("Place: @2", "Place: @1×@2", n, n, nname)
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)
- else
- return string.format(S("Eat: %s"), iname)
- end
+ -- Translators: @1 is count, @2 is description.
+ return NS("Eat: @2", "Eat: @1×@2", n, n, iname)
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)
- else
- return string.format(S("Craft: %s"), iname)
- end
+ -- Translators: @1 is count, @2 is description.
+ return NS("Craft: @2", "Craft: @1×@2", n, n, iname)
else
- return string.format(S("Craft %d item(s)."), self.trigger.target)
+ return NS("Craft an item.", "Craft @1 items.", n)
end
end
end)
diff --git a/unified_inventory.lua b/unified_inventory.lua
index a4bb02d..1042196 100644
--- a/unified_inventory.lua
+++ b/unified_inventory.lua
@@ -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",