diff options
Diffstat (limited to 'advtrains_luaautomation/chatcmds.lua')
-rw-r--r-- | advtrains_luaautomation/chatcmds.lua | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/advtrains_luaautomation/chatcmds.lua b/advtrains_luaautomation/chatcmds.lua index b6ffaee..7691013 100644 --- a/advtrains_luaautomation/chatcmds.lua +++ b/advtrains_luaautomation/chatcmds.lua @@ -1,28 +1,31 @@ --chatcmds.lua --Registers commands to modify the init and step code for LuaAutomation +-- Get current translator +local S = atlatc.translate + local function get_init_form(env, pname) local err = env.init_err or "" local code = env.init_code or "" local form = "size["..atlatc.CODE_FORM_SIZE.."]" .."style[code;font=mono]" - .."button[0.0,0.2;2.5,1;run;Run Init Code]" - .."button[2.5,0.2;2.5,1;cls;Clear S]" - .."button[5.0,0.2;2.5,1;save;Save]" - .."button[7.5,0.2;2.5,1;del;Delete Env.]" - .."textarea[0.3,1.5;"..atlatc.CODE_FORM_SIZE..";code;Environment initialization code;"..minetest.formspec_escape(code).."]" + .."button[0.0,0.2;2.5,1;run;"..S("Run Init Code").."]" + .."button[2.5,0.2;2.5,1;cls;"..S("Clear S").."]" + .."button[5.0,0.2;2.5,1;save;"..S("Save").."]" + .."button[7.5,0.2;2.5,1;del;"..S("Delete Env.").."]" + .."textarea[0.3,1.5;"..atlatc.CODE_FORM_SIZE..";code;"..S("Environment initialization code")..";"..minetest.formspec_escape(code).."]" .."label[0.0,9.7;"..err.."]" return form end core.register_chatcommand("env_setup", { params = "<environment name>", - description = "Set up and modify AdvTrains LuaAutomation environment", + description = S("Set up and modify AdvTrains LuaAutomation environment"), privs = {atlatc=true}, func = function(name, param) local env=atlatc.envs[param] - if not env then return false,"Invalid environment name!" end + if not env then return false,S("Invalid environment name!") end minetest.show_formspec(name, "atlatc_envsetup_"..param, get_init_form(env, name)) return true end, @@ -30,52 +33,52 @@ core.register_chatcommand("env_setup", { core.register_chatcommand("env_create", { params = "<environment name>", - description = "Create an AdvTrains LuaAutomation environment", + description = S("Create an AdvTrains LuaAutomation environment"), privs = {atlatc=true}, func = function(name, param) - if not param or param=="" then return false, "Name required!" end - if string.find(param, "[^a-zA-Z0-9-_]") then return false, "Invalid name (only common characters)" end - if atlatc.envs[param] then return false, "Environment already exists!" end + if not param or param=="" then return false, S("Name required!") end + if string.find(param, "[^a-zA-Z0-9-_]") then return false, S("Invalid name (only common characters)") end + if atlatc.envs[param] then return false, S("Environment already exists!") end atlatc.envs[param] = atlatc.env_new(param) atlatc.envs[param].subscribers = {name} - return true, "Created environment '"..param.."'. Use '/env_setup "..param.."' to define global initialization code, or start building LuaATC components!" + return true, S("Created environment '@1'. Use '/env_setup @2' to define global initialization code, or start building LuaATC components!", param, param) end, }) core.register_chatcommand("env_subscribe", { params = "<environment name>", - description = "Subscribe to the log of an Advtrains LuaATC environment", + description = S("Subscribe to the log of an Advtrains LuaATC environment"), privs = {atlatc=true}, func = function(name, param) local env=atlatc.envs[param] - if not env then return false,"Invalid environment name!" end + if not env then return false,S("Invalid environment name!") end for _,pname in ipairs(env.subscribers) do if pname==name then - return false, "Already subscribed!" + return false, S("Already subscribed!") end end table.insert(env.subscribers, name) - return true, "Subscribed to environment '"..param.."'." + return true, S("Subscribed to environment '@1'.", param) end, }) core.register_chatcommand("env_unsubscribe", { params = "<environment name>", - description = "Unubscribe to the log of an Advtrains LuaATC environment", + description = S("Unubscribe to the log of an Advtrains LuaATC environment"), privs = {atlatc=true}, func = function(name, param) local env=atlatc.envs[param] - if not env then return false,"Invalid environment name!" end + if not env then return false,S("Invalid environment name!") end for index,pname in ipairs(env.subscribers) do if pname==name then table.remove(env.subscribers, index) - return true, "Successfully unsubscribed!" + return true, S("Successfully unsubscribed!") end end - return false, "Not subscribed to environment '"..param.."'." + return false, S("Not subscribed!") end, }) core.register_chatcommand("env_subscriptions", { params = "[environment name]", - description = "List Advtrains LuaATC environments you are subscribed to (no parameters) or subscribers of an environment (giving an env name).", + description = S("List Advtrains LuaATC environments you are subscribed to (no parameters) or subscribers of an environment (giving an env name)."), privs = {atlatc=true}, func = function(name, param) if not param or param=="" then @@ -89,19 +92,19 @@ core.register_chatcommand("env_subscriptions", { end end if none then - return false, "Not subscribed to any!" + return false, S("Not subscribed to any!") end return true end local env=atlatc.envs[param] - if not env then return false,"Invalid environment name!" end + if not env then return false,S("Invalid environment name!") end local none=true for index,pname in ipairs(env.subscribers) do none=false minetest.chat_send_player(name, pname) end if none then - return false, "No subscribers!" + return false, S("No subscribers!") end return true end, @@ -115,7 +118,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local envname=string.match(formname, "^atlatc_delconfirm_(.+)$") if envname and fields.sure=="YES" then atlatc.envs[envname]=nil - minetest.chat_send_player(pname, "Environment deleted!") + minetest.chat_send_player(pname, S("Environment deleted!")) return end @@ -126,7 +129,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if not env then return end if fields.del then - minetest.show_formspec(pname, "atlatc_delconfirm_"..envname, "field[sure;"..minetest.formspec_escape("SURE TO DELETE ENVIRONMENT "..envname.."? Type YES (all uppercase) to continue or just quit form to cancel.")..";]") + minetest.show_formspec(pname, "atlatc_delconfirm_"..envname, "field[sure;" + ..minetest.formspec_escape(S("SURE TO DELETE ENVIRONMENT @1? Type YES (all uppercase) to continue or just quit form to cancel.", envname))..";]") return end |