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 NEWLINE = "\n"
local DESCRIPTION = "Command Tool" local DESCRIPTION = S("Command Tool")
local MAX_CMD_TOOLTIP_LEN = 48 local MAX_CMD_TOOLTIP_LEN = 48
local split_commands = function(commands_string) local split_commands = function(commands_string)
@ -18,9 +21,9 @@ local set_commands = function(itemstack, commands_string)
end end
local tooltip = DESCRIPTION .. NEWLINE .. first_cmd local tooltip = DESCRIPTION .. NEWLINE .. first_cmd
if #cmds == 2 then 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 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 end
meta:set_string("description", tooltip) meta:set_string("description", tooltip)
else else
@ -108,23 +111,34 @@ local execute_command = function(itemstack, player, pointed_thing)
local required_privs = def.privs local required_privs = def.privs
for priv, _ in pairs(required_privs) do for priv, _ in pairs(required_privs) do
if player_privs[priv] ~= true then 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 return
end end
end end
-- All tests survived! -- All tests survived!
-- Call the command -- 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 else
-- TODO: Rewrite error msg minetest.chat_send_player(player_name, minetest.colorize("#FF0000", S("Nothing pointed!")))
minetest.chat_send_player(player_name, "Placeholders in command “"..cmd_name.."” do not apply!")
end end
else 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 return
end end
else else
minetest.chat_send_player(player_name, "Invalid command!") minetest.chat_send_player(player_name, minetest.colorize("#FF0000", S("Invalid command!")))
return return
end end
-- One iteration is done. We continue with the next command. -- One iteration is done. We continue with the next command.
@ -145,40 +159,40 @@ local open_command_configuration = function(itemstack, player, pointed_thing)
end end
local formspec = local formspec =
"size[6,6]".. "size[6,6]"..
"textarea[0.25,0;6,5;commands;Commands:;"..minetest.formspec_escape(commands_str).."]".. "textarea[0.25,0;6,5;commands;"..F(S("Commands:"))..";"..F(commands_str).."]"..
"button_exit[0.5,5;2,1;ok;OK]".. "button_exit[0.5,5;2,1;ok;"..F(S("OK")).."]"..
"button_exit[3.5,5;2,1;cancel;Cancel]" "button_exit[3.5,5;2,1;cancel;"..F(S("Cancel")).."]"
minetest.show_formspec(player_name, "cmdtool", formspec) minetest.show_formspec(player_name, "cmdtool", formspec)
end end
minetest.register_tool("cmdtool:cmdtool", { minetest.register_tool("cmdtool:cmdtool", {
description = DESCRIPTION, description = DESCRIPTION,
_doc_items_longdesc = "This is a programmable tool which can be used to run server commands.", _doc_items_longdesc = S("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! _doc_items_usagehelp = S("This tool is very mighty, so handle with care!").."\n"..
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. 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"..
To run the commands, use the attack key. Note that commands might fail if you lack the required privileges or you made a mistake. 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: S("Optionally, you can use the following placeholders to insert variable values into your commands:").."\n"..
@playername: Your player name S("• @playername: Your player name").."\n"..
@plx, @ply and @plz: Your player coordinates S("• @plx, @ply and @plz: Your player coordinates").."\n"..
@@: Literal at sign S("• @@: Literal at sign").."\n\n"..
These placeholders only work when you use the tool on a block. S("These placeholders only work when you use the tool on a block.").."\n"..
@ptx, @pty and @ptz: Coordinates of the pointed node (i.e. block) S("• @ptx, @pty and @ptz: Coordinates of the pointed node (i.e. block)").."\n"..
@nodename: Itemstring of the pointed node S("• @nodename: Itemstring of the pointed node").."\n"..
@param2: param2 of the pointed node 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 time 12000
Sets time to midday. Sets time to midday.]]).."\n\n"..
Example 2: S([[Example 2:
teleport @plx 9 @plz teleport @plx 9 @plz
giveme default:apple 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", inventory_image = "cmdtool_cmdtool.png",
wield_imagee = "cmdtool_cmdtool.png", wield_imagee = "cmdtool_cmdtool.png",
on_use = execute_command, on_use = execute_command,