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,8 @@
along with steles. If not, see <http://www.gnu.org/licenses/>.
--]]
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"),
}

View File

@ -1,4 +1,5 @@
default
intllib?
display_lib
font_lib
technic?

View File

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

45
steles/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

47
steles/locale/fr.po Normal file
View File

@ -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 <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-08-05 09:03+0200\n"
"Last-Translator: fat115 <fat115@framasoft.org>\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"

View File

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

View File

@ -18,6 +18,9 @@
along with steles. If not, see <http://www.gnu.org/licenses/>.
--]]
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

25
steles/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