Ingame-Translation added.

This commit is contained in:
A.C.M 2019-11-21 19:23:21 +01:00
parent 82c32f03ed
commit 1d6c714919
12 changed files with 487 additions and 7 deletions

2
depends.txt Normal file
View File

@ -0,0 +1,2 @@
default
intllib?

View File

@ -21,10 +21,22 @@ barchair = {}
barchair.modname = minetest.get_current_modname()
barchair.modpath = minetest.get_modpath(barchair.modname)
barchair.version = 1
barchair.revision = 1
barchair.revision = 2
local material = {{nil, nil, nil}}
local S
if(minetest.get_modpath("intllib")) then
S = dofile(barchair.modpath .."/intllib.lua")
print("[MOD] " .. barchair.modname .. ": translating in intllib-mode.")
else
S = minetest.get_translator(barchair.modname)
print("[MOD] " .. barchair.modname .. ": translating in minetest-mode.")
end -- if(minetest.get_modpath(
-- Various default Wood
material = {
-- Mod , Material, burnvalue
@ -93,7 +105,7 @@ function barchair.register_barchair(mod, mat, burnvalue)
-- Barchair
minetest.register_node(":" .. barchair.modname .. ":barchairs_plain_" .. mod .. "_" .. mat, {
description = "Barchair plain " .. mod .. mat,
description = S("Barchair plain ") .. mod .. mat,
tiles = minetest.registered_nodes[mod .. ":" .. mat].tiles,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
@ -149,7 +161,7 @@ function barchair.register_barchair(mod, mat, burnvalue)
-- Bar Front
minetest.register_node(":" .. barchair.modname .. ":bar_front_" .. mod .. "_" .. mat, {
description = "Bar front " .. mod .. "_" .. mat,
description = S("Bar front ") .. mod .. "_" .. mat,
tiles = minetest.registered_nodes[mod .. ":" .. mat].tiles,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
@ -196,7 +208,7 @@ function barchair.register_barchair(mod, mat, burnvalue)
-- Bar Corner left
minetest.register_node(":" .. barchair.modname .. ":bar_corner_left_" .. mod .. "_" .. mat, {
description = "Bar corner left " .. mod .. "_" .. mat,
description = S("Bar corner left ") .. mod .. "_" .. mat,
tiles = minetest.registered_nodes[mod .. ":" .. mat].tiles,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
@ -244,7 +256,7 @@ function barchair.register_barchair(mod, mat, burnvalue)
-- Bar Corner right
minetest.register_node(":" .. barchair.modname .. ":bar_corner_right_" .. mod .. "_" .. mat, {
description = "Bar corner right " .. mod .. "_" .. mat,
description = S("Bar corner right ") .. mod .. "_" .. mat,
tiles = minetest.registered_nodes[mod .. ":" .. mat].tiles,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
@ -292,7 +304,7 @@ function barchair.register_barchair(mod, mat, burnvalue)
-- Bar Side
minetest.register_node(":" .. barchair.modname .. ":bar_side_" .. mod .. "_" .. mat, {
description = "Bar side " .. mod .. "_" .. mat,
description = S("Bar side ") .. mod .. "_" .. mat,
tiles = minetest.registered_nodes[mod .. ":" .. mat].tiles,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),

45
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

6
locale/barchairs.de.tr Normal file
View File

@ -0,0 +1,6 @@
# textdomain: barchairs
Barchair plain =Barstuhl einfach
Bar front =Bar vorne
Bar corner left =Bar Ecke links
Bar corner right =Bar Ecke rechts
Bar side =Bar seitlich

38
locale/de_DE.pot Normal file
View File

@ -0,0 +1,38 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
#
# acm <undertakers_help@yahoo.com>, 2019.
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-21 18:50+0100\n"
"PO-Revision-Date: 2019-11-21 19:00+0100\n"
"Last-Translator: acm <undertakers_help@yahoo.com>\n"
"Language-Team: German <kde-i18n-de@kde.org>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Lokalize 19.08.3\n"
#: init.lua
msgid "Barchair plain "
msgstr "Barstuhl einfach"
#: init.lua
msgid "Bar front "
msgstr "Bar vorne"
#: init.lua
msgid "Bar corner left "
msgstr "Bar Ecke links"
#: init.lua
msgid "Bar corner right "
msgstr "Bar Ecke rechts"
#: init.lua
msgid "Bar side "
msgstr "Bar seitlich"

38
locale/template.pot Normal file
View File

@ -0,0 +1,38 @@
# 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: 2019-11-21 18:50+0100\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"
#: init.lua
msgid "Barchair plain "
msgstr ""
#: init.lua
msgid "Bar front "
msgstr ""
#: init.lua
msgid "Bar corner left "
msgstr ""
#: init.lua
msgid "Bar corner right "
msgstr ""
#: init.lua
msgid "Bar side "
msgstr ""

6
locale/template.txt Normal file
View File

@ -0,0 +1,6 @@
# textdomain: barchairs
Barchair plain =
Bar front =
Bar corner left =
Bar corner right =
Bar side =

View File

@ -1,5 +1,5 @@
name = barchairs
description = A mod which adds Barchairs.
depends = default
optional_depends =
optional_depends = intllib

142
tools/findtext.lua Executable file
View File

@ -0,0 +1,142 @@
#! /usr/bin/env lua
local me = arg[0]:gsub(".*[/\\](.*)$", "%1")
local function err(fmt, ...)
io.stderr:write(("%s: %s\n"):format(me, fmt:format(...)))
os.exit(1)
end
local output
local inputs = { }
local lang
local author
local i = 1
local function usage()
print([[
Usage: ]]..me..[[ [OPTIONS] FILE...
Extract translatable strings from the given FILE(s).
Available options:
-h,--help Show this help screen and exit.
-o,--output X Set output file (default: stdout).
-a,--author X Set author.
-l,--lang X Set language name.
]])
os.exit(0)
end
while i <= #arg do
local a = arg[i]
if (a == "-h") or (a == "--help") then
usage()
elseif (a == "-o") or (a == "--output") then
i = i + 1
if i > #arg then
err("missing required argument to `%s'", a)
end
output = arg[i]
elseif (a == "-a") or (a == "--author") then
i = i + 1
if i > #arg then
err("missing required argument to `%s'", a)
end
author = arg[i]
elseif (a == "-l") or (a == "--lang") then
i = i + 1
if i > #arg then
err("missing required argument to `%s'", a)
end
lang = arg[i]
elseif a:sub(1, 1) ~= "-" then
table.insert(inputs, a)
else
err("unrecognized option `%s'", a)
end
i = i + 1
end
if #inputs == 0 then
err("no input files")
end
local outfile = io.stdout
local function printf(fmt, ...)
outfile:write(fmt:format(...))
end
if output then
local e
outfile, e = io.open(output, "w")
if not outfile then
err("error opening file for writing: %s", e)
end
end
if author or lang then
outfile:write("\n")
end
if lang then
printf("# Language: %s\n", lang)
end
if author then
printf("# Author: %s\n", author)
end
if author or lang then
outfile:write("\n")
end
local escapes = {
["\n"] = "\\n",
["="] = "\\=",
["\\"] = "\\\\",
}
local function escape(s)
return s:gsub("[\\\n=]", escapes)
end
local messages = { }
for _, file in ipairs(inputs) do
local infile, e = io.open(file, "r")
if infile then
for line in infile:lines() do
for s in line:gmatch('S%("([^"]*)"') do
table.insert(messages, s)
end
end
infile:close()
else
io.stderr:write(("%s: WARNING: error opening file: %s\n"):format(me, e))
end
end
table.sort(messages)
local last_msg
for _, msg in ipairs(messages) do
if msg ~= last_msg then
printf("%s =\n", escape(msg))
end
last_msg = msg
end
if output then
outfile:close()
end
--[[
TESTS:
S("foo") S("bar")
S("bar")
S("foo")
]]

131
tools/updatetext.lua Normal file
View File

@ -0,0 +1,131 @@
#! /usr/bin/env lua
local basedir = ""
if arg[0]:find("[/\\]") then
basedir = arg[0]:gsub("(.*[/\\]).*$", "%1"):gsub("\\", "/")
end
if basedir == "" then basedir = "./" end
-- Required by load_strings()
function string.trim(s) -- luacheck: ignore
return s:gsub("^%s*(.-)%s*$", "%1")
end
dofile(basedir.."/../lib.lua")
local me = arg[0]:gsub(".*[/\\](.*)$", "%1")
local function err(fmt, ...)
io.stderr:write(("%s: %s\n"):format(me, fmt:format(...)))
os.exit(1)
end
local output, outfile, template
local catalogs = { }
local function usage()
print([[
Usage: ]]..me..[[ [OPTIONS] TEMPLATE CATALOG...
Update a catalog with new strings from a template.
Available options:
-h,--help Show this help screen and exit.
-o,--output X Set output file (default: stdout).
Messages in the template that are not on the catalog are added to the
catalog at the end.
This tool also checks messages that are in the catalog but not in the
template, and reports such lines. It's up to the user to remove such
lines, if so desired.
]])
os.exit(0)
end
local i = 1
while i <= #arg do
local a = arg[i]
if (a == "-h") or (a == "--help") then
usage()
elseif (a == "-o") or (a == "--output") then
i = i + 1
if i > #arg then
err("missing required argument to `%s'", a)
end
output = arg[i]
elseif a:sub(1, 1) ~= "-" then
if not template then
template = a
else
table.insert(catalogs, a)
end
else
err("unrecognized option `%s'", a)
end
i = i + 1
end
if not template then
err("no template specified")
elseif #catalogs == 0 then
err("no catalogs specified")
end
local f, e = io.open(template, "r")
if not f then
err("error opening template: %s", e)
end
local escapes = { ["\n"] = "\\n", ["="] = "\\=", ["\\"] = "\\\\", }
local function escape(s)
return s:gsub("[\\\n=]", escapes)
end
if output then
outfile, e = io.open(output, "w")
if not outfile then
err("error opening file for writing: %s", e)
end
end
local template_msgs = intllib.load_strings(template)
for _, file in ipairs(catalogs) do
print("Processing: "..file)
local catalog_msgs = intllib.load_strings(file)
local dirty_lines = { }
if catalog_msgs then
-- Add new entries from template.
for k in pairs(template_msgs) do
if not catalog_msgs[k] then
print("NEW: "..k)
table.insert(dirty_lines, escape(k).." =")
end
end
-- Check for old messages.
for k, v in pairs(catalog_msgs) do
if not template_msgs[k] then
print("OLD: "..k)
table.insert(dirty_lines, "OLD: "..escape(k).." = "..escape(v))
end
end
if #dirty_lines > 0 then
local outf
outf, e = io.open(file, "a+")
if outf then
outf:write("\n")
for _, line in ipairs(dirty_lines) do
outf:write(line)
outf:write("\n")
end
outf:close()
else
io.stderr:write(("%s: WARNING: cannot write: %s\n"):format(me, e))
end
end
else
io.stderr:write(("%s: WARNING: could not load catalog\n"):format(me))
end
end

33
tools/xgettext.bat Normal file
View File

@ -0,0 +1,33 @@
@echo off
setlocal
set me=%~n0
rem # Uncomment the following line if gettext is not in your PATH.
rem # Value must be absolute and end in a backslash.
rem set gtprefix=C:\path\to\gettext\bin\
if "%1" == "" (
echo Usage: %me% FILE... 1>&2
exit 1
)
set xgettext=%gtprefix%xgettext.exe
set msgmerge=%gtprefix%msgmerge.exe
md locale > nul 2>&1
echo Generating template... 1>&2
echo %xgettext% --from-code=UTF-8 -kS -kNS:1,2 -k_ -o locale/template.pot %*
%xgettext% --from-code=UTF-8 -kS -kNS:1,2 -k_ -o locale/template.pot %*
if %ERRORLEVEL% neq 0 goto done
cd locale
for %%f in (*.po) do (
echo Updating %%f... 1>&2
%msgmerge% --update %%f template.pot
)
echo DONE! 1>&2
:done

27
tools/xgettext.sh Executable file
View File

@ -0,0 +1,27 @@
#! /bin/bash
me=$(basename "${BASH_SOURCE[0]}");
if [[ $# -lt 1 ]]; then
echo "Usage: $me FILE..." >&2;
exit 1;
fi
mkdir -p locale;
echo "Generating template..." >&2;
xgettext --from-code=UTF-8 \
--keyword=S \
--keyword=NS:1,2 \
--keyword=N_ \
--add-comments='Translators:' \
--add-location=file \
-o locale/template.pot \
"$@" \
|| exit;
find locale -name '*.po' -type f | while read -r file; do
echo "Updating $file..." >&2;
msgmerge --update "$file" locale/template.pot;
done
echo "DONE!" >&2;