Skip to content

Commit

Permalink
Introducing 'game_intllib' and S() for gettext
Browse files Browse the repository at this point in the history
The new branch 'game_intllib' is aiming at MT internationalization.

Please note the about 400 lines of code changed in the Lua code of the
existing mods by addition of a S("string") enclosure for GNU gettext.
This is in compliance to the GNU gettext toolchain procedures.

'game_intllib' is an attempt at providing internationalization support
for the default game mods specifically. Hopefully, we may delay the
issue of an optimal translation for the MT server into the future.

There is no requirement to include the 'game_intllib' mod into the
game code basis if an alternative solution for a translation of
user-facing strings of the default mods inside the game is in place.
However, the 'game_intllib' and tools may be helpful in assisting the
task of translation of user-facing strings of the default mods prior
a new release of the game and after introduction of new game code.

Please consider to look at my contribution in the MT forum:
https://forum.minetest.net/viewtopic.php?f=11&t=4929&p=346791#p346791

This is up to deliberations of the MT developers and the MT game devs.

*****************

This is the new branch 'game_intllib' comprising the following:

  - changed:   README.txt
  - changed:   mods/beds/beds.lua
  - changed:   mods/beds/depends.txt
  - new file:  mods/beds/gintllib.lua
  - changed:   mods/binoculars/depends.txt
  - new file:  mods/binoculars/gintllib.lua
  - changed:   mods/binoculars/init.lua
  - changed:   mods/boats/depends.txt
  - new file:  mods/boats/gintllib.lua
  - changed:   mods/boats/init.lua
  - changed:   mods/bones/depends.txt
  - new file:  mods/bones/gintllib.lua
  - changed:   mods/bones/init.lua
  - changed:   mods/bucket/depends.txt
  - new file:  mods/bucket/gintllib.lua
  - changed:   mods/bucket/init.lua
  - changed:   mods/butterflies/depends.txt
  - new file:  mods/butterflies/gintllib.lua
  - changed:   mods/butterflies/init.lua
  - changed:   mods/carts/cart_entity.lua
  - changed:   mods/carts/depends.txt
  - new file:  mods/carts/gintllib.lua
  - changed:   mods/carts/rails.lua
  - changed:   mods/creative/depends.txt
  - new file:  mods/creative/gintllib.lua
  - changed:   mods/creative/init.lua
  - changed:   mods/creative/inventory.lua
  - changed:   mods/default/chests.lua
  - changed:   mods/default/craftitems.lua
  - changed:   mods/default/depends.txt
  - changed:   mods/default/furnace.lua
  - new file:  mods/default/gintllib.lua
  - changed:   mods/default/nodes.lua
  - changed:   mods/default/tools.lua
  - changed:   mods/default/torch.lua
  - changed:   mods/default/trees.lua
  - changed:   mods/doors/depends.txt
  - new file:  mods/doors/gintllib.lua
  - changed:   mods/doors/init.lua
  - changed:   mods/dye/depends.txt
  - new file:  mods/dye/gintllib.lua
  - changed:   mods/dye/init.lua
  - changed:   mods/farming/api.lua
  - changed:   mods/farming/depends.txt
  - new file:  mods/farming/gintllib.lua
  - changed:   mods/farming/hoes.lua
  - changed:   mods/farming/init.lua
  - changed:   mods/farming/nodes.lua
  - changed:   mods/fire/depends.txt
  - new file:  mods/fire/gintllib.lua
  - changed:   mods/fire/init.lua
  - changed:   mods/fireflies/depends.txt
  - new file:  mods/fireflies/gintllib.lua
  - changed:   mods/fireflies/init.lua
  - changed:   mods/flowers/depends.txt
  - new file:  mods/flowers/gintllib.lua
  - changed:   mods/flowers/init.lua
  - new file:  mods/game_commands/depends.txt
  - new file:  mods/game_commands/gintllib.lua
  - changed:   mods/game_commands/init.lua
  - new file:  mods/game_intllib/LICENSE.md
  - new file:  mods/game_intllib/README.md
  - new file:  mods/game_intllib/description.txt
  - new file:  mods/game_intllib/doc/developer.md
  - new file:  mods/game_intllib/doc/localefile.md
  - new file:  mods/game_intllib/doc/translator.md
  - new file:  mods/game_intllib/gettext.lua
  - new file:  mods/game_intllib/init.lua
  - new file:  mods/game_intllib/intltest/README.md
  - new file:  mods/game_intllib/intltest/depends.txt
  - new file:  mods/game_intllib/intltest/gintllib.lua
  - new file:  mods/game_intllib/intltest/init.lua
  - new file:  mods/game_intllib/intltest/locale/es.po
  - new file:  mods/game_intllib/intltest/locale/template.pot
  - new file:  mods/game_intllib/lib.lua
  - new file:  mods/game_intllib/lib/gintllib.lua
  - new file:  mods/game_intllib/license.txt
  - new file:  mods/game_intllib/locale/de.po
  - new file:  mods/game_intllib/locale/template.pot
  - new file:  mods/game_intllib/tools/findtext.lua
  - new file:  mods/game_intllib/tools/updatetext.lua
  - new file:  mods/game_intllib/tools/xgettext.bat
  - new file:  mods/game_intllib/tools/xgettext.sh
  - changed:   mods/map/depends.txt
  - new file:  mods/map/gintllib.lua
  - changed:   mods/map/init.lua
  - new file:  mods/screwdriver/depends.txt
  - new file:  mods/screwdriver/gintllib.lua
  - changed:   mods/screwdriver/init.lua
  - new file:  mods/sethome/depends.txt
  - new file:  mods/sethome/gintllib.lua
  - changed:   mods/sethome/init.lua
  - changed:   mods/stairs/depends.txt
  - new file:  mods/stairs/gintllib.lua
  - changed:   mods/stairs/init.lua
  - changed:   mods/tnt/depends.txt
  - new file:  mods/tnt/gintllib.lua
  - changed:   mods/tnt/init.lua
  - changed:   mods/vessels/depends.txt
  - new file:  mods/vessels/gintllib.lua
  - changed:   mods/vessels/init.lua
  - changed:   mods/walls/depends.txt
  - new file:  mods/walls/gintllib.lua
  - changed:   mods/walls/init.lua
  - changed:   mods/wool/depends.txt
  - new file:  mods/wool/gintllib.lua
  - changed:   mods/wool/init.lua
  - changed:   mods/xpanes/depends.txt
  - new file:  mods/xpanes/gintllib.lua
  - changed:   mods/xpanes/init.lua

