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 --- ontime_clocks/depends.txt | 1 + ontime_clocks/init.lua | 9 ++++---- ontime_clocks/intllib.lua | 45 +++++++++++++++++++++++++++++++++++++++ ontime_clocks/locale/fr.po | 43 +++++++++++++++++++++++++++++++++++++ ontime_clocks/locale/template.pot | 42 ++++++++++++++++++++++++++++++++++++ ontime_clocks/nodes.lua | 14 ++++++------ ontime_clocks/tools/updatepo.sh | 25 ++++++++++++++++++++++ 7 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 ontime_clocks/intllib.lua create mode 100644 ontime_clocks/locale/fr.po create mode 100644 ontime_clocks/locale/template.pot create mode 100755 ontime_clocks/tools/updatepo.sh (limited to 'ontime_clocks') 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 . + +-- 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 , 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 \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 , 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 "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 . --]] +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 -- cgit v1.2.3