Add localization support
parent
d0003bfa1e
commit
a3baffcd4c
2
TODO.txt
2
TODO.txt
|
@ -1,3 +1,3 @@
|
|||
|
||||
TODO:
|
||||
- add localization support
|
||||
- specify that "pos" & "name" are NOT meta data when using infostick
|
||||
|
|
60
init.lua
60
init.lua
|
@ -2,10 +2,12 @@
|
|||
alternode = {}
|
||||
alternode.name = core.get_current_modname()
|
||||
|
||||
local S = core.get_translator(alternode.name)
|
||||
|
||||
|
||||
core.register_craftitem(alternode.name .. ":infostick", {
|
||||
description = "Tool for retrieving information about node",
|
||||
short_description = "Info Stick",
|
||||
description = S("Tool for retrieving information about a node"),
|
||||
short_description = S("Info Stick"),
|
||||
inventory_image = "alternode_infostick.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
|
@ -15,27 +17,26 @@ core.register_craftitem(alternode.name .. ":infostick", {
|
|||
|
||||
local granted, missing = core.check_player_privs(pname, {server=true,})
|
||||
if not granted then
|
||||
core.chat_send_player(pname, "You do not have privileges to use this item (missing priviliges: " .. table.concat(missing, ", ") .. ")")
|
||||
core.chat_send_player(pname,
|
||||
S("You do not have privileges to use this item (missing priviliges: @1)", table.concat(missing, ", ")))
|
||||
return
|
||||
end
|
||||
|
||||
if pointed_thing.type ~= "node" then
|
||||
core.chat_send_player(pname, "This item only works on nodes")
|
||||
core.chat_send_player(pname, S("This item only works on nodes"))
|
||||
return
|
||||
end
|
||||
|
||||
local pos = core.get_pointed_thing_position(pointed_thing, false)
|
||||
local node = core.get_node_or_nil(pos)
|
||||
if not node then
|
||||
core.chat_send_player(pname, "That doesn't seem to be a proper node")
|
||||
core.chat_send_player(pname, S("That doesn't seem to be a proper node"))
|
||||
return
|
||||
end
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
local infostring = "pos: x=" .. tostring(pos.x)
|
||||
.. ", y=" .. tostring(pos.y)
|
||||
.. ", z=" .. tostring(pos.z)
|
||||
.. "; name=" .. node.name
|
||||
local infostring = S("pos: x@=@1, y@=@2, z@=@3; name@=@4",
|
||||
tostring(pos.x), tostring(pos.y), tostring(pos.z), node.name)
|
||||
|
||||
for _, key in ipairs({"infotext", "owner"}) do
|
||||
local value = meta:get_string(key)
|
||||
|
@ -61,20 +62,20 @@ end
|
|||
|
||||
|
||||
core.register_chatcommand("setmeta", {
|
||||
params = "<x> <y> <z> <key> <value>",
|
||||
description = "Alter meta data of a node",
|
||||
params = S("<x> <y> <z> <key> <value>"),
|
||||
description = S("Alter meta data of a node"),
|
||||
privs = {server=true,},
|
||||
func = function(player, param)
|
||||
local plist = string.split(param, " ")
|
||||
|
||||
if #plist < 3 then
|
||||
core.chat_send_player(player, "You must supply proper coordinates")
|
||||
core.chat_send_player(player, S("You must supply proper coordinates"))
|
||||
return false
|
||||
end
|
||||
|
||||
for _, p in ipairs({plist[1], plist[2], plist[3]}) do
|
||||
if tonumber(p) == nil then
|
||||
core.chat_send_player(player, "You must supply proper coordinates")
|
||||
core.chat_send_player(player, S("You must supply proper coordinates"))
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -89,7 +90,7 @@ core.register_chatcommand("setmeta", {
|
|||
if key then key = key:trim() end
|
||||
|
||||
if not key or key == "" then
|
||||
core.chat_send_player(player, "You must supply a key parameter")
|
||||
core.chat_send_player(player, S("You must supply a key parameter"))
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -101,7 +102,7 @@ core.register_chatcommand("setmeta", {
|
|||
end
|
||||
|
||||
if #value == 0 then
|
||||
core.chat_send_player(player, "You must supply a value parameter")
|
||||
core.chat_send_player(player, S("You must supply a value parameter"))
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -109,18 +110,13 @@ core.register_chatcommand("setmeta", {
|
|||
|
||||
if not retval then
|
||||
core.chat_send_player(player,
|
||||
"Failed to set node meta at "
|
||||
.. tostring(pos.x) .. ","
|
||||
.. tostring(pos.y) .. ","
|
||||
.. tostring(pos.z))
|
||||
S("Failed to set node meta at @1,@2,@3",
|
||||
tostring(pos.x), tostring(pos.y), tostring(pos.z)))
|
||||
else
|
||||
core.chat_send_player(player,
|
||||
"Set meta \"" .. key .. "="
|
||||
.. core.get_meta(pos):get_string(key)
|
||||
.. "\" for node at "
|
||||
.. tostring(pos.x) .. ","
|
||||
.. tostring(pos.y) .. ","
|
||||
.. tostring(pos.z))
|
||||
S('Set meta "@1@=@2" for node at @3,@4,@5',
|
||||
key, core.get_meta(pos):get_string(key),
|
||||
tostring(pos.x), tostring(pos.y), tostring(pos.z)))
|
||||
end
|
||||
|
||||
return retval
|
||||
|
@ -128,20 +124,20 @@ core.register_chatcommand("setmeta", {
|
|||
})
|
||||
|
||||
core.register_chatcommand("getmeta", {
|
||||
params = "<x> <y> <z> <key>",
|
||||
description = "Retrieve meta data of a node",
|
||||
params = S("<x> <y> <z> <key>"),
|
||||
description = S("Retrieve meta data of a node"),
|
||||
privs = {server=true,},
|
||||
func = function(player, param)
|
||||
local plist = string.split(param, " ")
|
||||
|
||||
if #plist < 3 then
|
||||
core.chat_send_player(player, "You must supply proper coordinates")
|
||||
core.chat_send_player(player, S("You must supply proper coordinates"))
|
||||
return false
|
||||
end
|
||||
|
||||
for _, p in ipairs({plist[1], plist[2], plist[3]}) do
|
||||
if tonumber(p) == nil then
|
||||
core.chat_send_player(player, "You must supply proper coordinates")
|
||||
core.chat_send_player(player, S("You must supply proper coordinates"))
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -156,17 +152,17 @@ core.register_chatcommand("getmeta", {
|
|||
if key then key = key:trim() end
|
||||
|
||||
if not key or key == "" then
|
||||
core.chat_send_player(player, "You must supply a key parameter")
|
||||
core.chat_send_player(player, S("You must supply a key parameter"))
|
||||
return false
|
||||
end
|
||||
|
||||
local value = alternode.get(pos, key)
|
||||
if not value or value == "" then
|
||||
core.chat_send_player(player,
|
||||
"\"" .. key .. "\" key value not present in node meta data")
|
||||
S('"@1" key value not present in node meta data', key))
|
||||
else
|
||||
core.chat_send_player(player,
|
||||
"Meta value: " .. key .. "=" .. value)
|
||||
S("Meta value: @1@=@2", key, value))
|
||||
end
|
||||
|
||||
return true
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Translated by:
|
||||
|
||||
|
||||
Tool for retrieving information about a node=
|
||||
Info Stick=
|
||||
You do not have privileges to use this item (missing priviliges: @1)=
|
||||
This item only works on nodes=
|
||||
That doesn't seem to be a proper node=
|
||||
pos: x@=@1, y@=@2, z@=@3; name@=@4=
|
||||
<x> <y> <z> <key>=
|
||||
<x> <y> <z> <key> <value>=
|
||||
Alter meta data of a node=
|
||||
Retrieve meta data of a node=
|
||||
You must supply proper coordinates=
|
||||
You must supply a key parameter=
|
||||
You must supply a value parameter=
|
||||
Failed to set node meta at @1,@2,@3=
|
||||
Set meta "@1@=@2" for node at @3,@4,@5=
|
||||
"@1" key value not present in node meta data=
|
||||
Meta value: @1@=@2=
|
Loading…
Reference in New Issue