Added intllib support (thanks Xanthin)

This commit is contained in:
TenPlus1 2016-06-07 20:29:06 +01:00
parent b0c2e6433f
commit a9981e3518
7 changed files with 154 additions and 43 deletions

@ -1,24 +1,26 @@
local S = protector.intllib
protector.removal_names = ""
minetest.register_chatcommand("delprot", {
params = "",
description = "Remove Protectors near players with names provided (separate names with spaces)",
description = S("Remove Protectors near players with names provided (separate names with spaces)"),
privs = {server = true},
func = function(name, param)
if not param or param == "" then
minetest.chat_send_player(name,
"Protector Names to remove: "
.. protector.removal_names)
S("Protector Names to remove: %1",
protector.removal_names))
return
end
if param == "-" then
minetest.chat_send_player(name,
"Name List Reset")
S("Name List Reset"))
protector.removal_names = ""

@ -1,3 +1,4 @@
default
doors?
mobs?
mobs?
intllib?

@ -3,6 +3,8 @@
-- WTFPL licenced code from the old doors mod and included an edited version
-- of it within this mod for local use.
local S = protector.intllib
-- Registers a door
function register_door(name, def)
def.groups.not_in_creative_inventory = 1
@ -295,7 +297,7 @@ end
local name = "protector:door_wood"
register_door(name, {
description = "Protected Wooden Door",
description = S("Protected Wooden Door"),
inventory_image = "doors_wood.png^protector_logo.png",
groups = {
snappy = 1, choppy = 2, oddly_breakable_by_hand = 2,
@ -328,7 +330,7 @@ minetest.register_craft({
local name = "protector:door_steel"
register_door(name, {
description = "Protected Steel Door",
description = S("Protected Steel Door"),
inventory_image = "doors_steel.png^protector_logo.png",
groups = {
snappy = 1, bendy = 2, cracky = 1,
@ -419,7 +421,7 @@ end
-- Protected Wooden Trapdoor
register_trapdoor("protector:trapdoor", {
description = "Protected Trapdoor",
description = S("Protected Trapdoor"),
inventory_image = "doors_trapdoor.png^protector_logo.png",
wield_image = "doors_trapdoor.png^protector_logo.png",
tile_front = "doors_trapdoor.png^protector_logo.png",
@ -450,7 +452,7 @@ minetest.register_craft({
-- Protected Steel Trapdoor
register_trapdoor("protector:trapdoor_steel", {
description = "Protected Steel Trapdoor",
description = S("Protected Steel Trapdoor"),
inventory_image = "doors_trapdoor_steel.png^protector_logo.png",
wield_image = "doors_trapdoor_steel.png^protector_logo.png",
tile_front = "doors_trapdoor_steel.png^protector_logo.png",
@ -480,7 +482,7 @@ minetest.register_craft({
-- Protected Chest
minetest.register_node("protector:chest", {
description = "Protected Chest",
description = S("Protected Chest"),
tiles = {
"default_chest_top.png", "default_chest_top.png",
"default_chest_side.png", "default_chest_side.png",
@ -497,7 +499,7 @@ minetest.register_node("protector:chest", {
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext", "Protected Chest")
meta:set_string("infotext", S("Protected Chest"))
meta:set_string("name", "")
inv:set_size("main", 8 * 4)
end,
@ -517,16 +519,14 @@ minetest.register_node("protector:chest", {
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()
.. " moves stuff to protected chest at "
.. minetest.pos_to_string(pos))
minetest.log("action", S("@1 moves stuff to protected chest at @2",
player:get_player_name(), minetest.pos_to_string(pos)))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()
.. " takes stuff from protected chest at "
.. minetest.pos_to_string(pos))
minetest.log("action", S("@1 takes stuff from protected chest at @2",
player:get_player_name(), minetest.pos_to_string(pos)))
end,
on_rightclick = function(pos, node, clicker)
@ -547,10 +547,10 @@ minetest.register_node("protector:chest", {
.. default.gui_bg_img
.. default.gui_slots
.. "list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"
.. "button[0,4.5;2,0.25;toup;To Chest]"
.. "button[0,4.5;2,0.25;toup;" .. S("To Chest") .. "]"
.. "field[2.3,4.8;4,0.25;chestname;;"
.. meta:get_string("name") .. "]"
.. "button[6,4.5;2,0.25;todn;To Inventory]"
.. "button[6,4.5;2,0.25;todn;" .. S("To Inventory") .. "]"
.. "list[current_player;main;0,5;8,1;]"
.. "list[current_player;main;0,6.08;8,3;8]"
.. "listring[nodemeta:" .. spos .. ";main]"
@ -622,9 +622,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta:set_string("name", fields.chestname)
meta:set_string("infotext",
"Protected Chest (" .. fields.chestname .. ")")
S("Protected Chest (@1)", fields.chestname))
else
meta:set_string("infotext", "Protected Chest")
meta:set_string("infotext", S("Protected Chest"))
end
end

@ -7,6 +7,28 @@ protector.radius = (tonumber(minetest.setting_get("protector_radius")) or 5)
protector.drop = minetest.setting_getbool("protector_drop") or false
protector.hurt = (tonumber(minetest.setting_get("protector_hurt")) or 0)
-- Intllib
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
else
S = function(s, a, ...)
if a == nil then
return s
end
a = {a, ...}
return s:gsub("(@?)@(%(?)(%d+)(%)?)",
function(e, o, n, c)
if e == ""then
return a[tonumber(n)] .. (o == "" and c or "")
else
return "@" .. o .. n .. c
end
end)
end
end
protector.intllib = S
protector.get_member_list = function(meta)
return meta:get_string("members"):split(" ")
@ -65,10 +87,10 @@ protector.generate_formspec = function(meta)
.. default.gui_bg
.. default.gui_bg_img
.. default.gui_slots
.. "label[2.5,0;-- Protector interface --]"
.. "label[0,1;PUNCH node to show protected area or USE for area check]"
.. "label[0,2;Members:]"
.. "button_exit[2.5,6.2;3,0.5;close_me;Close]"
.. "label[2.5,0;" .. S("-- Protector interface --") .. "]"
.. "label[0,1;" .. S("PUNCH node to show protected area or USE for area check") .. "]"
.. "label[0,2;" .. S("Members:") .. "]"
.. "button_exit[2.5,6.2;3,0.5;close_me;" .. S("Close") .. "]"
local members = protector.get_member_list(meta)
local npp = 12 -- max users added onto protector list
@ -154,20 +176,20 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
if infolevel == 1 then
minetest.chat_send_player(digger,
"This area is owned by " .. owner .. " !")
S("This area is owned by @1!", owner))
elseif infolevel == 2 then
minetest.chat_send_player(digger,
"This area is owned by " .. owner .. ".")
S("This area is owned by @1.", owner))
minetest.chat_send_player(digger,
"Protection located at: " .. minetest.pos_to_string(pos[n]))
S("Protection located at: @1", minetest.pos_to_string(pos[n])))
if members ~= "" then
minetest.chat_send_player(digger,
"Members: " .. members .. ".")
S("Members: @1.", members))
end
end
@ -178,15 +200,15 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
if infolevel == 2 then
minetest.chat_send_player(digger,
"This area is owned by " .. owner .. ".")
S("This area is owned by @1.", owner))
minetest.chat_send_player(digger,
"Protection located at: " .. minetest.pos_to_string(pos[n]))
S("Protection located at: @1", minetest.pos_to_string(pos[n])))
if members ~= "" then
minetest.chat_send_player(digger,
"Members: " .. members .. ".")
S("Members: @1.", members))
end
return false
@ -199,10 +221,10 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
if #pos < 1 then
minetest.chat_send_player(digger,
"This area is not protected.")
S("This area is not protected."))
end
minetest.chat_send_player(digger, "You can build here.")
minetest.chat_send_player(digger, S("You can build here."))
end
return true
@ -270,7 +292,7 @@ function protector.check_overlap(itemstack, placer, pointed_thing)
placer:get_player_name(), true, 3) then
minetest.chat_send_player(placer:get_player_name(),
"Overlaps into above players protected area")
S("Overlaps into above players protected area"))
return
end
@ -282,7 +304,7 @@ end
--= Protection Block
minetest.register_node("protector:protect", {
description = "Protection Block",
description = S("Protection Block"),
drawtype = "nodebox",
tiles = {
"moreblocks_circle_stone_bricks.png",
@ -309,7 +331,7 @@ minetest.register_node("protector:protect", {
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
meta:set_string("infotext", "Protection (owned by " .. meta:get_string("owner") .. ")")
meta:set_string("infotext", S("Protection (owned by @1)", meta:get_string("owner")))
meta:set_string("members", "")
end,
@ -362,7 +384,7 @@ minetest.register_craft({
--= Protection Logo
minetest.register_node("protector:protect2", {
description = "Protection Logo",
description = S("Protection Logo"),
tiles = {"protector_logo.png"},
wield_image = "protector_logo.png",
inventory_image = "protector_logo.png",
@ -390,7 +412,7 @@ minetest.register_node("protector:protect2", {
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
meta:set_string("infotext", "Protection (owned by " .. meta:get_string("owner") .. ")")
meta:set_string("infotext", S("Protection (owned by @1)", meta:get_string("owner")))
meta:set_string("members", "")
end,
@ -543,4 +565,4 @@ dofile(minetest.get_modpath("protector") .. "/doors_chest.lua")
dofile(minetest.get_modpath("protector") .. "/pvp.lua")
dofile(minetest.get_modpath("protector") .. "/admin.lua")
print ("[MOD] Protector Redo loaded")
print (S("[MOD] Protector Redo loaded"))

43
locale/de.txt Normal file

@ -0,0 +1,43 @@
# German Translation for protector mod
# Deutsche Übersetzung der protector Mod
# last update: 2016/June/5
# Author: Xanthin
#admin.lua
Remove Protectors near players with names provided (separate names with spaces) = Entferne Stoerschuetzer von bestimmten Namen in der Naehe von Spielern (trenne Namen durch Leerzeichen)
Protector Names to remove: @1 = Stoerschutznamen zum Entfernen: @1
Name List Reset = Namensliste zurueckgesetzt
#doors_chest.lua
Protected Wooden Door = Geschützte Holztür
Protected Steel Door = Geschützte Stahltür
Protected Trapdoor = Geschützte Falltür
Protected Steel Trapdoor = Geschützte Stahlfalltür
Protected Chest = Geschützte Truhe
@1 moves stuff to protected chest at @2 = @1 verlagert Dinge in geschützte Truhe bei @2
@1 takes stuff from protected chest at @2 = @1 nimmt Dinge aus geschützter Truhe bei @2
To Chest = Zur Truhe
To Inventory = Zum Inventar
Protected Chest (@1) = Geschützte Truhe (@1)
#init.lua
-- Protector interface -- = -- Störschutz-Interface --
PUNCH node to show protected area or USE for area check = SCHLAGE Node, um geschützten Bereich anzuzeigen oder\nBENUTZE für Bereichsprüfung
Members: = Mitglieder:
Close = Schließen
This area is owned by @1! = Dieses Gebiet gehoert @1!
This area is owned by @1. = Dieses Gebiet gehoert @1.
Protection located at: @1 = Stoerschutz befindet sich bei: @1
Members: @1. = Mitglieder: @1.
This area is not protected. = Dieses Gebiet ist nicht geschuetzt.
You can build here. = Du kannst hier bauen.
Overlaps into above players protected area = Ueberlappt in geschuetzen Bereich eines Spielers
Protection Block = Störschutzblock
Protection (owned by @1) = Störschutz (gehört @1)
Protection Logo = Störschutzlogo
[MOD] Protector Redo loaded = [MOD] Protector Redo geladen
#pvp.lua
[Protector] on_punchplayer called with nil objects = on_punchplayer wurde durch "nil objects" aufgerufen
[Protector] pvp_protect not active, update your version of Minetest = pvp_protect ist nicht aktiv, aktualisiere deine Minetestversion
[Protector] pvp_protect is disabled = pvp_protect ist ausgeschaltet

41
locale/template.txt Normal file

@ -0,0 +1,41 @@
# Template for translations of protector mod
# last update: 2016/June/5
#admin.lua
Remove Protectors near players with names provided (separate names with spaces) =
Protector Names to remove: @1 =
Name List Reset =
#doors_chest.lua
Protected Wooden Door =
Protected Steel Door =
Protected Trapdoor =
Protected Steel Trapdoor =
Protected Chest =
@1 moves stuff to protected chest at @2 =
@1 takes stuff from protected chest at @2 =
To Chest =
To Inventory =
Protected Chest (@1) =
#init.lua
-- Protector interface -- =
PUNCH node to show protected area or USE for area check =
Members: =
Close =
This area is owned by @1! =
This area is owned by @1. =
Protection located at: @1 =
Members: @1. =
This area is not protected. =
You can build here. =
Overlaps into above players protected area =
Protection Block =
Protection (owned by @1) =
Protection Logo =
[MOD] Protector Redo loaded =
#pvp.lua
[Protector] on_punchplayer called with nil objects =
[Protector] pvp_protect not active, update your version of Minetest =
[Protector] pvp_protect is disabled =

@ -1,4 +1,6 @@
local S = protector.intllib
-- get static spawn position
local statspawn = (minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 2, z = 0})
@ -16,7 +18,7 @@ if minetest.setting_getbool("enable_pvp") and protector.pvp then
if not player
or not hitter then
print("[Protector] on_punchplayer called with nil objects")
print(S("[Protector] on_punchplayer called with nil objects"))
end
if not hitter:is_player() then
@ -43,9 +45,9 @@ if minetest.setting_getbool("enable_pvp") and protector.pvp then
end)
else
print("[Protector] pvp_protect not active, update your version of Minetest")
print(S("[Protector] pvp_protect not active, update your version of Minetest"))
end
else
print("[Protector] pvp_protect is disabled")
print(S("[Protector] pvp_protect is disabled"))
end