*****************

The 'game_intllib' internal mod is specifially aimed at default mods
internal to the game in the 'minetest_game' folder.

The original 'intllib' is an attempt at providing internationalization
support for external mods (something Minetest currently lacks).

IMHO the 'intllib' mod is a reliable and helpful tool and I have found
it to be both robust and compliant to the GNU gettext tool chain.

I would like to thank all of the MT developers and certainly @kaeza.
[snoopy (Zweihorn)] 2019-05-13
  • Loading branch information
Zweihorn committed May 12, 2019
1 parent 5c48c76 commit 2d8d7f4
Show file tree
Hide file tree
Showing 110 changed files with 6,661 additions and 481 deletions.
2 changes: 1 addition & 1 deletion README.txt
Expand Up @@ -15,7 +15,7 @@ The Minetest Game github master HEAD is generally compatible with the github
master HEAD of the Minetest engine.

Additionally, when the Minetest engine is tagged to be a certain version (eg.
0.4.10), Minetest Game is tagged with the version too.
5.0.1), Minetest Game is tagged with the version too.

When stable releases are made, Minetest Game is packaged and made available in
http://minetest.net/downloads/
Expand Down
10 changes: 8 additions & 2 deletions mods/beds/beds.lua 100644 → 100755
@@ -1,7 +1,13 @@
-- beds/beds.lua

-- Load support for game_intllib.
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP .. "/gintllib.lua")

-- Fancy shaped bed

