From 646e0566f68e89f45a7bedc385bd06df29d04959 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Fri, 3 Feb 2017 00:22:31 -0700 Subject: [PATCH] intllib support --- crafts.lua | 6 ++- depends.txt | 3 +- doc.lua | 23 +++++----- functions.lua | 4 +- init.lua | 6 ++- intllib.lua | 45 +++++++++++++++++++ ladder.lua | 12 +++-- locale/template.pot | 104 ++++++++++++++++++++++++++++++++++++++++++++ ropeboxes.lua | 12 +++-- 9 files changed, 190 insertions(+), 25 deletions(-) create mode 100644 intllib.lua create mode 100644 locale/template.pot diff --git a/crafts.lua b/crafts.lua index 5070947..2316c82 100644 --- a/crafts.lua +++ b/crafts.lua @@ -1,4 +1,6 @@ --- Misc +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") if minetest.get_modpath("farming") then minetest.register_craft({ @@ -12,7 +14,7 @@ if minetest.get_modpath("farming") then end minetest.register_craftitem("ropes:ropesegment", { - description = "Rope", + description = S("Rope Segment"), _doc_items_longdesc = ropes.doc.ropesegment_longdesc, _doc_items_usagehelp = ropes.doc.ropesegment_usage, groups = {vines = 1}, diff --git a/depends.txt b/depends.txt index eeb20c1..ece13c0 100644 --- a/depends.txt +++ b/depends.txt @@ -1,4 +1,5 @@ default farming? vines? -doc? \ No newline at end of file +doc? +intllib? \ No newline at end of file diff --git a/doc.lua b/doc.lua index eae81d1..50bfad5 100644 --- a/doc.lua +++ b/doc.lua @@ -4,18 +4,21 @@ if not minetest.get_modpath("doc") then return end -ropes.doc.ropesegment_longdesc = "Rope segments are bundles of fibre twisted into robust cables." -ropes.doc.ropesegment_usage = "This craft item is useful for creating rope ladders, or for spooling on wooden spindles to hang and climb upon." +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") -ropes.doc.ropeladder_longdesc = "A hanging rope ladder that automatically extends downward" -ropes.doc.ropeladder_usage = "After a rope ladder is placed on a vertical wall it will begin extending downward until it reaches its maximum length (" .. tostring(ropes.ropeLadderLength) .. "m). If the rope ladder is removed all of the ladder below the point of removal will disappear. A rope ladder can be severed partway down using an axe or similar tool, and the ladder below the point where it is cut will collapse. No rope is actually lost in the process, though, and if the uppermost section of the ladder is removed and replaced the ladder will re-extend to the same maximum length as before." +ropes.doc.ropesegment_longdesc = S("Rope segments are bundles of fibre twisted into robust cables.") +ropes.doc.ropesegment_usage = S("This craft item is useful for creating rope ladders, or for spooling on wooden spindles to hang and climb upon.") -ropes.doc.ropebox_longdesc = "Ropes are hung by placing rope boxes, which automatically lower a rope of fixed length below them. They can be climbed and cut." -ropes.doc.ropebox_usage = "Rope boxes have a certain amount of rope contained within them specified in the name of the node. They come in five standard lengths " .. - string.format("(%dm, %dm, %dm, %dm and %dm)", ropes.ropeLength, ropes.ropeLength*2, ropes.ropeLength*3, ropes.ropeLength*4, ropes.ropeLength*5) .. - " that can be crafted by combining and splitting up rope boxes in the crafting grid. For example, you can craft a " .. tostring(ropes.ropeLength*2) .. "m rope box by combining two " .. tostring(ropes.ropeLength) .. "m rope boxes, and the two " .. tostring(ropes.ropeLength) .. "m rope boxes can be recovered by splitting it back up in the crafting grid.\n\n" .. - "When a rope box is placed the rope will immediately begin lowering from it at one meter per second. The rope will only descend when its end is in the vicinity of an active player, suspending its journey when no players are nearby, so a long descent may require a player to climb down the rope as it goes. Take care not to fall off the end! The rope will stop when it encounters and obstruction, but will resume lowering if the obstruction is removed.\n\n" .. - "A rope can be severed midway using an axe or other similar tools. The section of rope below the cut will collapse and disappear, potentially causing players who were hanging on to it to fall. The remaining rope will not resume descent on its own, but the rope box at the top of the rope \"remembers\" how long the rope was and if it is deconstructed and replaced it will still have the same maximum length of rope as before - no rope is permnanently lost when a rope is severed like this." +ropes.doc.ropeladder_longdesc = S("A hanging rope ladder that automatically extends downward.") +ropes.doc.ropeladder_usage = string.format(S("After a rope ladder is placed on a vertical wall it will begin extending downward until it reaches its maximum length (%dm). If the rope ladder is removed all of the ladder below the point of removal will disappear. A rope ladder can be severed partway down using an axe or similar tool, and the ladder below the point where it is cut will collapse. No rope is actually lost in the process, though, and if the uppermost section of the ladder is removed and replaced the ladder will re-extend to the same maximum length as before."), ropes.ropeLadderLength) + +ropes.doc.ropebox_longdesc = S("Ropes are hung by placing rope boxes, which automatically lower a rope of fixed length below them. They can be climbed and cut.") +ropes.doc.ropebox_usage = + string.format(S("Rope boxes have a certain amount of rope contained within them specified in the name of the node. They come in five standard lengths (%dm, %dm, %dm, %dm and %dm) that can be crafted by combining and splitting up rope boxes in the crafting grid. For example, you can craft a %dm rope box by combining two %dm rope boxes, and the two %dm rope boxes can be recovered by splitting the %dm rope box back up in the crafting grid."), ropes.ropeLength, ropes.ropeLength*2, ropes.ropeLength*3, ropes.ropeLength*4, ropes.ropeLength*5, ropes.ropeLength*2, ropes.ropeLength, ropes.ropeLength, ropes.ropeLength*2) .. "\n\n" .. + S("When a rope box is placed the rope will immediately begin lowering from it at one meter per second. The rope will only descend when its end is in the vicinity of an active player, suspending its journey when no players are nearby, so a long descent may require a player to climb down the rope as it goes. Take care not to fall off the end! The rope will stop when it encounters and obstruction, but will resume lowering if the obstruction is removed.") .. "\n\n" .. + S("A rope can be severed midway using an axe or other similar tools. The section of rope below the cut will collapse and disappear, potentially causing players who were hanging on to it to fall. The remaining rope will not resume descent on its own, but the rope box at the top of the rope \"remembers\" how long the rope was and if it is deconstructed and replaced it will still have the same maximum length of rope as before - no rope is permnanently lost when a rope is severed like this.") doc.add_entry_alias("nodes", "ropes:ropeladder_top", "nodes", "ropes:ropeladder") doc.add_entry_alias("nodes", "ropes:ropeladder_top", "nodes", "ropes:ropeladder_bottom") diff --git a/functions.lua b/functions.lua index 285e205..799f43c 100644 --- a/functions.lua +++ b/functions.lua @@ -47,7 +47,7 @@ end ropes.hanging_after_destruct = function(pos, top_node, middle_node, bottom_node) local node = minetest.get_node(pos) if node.name == top_node or node.name == middle_node or node.name == bottom_node then - return -- this was done by another ladder node changing this one, don't react + return -- this was done by another ladder or rope node changing this one, don't react end pos.y = pos.y + 1 -- one up @@ -60,8 +60,6 @@ ropes.hanging_after_destruct = function(pos, top_node, middle_node, bottom_node) local node_below = minetest.get_node(pos) if node_below.name == middle_node then ropes.destroy_rope_starting(pos, middle_node, bottom_node, top_node) - --minetest.swap_node(pos, {name="ropes:ropeladder_falling", param2=node_below.param2}) - --minetest.get_node_timer(pos):start(0) elseif node_below.name == bottom_node then minetest.swap_node(pos, {name="air"}) end diff --git a/init.lua b/init.lua index 5e670d6..c80acd1 100644 --- a/init.lua +++ b/init.lua @@ -2,6 +2,10 @@ ropes = { name = 'ropes', } +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + local rope_length = minetest.setting_get("ropes_rope_length") if not rope_length then rope_length = 50 @@ -45,4 +49,4 @@ swapper("vines:ropeladder_bottom", "ropes:ropeladder_bottom") swapper("vines:ropeladder_falling", "ropes:ropeladder_falling") swapper("vines:rope_block", "ropes:5rope_block") -- for the original vines mod -print("[Ropes] Loaded!") +print(S("[Ropes] Loaded!")) 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 diff --git a/ladder.lua b/ladder.lua index 4cecf91..016f0d0 100644 --- a/ladder.lua +++ b/ladder.lua @@ -1,5 +1,9 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + minetest.register_node("ropes:ropeladder_top", { - description = "Rope ladder", + description = S("Rope Ladder"), _doc_items_longdesc = ropes.doc.ropeladder_longdesc, _doc_items_usagehelp = ropes.doc.ropeladder_usage, drawtype = "signlike", @@ -42,7 +46,7 @@ minetest.register_node("ropes:ropeladder_top", { }) minetest.register_node("ropes:ropeladder", { - description = "Rope ladder", + description = S("Rope Ladder"), _doc_items_create_entry = false, drop = "", drawtype = "signlike", @@ -70,7 +74,7 @@ minetest.register_node("ropes:ropeladder", { }) minetest.register_node("ropes:ropeladder_bottom", { - description = "Rope ladder", + description = S("Rope Ladder"), _doc_items_create_entry = false, drop = "", drawtype = "signlike", @@ -124,7 +128,7 @@ minetest.register_node("ropes:ropeladder_bottom", { }) minetest.register_node("ropes:ropeladder_falling", { - description = "Rope ladder", + description = S("Rope Ladder"), _doc_items_create_entry = false, drop = "", drawtype = "signlike", diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..972b867 --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,104 @@ +# Ropes mod. +# Copyright (C) 2017 +# This file is distributed under the same license as the ropes package. +# FaceDeer. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-02-03 00:18-0700\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: crafts.lua:17 +msgid "Rope Segment" +msgstr "" + +#: doc.lua:11 +msgid "Rope segments are bundles of fibre twisted into robust cables." +msgstr "" + +#: doc.lua:12 +msgid "" +"This craft item is useful for creating rope ladders, or for spooling on " +"wooden spindles to hang and climb upon." +msgstr "" + +#: doc.lua:14 +msgid "A hanging rope ladder that automatically extends downward." +msgstr "" + +#: doc.lua:15 +#, c-format +msgid "" +"After a rope ladder is placed on a vertical wall it will begin extending " +"downward until it reaches its maximum length (%dm). If the rope ladder is " +"removed all of the ladder below the point of removal will disappear. A rope " +"ladder can be severed partway down using an axe or similar tool, and the " +"ladder below the point where it is cut will collapse. No rope is actually " +"lost in the process, though, and if the uppermost section of the ladder is " +"removed and replaced the ladder will re-extend to the same maximum length as " +"before." +msgstr "" + +#: doc.lua:17 +msgid "" +"Ropes are hung by placing rope boxes, which automatically lower a rope of " +"fixed length below them. They can be climbed and cut." +msgstr "" + +#: doc.lua:19 +#, c-format +msgid "" +"Rope boxes have a certain amount of rope contained within them specified in " +"the name of the node. They come in five standard lengths (%dm, %dm, %dm, %dm " +"and %dm) that can be crafted by combining and splitting up rope boxes in the " +"crafting grid. For example, you can craft a %dm rope box by combining two %" +"dm rope boxes, and the two %dm rope boxes can be recovered by splitting the %" +"dm rope box back up in the crafting grid." +msgstr "" + +#: doc.lua:20 +msgid "" +"When a rope box is placed the rope will immediately begin lowering from it " +"at one meter per second. The rope will only descend when its end is in the " +"vicinity of an active player, suspending its journey when no players are " +"nearby, so a long descent may require a player to climb down the rope as it " +"goes. Take care not to fall off the end! The rope will stop when it " +"encounters and obstruction, but will resume lowering if the obstruction is " +"removed." +msgstr "" + +#: doc.lua:21 +msgid "" +"A rope can be severed midway using an axe or other similar tools. The " +"section of rope below the cut will collapse and disappear, potentially " +"causing players who were hanging on to it to fall. The remaining rope will " +"not resume descent on its own, but the rope box at the top of the rope " +"\"remembers\" how long the rope was and if it is deconstructed and replaced " +"it will still have the same maximum length of rope as before - no rope is " +"permnanently lost when a rope is severed like this." +msgstr "" + +#: init.lua:52 +msgid "[Ropes] Loaded!" +msgstr "" + +#: ladder.lua:6 ladder.lua:49 ladder.lua:77 ladder.lua:131 +msgid "Rope Ladder" +msgstr "" + +#: ropeboxes.lua:7 +#, c-format +msgid "Rope %im" +msgstr "" + +#: ropeboxes.lua:92 ropeboxes.lua:114 ropeboxes.lua:160 +msgid "Rope" +msgstr "" diff --git a/ropeboxes.lua b/ropeboxes.lua index e848eff..ef5249e 100644 --- a/ropeboxes.lua +++ b/ropeboxes.lua @@ -1,6 +1,10 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + local function register_rope_block(multiple, pixels) minetest.register_node(string.format("ropes:%irope_block", multiple), { - description = string.format("Rope %im", ropes.ropeLength*multiple), + description = string.format(S("Rope %im"), ropes.ropeLength*multiple), _doc_items_create_entry = false, drawtype="nodebox", sunlight_propagates = true, @@ -85,7 +89,7 @@ register_rope_block(4, 10) register_rope_block(5, 12) minetest.register_node("ropes:rope", { - description = "Rope", + description = S("Rope"), _doc_items_longdesc = ropes.doc.ropebox_longdesc, _doc_items_usagehelp = ropes.doc.ropebox_usage, walkable = false, @@ -107,7 +111,7 @@ minetest.register_node("ropes:rope", { }) minetest.register_node("ropes:rope_bottom", { - description = "Rope", + description = S("Rope"), _doc_items_create_entry = false, walkable = false, climbable = true, @@ -153,7 +157,7 @@ minetest.register_node("ropes:rope_bottom", { }) minetest.register_node("ropes:rope_top", { - description = "Rope", + description = S("Rope"), _doc_items_create_entry = false, walkable = false, climbable = true,