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 --- steles/config.lua | 9 +++++++++ steles/depends.txt | 1 + steles/init.lua | 9 +++++---- steles/intllib.lua | 45 ++++++++++++++++++++++++++++++++++++++++++++ steles/locale/fr.po | 47 ++++++++++++++++++++++++++++++++++++++++++++++ steles/locale/template.pot | 46 +++++++++++++++++++++++++++++++++++++++++++++ steles/nodes.lua | 16 ++++++++++------ steles/tools/updatepo.sh | 25 ++++++++++++++++++++++++ 8 files changed, 188 insertions(+), 10 deletions(-) create mode 100644 steles/intllib.lua create mode 100644 steles/locale/fr.po create mode 100644 steles/locale/template.pot create mode 100755 steles/tools/updatepo.sh (limited to 'steles') 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 . --]] +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 . + +-- 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 , 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 \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 , 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 \n" +"Language-Team: LANGUAGE \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 . --]] +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 -- cgit v1.2.3