beds.register_bed("beds:fancy_bed", {
description = "Fancy Bed",
description = S("Fancy Bed"),
inventory_image = "beds_bed_fancy.png",
wield_image = "beds_bed_fancy.png",
tiles = {
Expand Down Expand Up @@ -52,7 +58,7 @@ beds.register_bed("beds:fancy_bed", {
-- Simple shaped bed

beds.register_bed("beds:bed", {
description = "Simple Bed",
description = S("Simple Bed"),
inventory_image = "beds_bed.png",
wield_image = "beds_bed.png",
tiles = {
Expand Down
2 changes: 2 additions & 0 deletions mods/beds/depends.txt 100644 → 100755
@@ -1,2 +1,4 @@
default
wool
game_intllib?

50 changes: 50 additions & 0 deletions mods/beds/gintllib.lua
@@ -0,0 +1,50 @@
-- gintllib.lua
-- should be copied from ../game_intllib/lib/gintllib.lua (2019-05-12)

-- Please note: This is for the default minetest_game mod tree only.
-- For external mods one should make use of the original inttlib mod
-- without interference to the game_intllib mod and it's functions.

-- Fallback functions for when `game_intllib` is not installed.
-- Code released under ../gintllib/LICENSE.md [snoopy (Zweihorn)]

-- Minetest Game Translation with 'game_intllib' (based on 'intllib')
-- Copyright (2019) The Minetest Core & Minetest Game Developers (LGPLv2.1+)

-- Fallback to handle a S("string") enclosure if not installed.

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

-- Hopefully, use make_gettext_pair from game_intllib if installed.

if minetest.get_modpath("game_intllib") then
gettext, ngettext = gintllib.make_gettext_pair()
end

-- Fill in missing functions if game_intllib is not installed.

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
2 changes: 2 additions & 0 deletions mods/binoculars/depends.txt 100644 → 100755
@@ -1,2 +1,4 @@
default
creative?
game_intllib?

50 changes: 50 additions & 0 deletions mods/binoculars/gintllib.lua
@@ -0,0 +1,50 @@
-- gintllib.lua
-- should be copied from ../game_intllib/lib/gintllib.lua (2019-05-12)

-- Please note: This is for the default minetest_game mod tree only.
-- For external mods one should make use of the original inttlib mod
-- without interference to the game_intllib mod and it's functions.

-- Fallback functions for when `game_intllib` is not installed.
-- Code released under ../gintllib/LICENSE.md [snoopy (Zweihorn)]

-- Minetest Game Translation with 'game_intllib' (based on 'intllib')
-- Copyright (2019) The Minetest Core & Minetest Game Developers (LGPLv2.1+)

-- Fallback to handle a S("string") enclosure if not installed.

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

-- Hopefully, use make_gettext_pair from game_intllib if installed.

if minetest.get_modpath("game_intllib") then
gettext, ngettext = gintllib.make_gettext_pair()
end

-- Fill in missing functions if game_intllib is not installed.

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
8 changes: 7 additions & 1 deletion mods/binoculars/init.lua 100644 → 100755
@@ -1,7 +1,13 @@
-- binoculars/init.lua

-- Mod global namespace

binoculars = {}

-- Load support for game_intllib.
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP .. "/gintllib.lua")


-- Detect creative mod
local creative_mod = minetest.get_modpath("creative")
Expand Down Expand Up @@ -54,7 +60,7 @@ minetest.after(4.7, cyclic_update)
-- Binoculars item

minetest.register_craftitem("binoculars:binoculars", {
description = "Binoculars\nUse with 'Zoom' key",
description = S("Binoculars\nUse with 'Zoom' key"),
inventory_image = "binoculars_binoculars.png",
stack_max = 1,

Expand Down
1 change: 1 addition & 0 deletions mods/boats/depends.txt 100644 → 100755
@@ -1,2 +1,3 @@
default
player_api
game_intllib?
50 changes: 50 additions & 0 deletions mods/boats/gintllib.lua
@@ -0,0 +1,50 @@
-- gintllib.lua
-- should be copied from ../game_intllib/lib/gintllib.lua (2019-05-12)

-- Please note: This is for the default minetest_game mod tree only.
-- For external mods one should make use of the original inttlib mod
-- without interference to the game_intllib mod and it's functions.

-- Fallback functions for when `game_intllib` is not installed.
-- Code released under ../gintllib/LICENSE.md [snoopy (Zweihorn)]

-- Minetest Game Translation with 'game_intllib' (based on 'intllib')
-- Copyright (2019) The Minetest Core & Minetest Game Developers (LGPLv2.1+)

-- Fallback to handle a S("string") enclosure if not installed.

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

-- Hopefully, use make_gettext_pair from game_intllib if installed.

if minetest.get_modpath("game_intllib") then
gettext, ngettext = gintllib.make_gettext_pair()
end

-- Fill in missing functions if game_intllib is not installed.

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
12 changes: 9 additions & 3 deletions mods/boats/init.lua 100644 → 100755
@@ -1,3 +1,9 @@
-- boats/init.lua

-- Load support for game_intllib.
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP .. "/gintllib.lua")

--
-- Helper functions
--
Expand Down Expand Up @@ -149,13 +155,13 @@ function boat.on_step(self, dtime)
if ctrl.up and ctrl.down then
if not self.auto then
self.auto = true
minetest.chat_send_player(self.driver, "[boats] Cruise on")
minetest.chat_send_player(self.driver, S("[boats] Cruise on"))
end
elseif ctrl.down then
self.v = self.v - dtime * 1.8
if self.auto then
self.auto = false
minetest.chat_send_player(self.driver, "[boats] Cruise off")
minetest.chat_send_player(self.driver, S("[boats] Cruise off"))
end
elseif ctrl.up or self.auto then
self.v = self.v + dtime * 1.8
Expand Down Expand Up @@ -242,7 +248,7 @@ minetest.register_entity("boats:boat", boat)


minetest.register_craftitem("boats:boat", {
description = "Boat",
description = S("Boat"),
inventory_image = "boats_inventory.png",
wield_image = "boats_wield.png",
wield_scale = {x = 2, y = 2, z = 1},
Expand Down
2 changes: 2 additions & 0 deletions mods/bones/depends.txt 100644 → 100755
@@ -1 +1,3 @@
default
game_intllib?

50 changes: 50 additions & 0 deletions mods/bones/gintllib.lua
@@ -0,0 +1,50 @@
-- gintllib.lua
-- should be copied from ../game_intllib/lib/gintllib.lua (2019-05-12)

-- Please note: This is for the default minetest_game mod tree only.
-- For external mods one should make use of the original inttlib mod
-- without interference to the game_intllib mod and it's functions.

-- Fallback functions for when `game_intllib` is not installed.
-- Code released under ../gintllib/LICENSE.md [snoopy (Zweihorn)]

-- Minetest Game Translation with 'game_intllib' (based on 'intllib')
-- Copyright (2019) The Minetest Core & Minetest Game Developers (LGPLv2.1+)

-- Fallback to handle a S("string") enclosure if not installed.

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

-- Hopefully, use make_gettext_pair from game_intllib if installed.

if minetest.get_modpath("game_intllib") then
gettext, ngettext = gintllib.make_gettext_pair()
end

-- Fill in missing functions if game_intllib is not installed.

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

0 comments on commit 2d8d7f4

Please sign in to comment.