aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfat115 <fat115@framasoft.org>2017-08-05 10:12:43 +0200
committerfat115 <fat115@framasoft.org>2017-08-05 10:12:43 +0200
commit2fef15d878f00c72a799aebc5b8a6bd61489296e (patch)
tree5d5ec63f18bb317fa7c56dcb00c8ffa7f3a62b10
parent54108e8054ee21e1a3b229f4a4e9e521f5700aa6 (diff)
downloaddisplay_modpack-2fef15d878f00c72a799aebc5b8a6bd61489296e.tar.gz
display_modpack-2fef15d878f00c72a799aebc5b8a6bd61489296e.tar.bz2
display_modpack-2fef15d878f00c72a799aebc5b8a6bd61489296e.zip
add intllib support (i18n)
-> mods ontime_clocks, signs, signs_roads & steles add french translations add updatepo.sh script to update po/pot files add specific array for full description of steles
-rw-r--r--ontime_clocks/depends.txt1
-rw-r--r--ontime_clocks/init.lua9
-rw-r--r--ontime_clocks/intllib.lua45
-rw-r--r--ontime_clocks/locale/fr.po43
-rw-r--r--ontime_clocks/locale/template.pot42
-rw-r--r--ontime_clocks/nodes.lua14
-rwxr-xr-xontime_clocks/tools/updatepo.sh25
-rw-r--r--signs/common.lua13
-rw-r--r--signs/depends.txt1
-rw-r--r--signs/init.lua10
-rw-r--r--signs/intllib.lua45
-rw-r--r--signs/locale/fr.po55
-rw-r--r--signs/locale/template.pot55
-rw-r--r--signs/nodes.lua20
-rwxr-xr-xsigns/tools/updatepo.sh25
-rw-r--r--signs_road/depends.txt1
-rw-r--r--signs_road/init.lua10
-rw-r--r--signs_road/intllib.lua45
-rw-r--r--signs_road/locale/fr.po35
-rw-r--r--signs_road/locale/template.pot34
-rw-r--r--signs_road/nodes.lua14
-rwxr-xr-xsigns_road/tools/updatepo.sh25
-rw-r--r--steles/config.lua9
-rw-r--r--steles/depends.txt1
-rw-r--r--steles/init.lua9
-rw-r--r--steles/intllib.lua45
-rw-r--r--steles/locale/fr.po47
-rw-r--r--steles/locale/template.pot46
-rw-r--r--steles/nodes.lua16
-rwxr-xr-xsteles/tools/updatepo.sh25
30 files changed, 715 insertions, 50 deletions
diff --git a/ontime_clocks/depends.txt b/ontime_clocks/depends.txt
index 282fbc3..bdefee1 100644
--- a/ontime_clocks/depends.txt
+++ b/ontime_clocks/depends.txt
@@ -2,3 +2,4 @@ default
dye
display_lib
+intllib?
diff --git a/ontime_clocks/init.lua b/ontime_clocks/init.lua
index abcaebf..d6d2da4 100644
--- a/ontime_clocks/init.lua
+++ b/ontime_clocks/init.lua
@@ -21,10 +21,11 @@
ontime_clocks = {}
ontime_clocks.path = minetest.get_modpath("ontime_clocks")
+-- Load support for intllib.
+local MP = minetest.get_modpath(minetest.get_current_modname())
+local S, NS = dofile(MP.."/intllib.lua")
+ontime_clocks.intllib = S
+
dofile(ontime_clocks.path.."/common.lua")
dofile(ontime_clocks.path.."/nodes.lua")
dofile(ontime_clocks.path.."/crafts.lua")
-
-
-
-
diff --git a/ontime_clocks/intllib.lua b/ontime_clocks/intllib.lua
new file mode 100644
index 0000000..6669d72
--- /dev/null
+++ b/ontime_clocks/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/ontime_clocks/locale/fr.po b/ontime_clocks/locale/fr.po
new file mode 100644
index 0000000..ed5d2b4
--- /dev/null
+++ b/ontime_clocks/locale/fr.po
@@ -0,0 +1,43 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 09:50+0200\n"
+"PO-Revision-Date: 2017-05-08 06:20+0200\n"
+"Last-Translator: Peppy <peppy@twang-factory.com>\n"
+"Language-Team: \n"
+"Language: fr\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.8.12\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#: nodes.lua
+msgid "Green digital clock"
+msgstr "Horloge numérique verte"
+
+#: nodes.lua
+msgid "Red digital clock"
+msgstr "Horloge numérique rouge"
+
+#: nodes.lua
+msgid "White clock"
+msgstr "Horloge blanche"
+
+#: nodes.lua
+msgid "Frameless clock"
+msgstr "Horloge sans cadre"
+
+#: nodes.lua
+msgid "Frameless gold clock"
+msgstr "Horloge dorée sans cadre"
+
+#: nodes.lua
+msgid "Frameless white clock"
+msgstr "Horloge blanche sans cadre"
diff --git a/ontime_clocks/locale/template.pot b/ontime_clocks/locale/template.pot
new file mode 100644
index 0000000..0367f5c
--- /dev/null
+++ b/ontime_clocks/locale/template.pot
@@ -0,0 +1,42 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 09:50+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: nodes.lua
+msgid "Green digital clock"
+msgstr ""
+
+#: nodes.lua
+msgid "Red digital clock"
+msgstr ""
+
+#: nodes.lua
+msgid "White clock"
+msgstr ""
+
+#: nodes.lua
+msgid "Frameless clock"
+msgstr ""
+
+#: nodes.lua
+msgid "Frameless gold clock"
+msgstr ""
+
+#: nodes.lua
+msgid "Frameless white clock"
+msgstr ""
diff --git a/ontime_clocks/nodes.lua b/ontime_clocks/nodes.lua
index 69bf1bc..8055c18 100644
--- a/ontime_clocks/nodes.lua
+++ b/ontime_clocks/nodes.lua
@@ -18,9 +18,11 @@
along with ontime_clocks. If not, see <http://www.gnu.org/licenses/>.
--]]
+local S = ontime_clocks.intllib
+
-- Green digital clock
minetest.register_node("ontime_clocks:green_digital", {
- description = "Green digital clock",
+ description = S("Green digital clock"),
inventory_image = "ontime_clocks_green_digital_inventory.png",
wield_image = "ontime_clocks_green_digital_inventory.png",
paramtype = "light",
@@ -58,7 +60,7 @@ minetest.register_abm({
-- Red digital clock
minetest.register_node("ontime_clocks:red_digital", {
- description = "Red digital clock",
+ description = S("Red digital clock"),
inventory_image = "ontime_clocks_red_digital_inventory.png",
wield_image = "ontime_clocks_red_digital_inventory.png",
paramtype = "light",
@@ -96,7 +98,7 @@ minetest.register_abm({
minetest.register_node("ontime_clocks:white", {
- description = "White clock",
+ description = S("White clock"),
inventory_image = "ontime_clocks_white_inventory.png",
wield_image = "ontime_clocks_white_inventory.png",
paramtype = "light",
@@ -133,7 +135,7 @@ minetest.register_abm({
})
minetest.register_node("ontime_clocks:frameless_black", {
- description = "Frameless clock",
+ description = S("Frameless clock"),
inventory_image = "ontime_clocks_frameless_inventory.png",
wield_image = "ontime_clocks_frameless_inventory.png",
paramtype = "light",
@@ -170,7 +172,7 @@ minetest.register_abm({
})
minetest.register_node("ontime_clocks:frameless_gold", {
- description = "Frameless gold clock",
+ description = S("Frameless gold clock"),
inventory_image = "ontime_clocks_frameless_inventory.png^[colorize:#FF0",
wield_image = "ontime_clocks_frameless_inventory.png^[colorize:#FF0",
paramtype = "light",
@@ -207,7 +209,7 @@ minetest.register_abm({
})
minetest.register_node("ontime_clocks:frameless_white", {
- description = "Frameless white clock",
+ description = S("Frameless white clock"),
inventory_image = "ontime_clocks_frameless_inventory.png^[colorize:#FFF",
wield_image = "ontime_clocks_frameless_inventory.png^[colorize:#FFF",
paramtype = "light",
diff --git a/ontime_clocks/tools/updatepo.sh b/ontime_clocks/tools/updatepo.sh
new file mode 100755
index 0000000..feb2504
--- /dev/null
+++ b/ontime_clocks/tools/updatepo.sh
@@ -0,0 +1,25 @@
+#! /bin/bash
+
+# To create a new translation:
+# msginit --locale=ll_CC -o locale/ll_CC.po -i locale/template.pot
+
+cd "$(dirname "${BASH_SOURCE[0]}")/..";
+
+# Extract translatable strings.
+xgettext --from-code=UTF-8 \
+ --language=Lua \
+ --sort-by-file \
+ --keyword=S \
+ --keyword=NS:1,2 \
+ --keyword=N_ \
+ --keyword=F \
+ --add-comments='Translators:' \
+ --add-location=file \
+ -o locale/template.pot \
+ $(find . -name '*.lua')
+
+# Update translations.
+find locale -name '*.po' | while read -r file; do
+ echo $file
+ msgmerge --update $file locale/template.pot;
+done
diff --git a/signs/common.lua b/signs/common.lua
index 08dd4b8..7771d49 100644
--- a/signs/common.lua
+++ b/signs/common.lua
@@ -18,6 +18,9 @@
along with signs. If not, see <http://www.gnu.org/licenses/>.
--]]
+local S = signs.intllib
+local F = function(...) return minetest.formspec_escape(S(...)) end
+
function signs.set_formspec(pos)
local meta = minetest.get_meta(pos)
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
@@ -27,17 +30,17 @@ function signs.set_formspec(pos)
if maxlines == 1 then
formspec = "size[6,3]"..
- "field[0.5,0.7;5.5,1;display_text;Displayed text;${display_text}]"..
- "button_exit[2,2;2,1;ok;Write]"
+ "field[0.5,0.7;5.5,1;display_text;"..F("Displayed text")..";${display_text}]"..
+ "button_exit[2,2;2,1;ok;"..F("Write").."]"
else
local extralabel = ""
if maxlines then
- extralabel = " (first "..maxlines.." lines only)"
+ extralabel = F(" (first %s lines only)"):format(maxlines)
end
formspec = "size[6,4]"..
- "textarea[0.5,0.7;5.5,2;display_text;Displayed text"..extralabel..";${display_text}]"..
- "button_exit[2,3;2,1;ok;Write]"
+ "textarea[0.5,0.7;5.5,2;display_text;"..F("Displayed text")..""..extralabel..";${display_text}]"..
+ "button_exit[2,3;2,1;ok;"..F("Write").."]"
end
meta:set_string("formspec", formspec)
diff --git a/signs/depends.txt b/signs/depends.txt
index b017eff..0c5fcba 100644
--- a/signs/depends.txt
+++ b/signs/depends.txt
@@ -2,3 +2,4 @@ default
display_lib
font_lib
homedecor?
+intllib?
diff --git a/signs/init.lua b/signs/init.lua
index d3118b9..efa1b26 100644
--- a/signs/init.lua
+++ b/signs/init.lua
@@ -21,11 +21,11 @@
signs = {}
signs.path = minetest.get_modpath("signs")
+-- Load support for intllib.
+local MP = minetest.get_modpath(minetest.get_current_modname())
+local S, NS = dofile(MP.."/intllib.lua")
+signs.intllib = S
+
dofile(signs.path.."/common.lua")
dofile(signs.path.."/nodes.lua")
dofile(signs.path.."/crafts.lua")
-
-
-
-
-
diff --git a/signs/intllib.lua b/signs/intllib.lua
new file mode 100644
index 0000000..6669d72
--- /dev/null
+++ b/signs/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/signs/locale/fr.po b/signs/locale/fr.po
new file mode 100644
index 0000000..ebfc543
--- /dev/null
+++ b/signs/locale/fr.po
@@ -0,0 +1,55 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 10:06+0200\n"
+"PO-Revision-Date: 2017-05-08 07:08+0200\n"
+"Last-Translator: Peppy <peppy@twang-factory.com>\n"
+"Language-Team: \n"
+"Language: fr\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.8.12\n"
+
+#: common.lua
+msgid "Displayed text"
+msgstr "Texte affiché"
+
+#: common.lua nodes.lua
+msgid "Write"
+msgstr "Écrire"
+
+#: common.lua
+#, lua-format
+msgid " (first %s lines only)"
+msgstr " (uniquement les %s premières lignes)"
+
+#: nodes.lua
+msgid "Title"
+msgstr "Titre"
+
+#: nodes.lua
+msgid "Text"
+msgstr "Texte"
+
+#: nodes.lua
+msgid "Close"
+msgstr "Fermer"
+
+#: nodes.lua
+msgid "(right-click to read more text)"
+msgstr "(Clic-droit pour afficher le texte entier)"
+
+#: nodes.lua
+msgid "Wooden direction sign"
+msgstr "Panneau indicateur en bois"
+
+#: nodes.lua
+msgid "Poster"
+msgstr "Affiche"
diff --git a/signs/locale/template.pot b/signs/locale/template.pot
new file mode 100644
index 0000000..fc374aa
--- /dev/null
+++ b/signs/locale/template.pot
@@ -0,0 +1,55 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 10:06+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: common.lua
+msgid "Displayed text"
+msgstr ""
+
+#: common.lua nodes.lua
+msgid "Write"
+msgstr ""
+
+#: common.lua
+#, lua-format
+msgid " (first %s lines only)"
+msgstr ""
+
+#: nodes.lua
+msgid "Title"
+msgstr ""
+
+#: nodes.lua
+msgid "Text"
+msgstr ""
+
+#: nodes.lua
+msgid "Close"
+msgstr ""
+
+#: nodes.lua
+msgid "(right-click to read more text)"
+msgstr ""
+
+#: nodes.lua
+msgid "Wooden direction sign"
+msgstr ""
+
+#: nodes.lua
+msgid "Poster"
+msgstr ""
diff --git a/signs/nodes.lua b/signs/nodes.lua
index 36d07dc..abd63a0 100644
--- a/signs/nodes.lua
+++ b/signs/nodes.lua
@@ -18,6 +18,9 @@
along with signs. If not, see <http://www.gnu.org/licenses/>.
--]]
+local S = signs.intllib
+local F = function(...) return minetest.formspec_escape(S(...)) end
+
-- Poster specific formspec
local function on_rightclick_poster(pos, node, player)
local formspec
@@ -25,9 +28,9 @@ local function on_rightclick_poster(pos, node, player)
if not minetest.is_protected(pos, player:get_player_name()) then
formspec =
"size[6.5,7.5]"..
- "field[0.5,0.7;6,1;display_text;Title;"..minetest.formspec_escape(meta:get_string("display_text")).."]"..
- "textarea[0.5,1.7;6,6;text;Text;"..minetest.formspec_escape(meta:get_string("text")).."]"..
- "button_exit[2,7;2,1;ok;Write]"
+ "field[0.5,0.7;6,1;display_text;"..F("Title")..";"..minetest.formspec_escape(meta:get_string("display_text")).."]"..
+ "textarea[0.5,1.7;6,6;text;"..F("Text")..";"..minetest.formspec_escape(meta:get_string("text")).."]"..
+ "button_exit[2,7;2,1;ok;"..F("Write").."]"
minetest.show_formspec(player:get_player_name(),
"signs:poster@"..minetest.pos_to_string(pos),
formspec)
@@ -37,7 +40,7 @@ local function on_rightclick_poster(pos, node, player)
"label[0.5,0;"..minetest.formspec_escape(meta:get_string("display_text")).."]"..
"textarea[0.5,1;6,7;;"..minetest.formspec_escape(meta:get_string("text"))..";]"..
"bgcolor[#111]"..
- "button_exit[2,7;2,1;ok;Close]"
+ "button_exit[2,7;2,1;ok;"..F("Close").."]"
minetest.show_formspec(player:get_player_name(),
"",
formspec)
@@ -53,7 +56,7 @@ local function on_receive_fields_poster(pos, formname, fields, player)
meta:set_string("display_text", fields.display_text)
meta:set_string("text", fields.text)
meta:set_string("infotext", "\""..fields.display_text
- .."\"\n(right-click to read more text)")
+ .."\"\n"..S("(right-click to read more text)"))
display_lib.update_entities(pos)
end
end
@@ -75,7 +78,7 @@ local models = {
color="#000",
},
node_fields = {
- description="Wooden direction sign",
+ description=S("Wooden direction sign"),
tiles={"signs_wooden_direction.png"},
inventory_image="signs_wooden_inventory.png",
on_place=signs.on_place_direction,
@@ -103,7 +106,7 @@ local models = {
color="#000",
},
node_fields = {
- description="Wooden direction sign",
+ description=S("Wooden direction sign"),
tiles={"signs_wooden_direction.png"},
inventory_image="signs_wooden_inventory.png",
on_place=signs.on_place_direction,
@@ -133,7 +136,7 @@ local models = {
valign="top",
},
node_fields = {
- description="Poster",
+ description=S("Poster"),
tiles={"signs_poster.png"},
inventory_image="signs_poster_inventory.png",
on_construct=display_lib.on_construct,
@@ -169,4 +172,3 @@ else
},
})
end
-
diff --git a/signs/tools/updatepo.sh b/signs/tools/updatepo.sh
new file mode 100755
index 0000000..feb2504
--- /dev/null
+++ b/signs/tools/updatepo.sh
@@ -0,0 +1,25 @@
+#! /bin/bash
+
+# To create a new translation:
+# msginit --locale=ll_CC -o locale/ll_CC.po -i locale/template.pot
+
+cd "$(dirname "${BASH_SOURCE[0]}")/..";
+
+# Extract translatable strings.
+xgettext --from-code=UTF-8 \
+ --language=Lua \
+ --sort-by-file \
+ --keyword=S \
+ --keyword=NS:1,2 \
+ --keyword=N_ \
+ --keyword=F \
+ --add-comments='Translators:' \
+ --add-location=file \
+ -o locale/template.pot \
+ $(find . -name '*.lua')
+
+# Update translations.
+find locale -name '*.po' | while read -r file; do
+ echo $file
+ msgmerge --update $file locale/template.pot;
+done
diff --git a/signs_road/depends.txt b/signs_road/depends.txt
index e34c7f1..e6b5e54 100644
--- a/signs_road/depends.txt
+++ b/signs_road/depends.txt
@@ -3,3 +3,4 @@ dye
display_lib
font_lib
signs
+intllib?
diff --git a/signs_road/init.lua b/signs_road/init.lua
index e78d583..60c1b66 100644
--- a/signs_road/init.lua
+++ b/signs_road/init.lua
@@ -22,10 +22,10 @@
signs_road = {}
signs_road.path = minetest.get_modpath("signs_road")
+-- Load support for intllib.
+local MP = minetest.get_modpath(minetest.get_current_modname())
+local S, NS = dofile(MP.."/intllib.lua")
+signs_road.intllib = S
+
dofile(signs_road.path.."/nodes.lua")
dofile(signs_road.path.."/crafts.lua")
-
-
-
-
-
diff --git a/signs_road/intllib.lua b/signs_road/intllib.lua
new file mode 100644
index 0000000..6669d72
--- /dev/null
+++ b/signs_road/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/signs_road/locale/fr.po b/signs_road/locale/fr.po
new file mode 100644
index 0000000..8208347
--- /dev/null
+++ b/signs_road/locale/fr.po
@@ -0,0 +1,35 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 09:50+0200\n"
+"PO-Revision-Date: 2017-05-08 06:40+0200\n"
+"Last-Translator: Peppy <peppy@twang-factory.com>\n"
+"Language-Team: \n"
+"Language: fr\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.8.12\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#: nodes.lua
+msgid "Blue street sign"
+msgstr "Plaque de rue bleue"
+
+#: nodes.lua
+msgid "Green street sign"
+msgstr "Plaque de rue verte"
+
+#: nodes.lua
+msgid "Black direction sign"
+msgstr "Panneau indicateur noir"
+
+#: nodes.lua
+msgid "Green direction sign"
+msgstr "Panneau indicateur vert"
diff --git a/signs_road/locale/template.pot b/signs_road/locale/template.pot
new file mode 100644
index 0000000..1b5cfae
--- /dev/null
+++ b/signs_road/locale/template.pot
@@ -0,0 +1,34 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 09:50+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: nodes.lua
+msgid "Blue street sign"
+msgstr ""
+
+#: nodes.lua
+msgid "Green street sign"
+msgstr ""
+
+#: nodes.lua
+msgid "Black direction sign"
+msgstr ""
+
+#: nodes.lua
+msgid "Green direction sign"
+msgstr ""
diff --git a/signs_road/nodes.lua b/signs_road/nodes.lua
index d5d32c2..980d4a3 100644
--- a/signs_road/nodes.lua
+++ b/signs_road/nodes.lua
@@ -19,6 +19,8 @@
along with signs_road. If not, see <http://www.gnu.org/licenses/>.
--]]
+local S = signs_road.intllib
+
local models = {
blue_street={
depth = 1/16,
@@ -30,7 +32,7 @@ local models = {
color="#fff",
},
node_fields = {
- description="Blue street sign",
+ description=S("Blue street sign"),
tiles={"signs_blue_street.png"},
inventory_image="signs_blue_street_inventory.png",
},
@@ -45,7 +47,7 @@ local models = {
color="#fff",
},
node_fields = {
- description="Green street sign",
+ description=S("Green street sign"),
tiles={"signs_green_street.png"},
inventory_image="signs_green_street_inventory.png",
},
@@ -60,7 +62,7 @@ local models = {
color="#000",
},
node_fields = {
- description="Black direction sign",
+ description=S("Black direction sign"),
tiles={"signs_black_right.png"},
inventory_image="signs_black_inventory.png",
on_place=signs.on_place_direction,
@@ -77,7 +79,7 @@ local models = {
color="#000",
},
node_fields = {
- description="Black direction sign",
+ description=S("Black direction sign"),
tiles={"signs_black_left.png"},
inventory_image="signs_black_inventory.png",
groups={not_in_creative_inventory=1},
@@ -97,7 +99,7 @@ local models = {
color="#fff",
},
node_fields = {
- description="Green direction sign",
+ description=S("Green direction sign"),
tiles={"signs_green_direction.png"},
inventory_image="signs_green_dir_inventory.png",
on_place=signs.on_place_direction,
@@ -125,7 +127,7 @@ local models = {
color="#fff",
},
node_fields = {
- description="Green direction sign",
+ description=S("Green direction sign"),
tiles={"signs_green_direction.png"},
inventory_image="signs_green_dir_inventory.png",
on_place=signs.on_place_direction,
diff --git a/signs_road/tools/updatepo.sh b/signs_road/tools/updatepo.sh
new file mode 100755
index 0000000..feb2504
--- /dev/null
+++ b/signs_road/tools/updatepo.sh
@@ -0,0 +1,25 @@
+#! /bin/bash
+
+# To create a new translation:
+# msginit --locale=ll_CC -o locale/ll_CC.po -i locale/template.pot
+
+cd "$(dirname "${BASH_SOURCE[0]}")/..";
+
+# Extract translatable strings.
+xgettext --from-code=UTF-8 \
+ --language=Lua \
+ --sort-by-file \
+ --keyword=S \
+ --keyword=NS:1,2 \
+ --keyword=N_ \
+ --keyword=F \
+ --add-comments='Translators:' \
+ --add-location=file \
+ -o locale/template.pot \
+ $(find . -name '*.lua')
+
+# Update translations.
+find locale -name '*.po' | while read -r file; do
+ echo $file
+ msgmerge --update $file locale/template.pot;
+done
diff --git a/steles/config.lua b/steles/config.lua
index d525010..551429d 100644
--- a/steles/config.lua
+++ b/steles/config.lua
@@ -18,6 +18,8 @@
along with steles. If not, see <http://www.gnu.org/licenses/>.
--]]
+local S = steles.intllib
+
steles.materials = {
'default:stone',
'default:sandstone',
@@ -26,3 +28,10 @@ steles.materials = {
'technic:granite',
}
+steles.materials_desc = {
+ S("Stone Stele"),
+ S("Sandstone Stele"),
+ S("Desert Stone Stele"),
+ S("Marble Stele"),
+ S("Granite Stele"),
+}
diff --git a/steles/depends.txt b/steles/depends.txt
index cf8c669..35625c0 100644
--- a/steles/depends.txt
+++ b/steles/depends.txt
@@ -1,4 +1,5 @@
default
+intllib?
display_lib
font_lib
technic?
diff --git a/steles/init.lua b/steles/init.lua
index dd5068f..a84a596 100644
--- a/steles/init.lua
+++ b/steles/init.lua
@@ -21,10 +21,11 @@
steles = {}
steles.path = minetest.get_modpath("steles")
+-- Load support for intllib.
+local MP = minetest.get_modpath(minetest.get_current_modname())
+local S, NS = dofile(MP.."/intllib.lua")
+steles.intllib = S
+
dofile(steles.path.."/config.lua")
dofile(steles.path.."/nodes.lua")
dofile(steles.path.."/crafts.lua")
-
-
-
-
diff --git a/steles/intllib.lua b/steles/intllib.lua
new file mode 100644
index 0000000..6669d72
--- /dev/null
+++ b/steles/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/steles/locale/fr.po b/steles/locale/fr.po
new file mode 100644
index 0000000..1785d8a
--- /dev/null
+++ b/steles/locale/fr.po
@@ -0,0 +1,47 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 10:06+0200\n"
+"PO-Revision-Date: 2017-08-05 09:03+0200\n"
+"Last-Translator: fat115 <fat115@framasoft.org>\n"
+"Language-Team: \n"
+"Language: fr\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.8.12\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#: config.lua
+msgid "Stone Stele"
+msgstr "Stèle en pierre"
+
+#: config.lua
+msgid "Sandstone Stele"
+msgstr "Stèle en grès"
+
+#: config.lua
+msgid "Desert Stone Stele"
+msgstr "Stèle en pierre du désert"
+
+#: config.lua
+msgid "Marble Stele"
+msgstr "Stèle en marbre"
+
+#: config.lua
+msgid "Granite Stele"
+msgstr "Stèle en granit"
+
+#: nodes.lua
+msgid "Displayed text (3 lines max)"
+msgstr "Texte à afficher (3 lignes maxi.)"
+
+#: nodes.lua
+msgid "Write"
+msgstr "Écrire"
diff --git a/steles/locale/template.pot b/steles/locale/template.pot
new file mode 100644
index 0000000..f494ee7
--- /dev/null
+++ b/steles/locale/template.pot
@@ -0,0 +1,46 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-08-05 10:06+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: config.lua
+msgid "Stone Stele"
+msgstr ""
+
+#: config.lua
+msgid "Sandstone Stele"
+msgstr ""
+
+#: config.lua
+msgid "Desert Stone Stele"
+msgstr ""
+
+#: config.lua
+msgid "Marble Stele"
+msgstr ""
+
+#: config.lua
+msgid "Granite Stele"
+msgstr ""
+
+#: nodes.lua
+msgid "Displayed text (3 lines max)"
+msgstr ""
+
+#: nodes.lua
+msgid "Write"
+msgstr ""
diff --git a/steles/nodes.lua b/steles/nodes.lua
index 36515f0..a298293 100644
--- a/steles/nodes.lua
+++ b/steles/nodes.lua
@@ -18,6 +18,9 @@
along with steles. If not, see <http://www.gnu.org/licenses/>.
--]]
+local S = steles.intllib
+local F = function(...) return minetest.formspec_escape(S(...)) end
+
function steles.on_receive_fields(pos, formname, fields, player)
if not minetest.is_protected(pos, player:get_player_name()) then
local meta = minetest.get_meta(pos)
@@ -31,7 +34,7 @@ end
display_lib.register_display_entity("steles:text")
-for _, material in ipairs(steles.materials) do
+for i, material in ipairs(steles.materials) do
local ndef = minetest.registered_nodes[material]
@@ -39,7 +42,7 @@ for _, material in ipairs(steles.materials) do
local parts = material:split(":")
minetest.register_node("steles:"..parts[2].."_stele", {
- description = ndef.description.." Stele",
+ description = steles.materials_desc[i],
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
@@ -65,9 +68,11 @@ for _, material in ipairs(steles.materials) do
on_place = display_lib.on_place,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
- meta:set_string("formspec", "size[6,4]"..
- "textarea[0.5,0.7;5.5,2;display_text;Displayed text (3 lines max);${display_text}]"..
- "button_exit[2,3;2,1;ok;Write]")
+ meta:set_string("formspec", "size[6,4]"
+ .."textarea[0.5,0.7;5.5,2;display_text;"
+ ..F("Displayed text (3 lines max)")
+ ..";${display_text}]"
+ .."button_exit[2,3;2,1;ok;"..F("Write").."]")
display_lib.on_construct(pos)
end,
on_destruct = display_lib.on_destruct,
@@ -85,4 +90,3 @@ for _, material in ipairs(steles.materials) do
})
end
end
-
diff --git a/steles/tools/updatepo.sh b/steles/tools/updatepo.sh
new file mode 100755
index 0000000..feb2504
--- /dev/null
+++ b/steles/tools/updatepo.sh
@@ -0,0 +1,25 @@
+#! /bin/bash
+
+# To create a new translation:
+# msginit --locale=ll_CC -o locale/ll_CC.po -i locale/template.pot
+
+cd "$(dirname "${BASH_SOURCE[0]}")/..";
+
+# Extract translatable strings.
+xgettext --from-code=UTF-8 \
+ --language=Lua \
+ --sort-by-file \
+ --keyword=S \
+ --keyword=NS:1,2 \
+ --keyword=N_ \
+ --keyword=F \
+ --add-comments='Translators:' \
+ --add-location=file \
+ -o locale/template.pot \
+ $(find . -name '*.lua')
+
+# Update translations.
+find locale -name '*.po' | while read -r file; do
+ echo $file
+ msgmerge --update $file locale/template.pot;
+done