mirror of
https://github.com/minetest-mods/drawers.git
synced 2024-12-22 20:42:22 +01:00
Add i18n support using intllib
This commit is contained in:
parent
cb616b0df9
commit
cde5c46e44
4
Makefile
Normal file
4
Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
PROJECT = drawers
|
||||
|
||||
updatepo:
|
||||
./tools/updatepo.sh
|
@ -2,3 +2,4 @@ default?
|
||||
mcl_core?
|
||||
screwdriver?
|
||||
pipeworks?
|
||||
intllib?
|
||||
|
13
init.lua
13
init.lua
@ -24,6 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
|
||||
-- Load support for intllib.
|
||||
local MP = core.get_modpath(core.get_current_modname())
|
||||
local S, NS = dofile(MP.."/intllib.lua")
|
||||
|
||||
drawers = {}
|
||||
drawers.drawer_visuals = {}
|
||||
|
||||
@ -51,10 +55,9 @@ drawers.enable_2x2 = not core.setting_getbool("drawers_disable_2x2")
|
||||
-- Load files
|
||||
--
|
||||
|
||||
local modpath = core.get_modpath("drawers")
|
||||
dofile(modpath .. "/lua/helpers.lua")
|
||||
dofile(modpath .. "/lua/visual.lua")
|
||||
dofile(modpath .. "/lua/api.lua")
|
||||
dofile(MP .. "/lua/helpers.lua")
|
||||
dofile(MP .. "/lua/visual.lua")
|
||||
dofile(MP .. "/lua/api.lua")
|
||||
|
||||
|
||||
--
|
||||
@ -62,7 +65,7 @@ dofile(modpath .. "/lua/api.lua")
|
||||
--
|
||||
|
||||
drawers.register_drawer("drawers:wood", {
|
||||
description = "Wooden",
|
||||
description = S("Wooden"),
|
||||
tiles1 = {"drawers_wood.png", "drawers_wood.png", "drawers_wood.png",
|
||||
"drawers_wood.png", "drawers_wood.png", "drawers_wood_front_1.png"},
|
||||
tiles2 = {"drawers_wood.png", "drawers_wood.png", "drawers_wood.png",
|
||||
|
45
intllib.lua
Normal file
45
intllib.lua
Normal 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
|
46
locale/template.pot
Normal file
46
locale/template.pot
Normal 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-04-11 12:56+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"
|
||||
|
||||
#: lua/helpers.lua
|
||||
msgid "@1 (@2% full)"
|
||||
msgstr ""
|
||||
|
||||
#: lua/helpers.lua
|
||||
msgid "@1 @2 (@3% full)"
|
||||
msgstr ""
|
||||
|
||||
#: lua/api.lua init.lua
|
||||
msgid "Wooden"
|
||||
msgstr ""
|
||||
|
||||
#: lua/api.lua
|
||||
msgid "@1 Drawer"
|
||||
msgstr ""
|
||||
|
||||
#: lua/api.lua
|
||||
msgid "@1 Drawers (1x2)"
|
||||
msgstr ""
|
||||
|
||||
#: lua/api.lua
|
||||
msgid "@1 Drawers (2x2)"
|
||||
msgstr ""
|
||||
|
||||
#: lua/visual.lua
|
||||
msgid "Empty"
|
||||
msgstr ""
|
12
lua/api.lua
12
lua/api.lua
@ -25,6 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
|
||||
-- Load support for intllib.
|
||||
local MP = core.get_modpath(core.get_current_modname())
|
||||
local S, NS = dofile(MP.."/intllib.lua")
|
||||
|
||||
drawers.node_box_simple = {
|
||||
{-0.5, -0.5, -0.4375, 0.5, 0.5, 0.5},
|
||||
{-0.5, -0.5, -0.5, -0.4375, 0.5, -0.4375},
|
||||
@ -125,7 +129,7 @@ function drawers.drawer_insert_object(pos, node, stack, direction)
|
||||
end
|
||||
|
||||
function drawers.register_drawer(name, def)
|
||||
def.description = def.description or "Wooden"
|
||||
def.description = def.description or S("Wooden")
|
||||
def.drawtype = "nodebox"
|
||||
def.node_box = {type = "fixed", fixed = drawers.node_box_simple}
|
||||
def.collision_box = {type = "regular"}
|
||||
@ -160,7 +164,7 @@ function drawers.register_drawer(name, def)
|
||||
if drawers.enable_1x1 then
|
||||
-- normal drawer 1x1 = 1
|
||||
local def1 = table.copy(def)
|
||||
def1.description = def.description .. " Drawer"
|
||||
def1.description = S("@1 Drawer", def.description)
|
||||
def1.tiles = def.tiles or def.tiles1
|
||||
def1.tiles1 = nil
|
||||
def1.tiles2 = nil
|
||||
@ -173,7 +177,7 @@ function drawers.register_drawer(name, def)
|
||||
if drawers.enable_1x2 then
|
||||
-- 1x2 = 2
|
||||
local def2 = table.copy(def)
|
||||
def2.description = def.description .. " Drawers (1x2)"
|
||||
def2.description = S("@1 Drawers (1x2)", def.description)
|
||||
def2.tiles = def.tiles2
|
||||
def2.tiles1 = nil
|
||||
def2.tiles2 = nil
|
||||
@ -185,7 +189,7 @@ function drawers.register_drawer(name, def)
|
||||
if drawers.enable_2x2 then
|
||||
-- 2x2 = 4
|
||||
local def4 = table.copy(def)
|
||||
def4.description = def.description .. " Drawers (2x2)"
|
||||
def4.description = S("@1 Drawers (2x2)", def.description)
|
||||
def4.tiles = def.tiles4
|
||||
def4.tiles1 = nil
|
||||
def4.tiles2 = nil
|
||||
|
@ -25,6 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
|
||||
-- Load support for intllib.
|
||||
local MP = core.get_modpath(core.get_current_modname())
|
||||
local S, NS = dofile(MP.."/intllib.lua")
|
||||
|
||||
function drawers.gen_info_text(basename, count, factor, stack_max)
|
||||
local maxCount = stack_max * factor
|
||||
local percent = count / maxCount * 100
|
||||
@ -32,10 +36,9 @@ function drawers.gen_info_text(basename, count, factor, stack_max)
|
||||
percent = math.floor(percent + 0.5)
|
||||
|
||||
if count == 0 then
|
||||
return basename .. " (" .. tostring(percent) .. "% full)"
|
||||
return S("@1 (@2% full)", basename, tostring(percent))
|
||||
else
|
||||
return tostring(count) .. " " .. basename .. " (" ..
|
||||
tostring(percent) .. "% full)"
|
||||
return S("@1 @2 (@3% full)", tostring(count), basename, tostring(percent))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,6 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
|
||||
-- Load support for intllib.
|
||||
local MP = core.get_modpath(core.get_current_modname())
|
||||
local S, NS = dofile(MP.."/intllib.lua")
|
||||
|
||||
core.register_entity("drawers:visual", {
|
||||
initial_properties = {
|
||||
hp_max = 1,
|
||||
@ -179,7 +183,7 @@ core.register_entity("drawers:visual", {
|
||||
self.itemName = ""
|
||||
meta:set_string("name"..self.visualId, self.itemName)
|
||||
self.texture = "blank.png"
|
||||
itemDescription = "Empty"
|
||||
itemDescription = S("Empty")
|
||||
end
|
||||
|
||||
local infotext = drawers.gen_info_text(itemDescription,
|
||||
@ -243,7 +247,7 @@ core.register_entity("drawers:visual", {
|
||||
if core.registered_items[self.itemName] then
|
||||
itemDescription = core.registered_items[self.itemName].description
|
||||
else
|
||||
itemDescription = "Empty"
|
||||
itemDescription = S("Empty")
|
||||
end
|
||||
local infotext = drawers.gen_info_text(itemDescription,
|
||||
self.count, self.stackMaxFactor, self.itemStackMax)
|
||||
|
22
tools/updatepo.sh
Executable file
22
tools/updatepo.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#! /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 \
|
||||
--keyword=S \
|
||||
--keyword=NS:1,2 \
|
||||
--keyword=N_ \
|
||||
--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
|
Loading…
Reference in New Issue
Block a user