1
0
mirror of https://github.com/pyrollo/display_modpack.git synced 2025-07-15 06:20:26 +02:00

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
This commit is contained in:
fat115
2017-08-05 10:12:43 +02:00
parent 54108e8054
commit 2fef15d878
30 changed files with 715 additions and 50 deletions

View File

@ -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)

View File

@ -2,3 +2,4 @@ default
display_lib
font_lib
homedecor?
intllib?

View File

@ -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")

45
signs/intllib.lua Normal file
View File

@ -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

55
signs/locale/fr.po Normal file
View File

@ -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"

55
signs/locale/template.pot Normal file
View File

@ -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 ""

View File

@ -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

25
signs/tools/updatepo.sh Executable file
View File

@ -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