11-- Minetest: builtin/common/chatcommands.lua
22
3+ -- For server-side translations (if INIT == "game")
4+ -- Otherwise, use core.gettext
5+ local S = core .get_translator (" __builtin" )
6+
37core .registered_chatcommands = {}
48
59function core .register_chatcommand (cmd , def )
@@ -29,25 +33,12 @@ function core.override_chatcommand(name, redefinition)
2933 core .registered_chatcommands [name ] = chatcommand
3034end
3135
32- local cmd_marker = " /"
33-
34- local function gettext (...)
35- return ...
36- end
37-
38- local function gettext_replace (text , replace )
39- return text :gsub (" $1" , replace )
40- end
41-
42-
43- if INIT == " client" then
44- cmd_marker = " ."
45- gettext = core .gettext
46- gettext_replace = fgettext_ne
47- end
48-
4936local function do_help_cmd (name , param )
5037 local function format_help_line (cmd , def )
38+ local cmd_marker = " /"
39+ if INIT == " client" then
40+ cmd_marker = " ."
41+ end
5142 local msg = core .colorize (" #00ffff" , cmd_marker .. cmd )
5243 if def .params and def .params ~= " " then
5344 msg = msg .. " " .. def .params
@@ -65,9 +56,21 @@ local function do_help_cmd(name, param)
6556 end
6657 end
6758 table.sort (cmds )
68- return true , gettext (" Available commands: " ) .. table.concat (cmds , " " ) .. " \n "
69- .. gettext_replace (" Use '$1help <cmd>' to get more information,"
70- .. " or '$1help all' to list everything." , cmd_marker )
59+ local msg
60+ if INIT == " game" then
61+ msg = S (" Available commands: @1" ,
62+ table.concat (cmds , " " )) .. " \n "
63+ .. S (" Use '/help <cmd>' to get more "
64+ .. " information, or '/help all' to list "
65+ .. " everything." )
66+ else
67+ msg = core .gettext (" Available commands: " )
68+ .. table.concat (cmds , " " ) .. " \n "
69+ .. core .gettext (" Use '.help <cmd>' to get more "
70+ .. " information, or '.help all' to list "
71+ .. " everything." )
72+ end
73+ return true , msg
7174 elseif param == " all" then
7275 local cmds = {}
7376 for cmd , def in pairs (core .registered_chatcommands ) do
@@ -76,19 +79,31 @@ local function do_help_cmd(name, param)
7679 end
7780 end
7881 table.sort (cmds )
79- return true , gettext (" Available commands:" ).. " \n " .. table.concat (cmds , " \n " )
82+ local msg
83+ if INIT == " game" then
84+ msg = S (" Available commands:" )
85+ else
86+ msg = core .gettext (" Available commands:" )
87+ end
88+ return true , msg .. " \n " .. table.concat (cmds , " \n " )
8089 elseif INIT == " game" and param == " privs" then
8190 local privs = {}
8291 for priv , def in pairs (core .registered_privileges ) do
8392 privs [# privs + 1 ] = priv .. " : " .. def .description
8493 end
8594 table.sort (privs )
86- return true , " Available privileges:\n " .. table.concat (privs , " \n " )
95+ return true , S ( " Available privileges:" ) .. " \n " .. table.concat (privs , " \n " )
8796 else
8897 local cmd = param
8998 local def = core .registered_chatcommands [cmd ]
9099 if not def then
91- return false , gettext (" Command not available: " ).. cmd
100+ local msg
101+ if INIT == " game" then
102+ msg = S (" Command not available: @1" , cmd )
103+ else
104+ msg = core .gettext (" Command not available: " ) .. cmd
105+ end
106+ return false , msg
92107 else
93108 return true , format_help_line (cmd , def )
94109 end
97112
98113if INIT == " client" then
99114 core .register_chatcommand (" help" , {
100- params = gettext (" [all | <cmd>]" ),
101- description = gettext (" Get help for commands" ),
115+ params = core . gettext (" [all | <cmd>]" ),
116+ description = core . gettext (" Get help for commands" ),
102117 func = function (param )
103118 return do_help_cmd (nil , param )
104119 end ,
105120 })
106121else
107122 core .register_chatcommand (" help" , {
108- params = " [all | privs | <cmd>]" ,
109- description = " Get help for commands or list privileges" ,
123+ params = S ( " [all | privs | <cmd>]" ) ,
124+ description = S ( " Get help for commands or list privileges" ) ,
110125 func = do_help_cmd ,
111126 })
112127end
0 commit comments