Translate possibility

master
Wuzzy 2020-11-18 15:31:57 +01:00
parent e46331f954
commit 377e113386
1 changed files with 43 additions and 29 deletions

View File

@ -1,5 +1,8 @@
local S = minetest.get_translator("cmdtool")
local F = minetest.formspec_escape
local NEWLINE = "\n"
local DESCRIPTION = "Command Tool"
local DESCRIPTION = S("Command Tool")
local MAX_CMD_TOOLTIP_LEN = 48
local split_commands = function(commands_string)
@ -18,9 +21,9 @@ local set_commands = function(itemstack, commands_string)
end
local tooltip = DESCRIPTION .. NEWLINE .. first_cmd
if #cmds == 2 then
tooltip = tooltip .. NEWLINE .. string.format("… and %d more command", #cmds - 1)
tooltip = tooltip .. NEWLINE .. S("… and 1 more command")
elseif #cmds > 2 then
tooltip = tooltip .. NEWLINE .. string.format("… and %d more commands", #cmds - 1)
tooltip = tooltip .. NEWLINE .. S("… and @1 more command(s)", #cmds - 1)
end
meta:set_string("description", tooltip)
else
@ -108,23 +111,34 @@ local execute_command = function(itemstack, player, pointed_thing)
local required_privs = def.privs
for priv, _ in pairs(required_privs) do
if player_privs[priv] ~= true then
minetest.chat_send_player(player_name, "Insufficient privileges for using command “"..cmd_name.."”! You need the “"..priv.."” privilege.")
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", S("Insufficient privileges for command “@1”! You need the “@2” privilege.", cmd_name, priv)))
return
end
end
-- All tests survived!
-- Call the command
def.func(player_name, cmd_params)
local retval, msg = def.func(player_name, cmd_params)
-- Print return value and message
if retval == true then
minetest.chat_send_player(player_name, minetest.colorize("#00FF00", "["..S("OK").."] ".. cmd))
elseif retval == false then
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", "["..S("FAIL").."] ".. cmd))
elseif retval == nil then
minetest.chat_send_player(player_name, minetest.colorize("#FF8800", "["..S("UNKN").."] ".. cmd))
end
if msg ~= nil and msg ~= "" then
minetest.chat_send_player(player_name, "> " .. msg)
end
else
-- TODO: Rewrite error msg
minetest.chat_send_player(player_name, "Placeholders in command “"..cmd_name.."” do not apply!")
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", S("Nothing pointed!")))
end
else
minetest.chat_send_player(player_name, "The command “"..cmd_name.."” does not exist!")
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", S("The command “@1” does not exist!", cmd_name)))
return
end
else
minetest.chat_send_player(player_name, "Invalid command!")
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", S("Invalid command!")))
return
end
-- One iteration is done. We continue with the next command.
@ -145,40 +159,40 @@ local open_command_configuration = function(itemstack, player, pointed_thing)
end
local formspec =
"size[6,6]"..
"textarea[0.25,0;6,5;commands;Commands:;"..minetest.formspec_escape(commands_str).."]"..
"button_exit[0.5,5;2,1;ok;OK]"..
"button_exit[3.5,5;2,1;cancel;Cancel]"
"textarea[0.25,0;6,5;commands;"..F(S("Commands:"))..";"..F(commands_str).."]"..
"button_exit[0.5,5;2,1;ok;"..F(S("OK")).."]"..
"button_exit[3.5,5;2,1;cancel;"..F(S("Cancel")).."]"
minetest.show_formspec(player_name, "cmdtool", formspec)
end
minetest.register_tool("cmdtool:cmdtool", {
description = DESCRIPTION,
_doc_items_longdesc = "This is a programmable tool which can be used to run server commands.",
_doc_items_usagehelp = [[This tool is very mighty, so handle with care!
Rightclick to set the commands. Write a list of server commands you wish to execute (with one command per line), in that order, but without the trailing slash like in the chat. Confirm with the OK button.
To run the commands, use the attack key. Note that commands might fail if you lack the required privileges or you made a mistake.
_doc_items_longdesc = S("This is a programmable tool which can be used to run server commands."),
_doc_items_usagehelp = S("This tool is very mighty, so handle with care!").."\n"..
S("Rightclick to set the commands. Write a list of server commands you wish to execute (with one command per line), in that order, but without the trailing slash like in the chat. Confirm with the OK button.").."\n"..
S("To run the commands, use the attack key. Note that commands might fail if you lack the required privileges or you made a mistake.").."\n\n"..
Optionally, you can use the following placeholders to insert variable values into your commands:
@playername: Your player name
@plx, @ply and @plz: Your player coordinates
@@: Literal at sign
S("Optionally, you can use the following placeholders to insert variable values into your commands:").."\n"..
S("• @playername: Your player name").."\n"..
S("• @plx, @ply and @plz: Your player coordinates").."\n"..
S("• @@: Literal at sign").."\n\n"..
These placeholders only work when you use the tool on a block.
@ptx, @pty and @ptz: Coordinates of the pointed node (i.e. block)
@nodename: Itemstring of the pointed node
@param2: param2 of the pointed node
S("These placeholders only work when you use the tool on a block.").."\n"..
S("• @ptx, @pty and @ptz: Coordinates of the pointed node (i.e. block)").."\n"..
S("• @nodename: Itemstring of the pointed node").."\n"..
S("• @param2: param2 of the pointed node").."\n\n"..
Refer to Advancd usage > Server commands to learn more about server commands.
S("Refer to “Advancd usage > Server commands” to learn more about server commands.").."\n\n\n"..
Example 1:
S([[Example 1:
time 12000
Sets time to midday.
Sets time to midday.]]).."\n\n"..
Example 2:
S([[Example 2:
teleport @plx 9 @plz
giveme default:apple
Teleports you to Y=9 without changing the X and Z coordinates, then gives you an apple.]],
Teleports you to Y=9 without changing the X and Z coordinates, then gives you an apple.]]),
inventory_image = "cmdtool_cmdtool.png",
wield_imagee = "cmdtool_cmdtool.png",
on_use = execute_command,