aboutsummaryrefslogtreecommitdiff
path: root/signs
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 /signs
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
Diffstat (limited to 'signs')
-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
8 files changed, 205 insertions, 19 deletions
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