From 2fef15d878f00c72a799aebc5b8a6bd61489296e Mon Sep 17 00:00:00 2001 From: fat115 Date: Sat, 5 Aug 2017 10:12:43 +0200 Subject: 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 --- signs_road/depends.txt | 1 + signs_road/init.lua | 10 +++++----- signs_road/intllib.lua | 45 ++++++++++++++++++++++++++++++++++++++++++ signs_road/locale/fr.po | 35 ++++++++++++++++++++++++++++++++ signs_road/locale/template.pot | 34 +++++++++++++++++++++++++++++++ signs_road/nodes.lua | 14 +++++++------ signs_road/tools/updatepo.sh | 25 +++++++++++++++++++++++ 7 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 signs_road/intllib.lua create mode 100644 signs_road/locale/fr.po create mode 100644 signs_road/locale/template.pot create mode 100755 signs_road/tools/updatepo.sh (limited to 'signs_road') 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 . + +-- 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 , 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 \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 , 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 \n" +"Language-Team: LANGUAGE \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 . --]] +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 -- cgit v1.2.3