diff --git a/lua/command/redirect.lua b/lua/command/redirect.lua index 428ad4d50..c6ac1f84e 100644 --- a/lua/command/redirect.lua +++ b/lua/command/redirect.lua @@ -22,7 +22,7 @@ function command_redirect(account, text) local dest = api.account_get_by_name(args[1]) if next(dest) == nil or dest.online == "false" then - api.message_send_text(account.name, message_type_error, account.name, "User '" ..args[1].. "' is offline") + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "User \"{}\" is offline", args[1])) return 1 end diff --git a/lua/extend/message.lua b/lua/extend/message.lua index 62767b3cd..2247e8d53 100644 --- a/lua/extend/message.lua +++ b/lua/extend/message.lua @@ -13,3 +13,6 @@ function message_send_all(text) end end +function localize(username, arg1, arg2, arg3, arg4, arg5) + return api.localize(username, arg1, arg2, arg3, arg4, arg5) +end \ No newline at end of file diff --git a/lua/handle_command.lua b/lua/handle_command.lua index 5012553cb..43aae10e5 100644 --- a/lua/handle_command.lua +++ b/lua/handle_command.lua @@ -31,7 +31,7 @@ function handle_command(account, text) -- check if command group is in account.commandgroups if math_and(account.commandgroups, cg) == 0 then - api.message_send_text(account.name, message_type_error, account.name, "This command is reserved for admins.") + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "This command is reserved for admins.")) return 1 end diff --git a/lua/quiz/command.lua b/lua/quiz/command.lua index d61b448ac..eacb8710a 100644 --- a/lua/quiz/command.lua +++ b/lua/quiz/command.lua @@ -37,24 +37,24 @@ end function q_command_start(account, filename) if not account_is_operator_or_admin(account.name) then - api.message_send_text(account.name, message_type_error, account.name, "You must be at least a Channel Operator to use this command.") + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "You must be at least a Channel Operator to use this command.")) return 1 end local channel = api.channel_get_by_id(account.channel_id) if not channel then - api.message_send_text(account.name, message_type_error, account.name, "This command can only be used inside a channel.") + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "This command can only be used inside a channel.")) return 1 end if config.quiz_channel then - api.message_send_text(account.name, message_type_error, account.name, 'Quiz has already ran in channel "'..config.quiz_channel..'". Use /qstop to force finish.') + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "Quiz has already ran in channel \"{}\". Use /quiz stop to force finish.", config.quiz_channel)) return 1 end -- check if file exists if not filename or not file_exists(q_directory() .. "/questions/" .. filename .. ".txt") then - api.message_send_text(account.name, message_type_error, account.name, "Available Quiz dictionaries: ") + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "Available Quiz dictionaries: ")) api.message_send_text(account.name, message_type_error, account.name, " " .. config.quiz_filelist) return 1 end @@ -67,12 +67,12 @@ end function q_command_stop(account) if not account_is_operator_or_admin(account.name) then - api.message_send_text(account.name, message_type_error, account.name, "You must be at least a Channel Operator to use this command.") + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "You must be at least a Channel Operator to use this command.")) return 1 end if not config.quiz_channel then - api.message_send_text(account.name, message_type_error, account.name, 'Quiz is not running.') + api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "Quiz is not running.")) return 1 end @@ -89,14 +89,14 @@ function q_command_toplist(account) return 0 end - local output = "Top " .. config.quiz_users_in_top .. " Quiz records:" + local output = localize(account.name, "Top {} Quiz records:", config.quiz_users_in_top) api.message_send_text(account.name, message_type_info, account.name, output) -- display TOP of total records for i,t in pairs(q_records_total) do if (i > config.quiz_users_in_top) then break end - local output = string.format(" %d. %s [%d points]", i, t.username, t.points) + local output = string.format(" %d. %s [%d %s]", i, t.username, t.points, localize(account.name, "points")) api.message_send_text(account.name, message_type_info, account.name, output) end @@ -116,9 +116,9 @@ function q_command_stats(account, username) -- find user in records for i,t in pairs(q_records_total) do if string.upper(t.username) == string.upper(username) then - api.message_send_text(account.name, message_type_info, account.name, t.username.. "'s Quiz record:") + api.message_send_text(account.name, message_type_info, account.name, localize(account.name, "{}'s Quiz record:", t.username)) - local output = string.format(" %d. %s [%d points]", i, t.username, t.points) + local output = string.format(" %d. %s [%d %s]", i, t.username, t.points, localize(account.name, "points")) api.message_send_text(account.name, message_type_info, account.name, output) found = true @@ -126,7 +126,7 @@ function q_command_stats(account, username) end if not found then - api.message_send_text(account.name, message_type_info, account.name, username .. " has never played Quiz.") + api.message_send_text(account.name, message_type_info, account.name, localize(account.name, "{} has never played Quiz.", username)) end return 1 diff --git a/src/bnetd/luafunctions.cpp b/src/bnetd/luafunctions.cpp index b2a4362d1..074b37848 100644 --- a/src/bnetd/luafunctions.cpp +++ b/src/bnetd/luafunctions.cpp @@ -48,6 +48,7 @@ #include "attrlayer.h" #include "icons.h" #include "helpfile.h" +#include "i18n.h" #include "luawrapper.h" #include "luaobjects.h" @@ -129,6 +130,7 @@ namespace pvpgn st.at(1, loglevel); st.at(2, function); st.at(3, text); + eventlog(t_eventlog_level(loglevel), function, text); } catch (const std::exception& e) { @@ -138,7 +140,6 @@ namespace pvpgn { eventlog(eventlog_level_error, __FUNCTION__, "lua exception\n"); } - eventlog(t_eventlog_level(loglevel), function, text); return 0; } @@ -766,7 +767,41 @@ namespace pvpgn return 0; } + /* Localize text */ + extern int __localize(lua_State* L) + { + const char *username, *text; + const char *arg1, *arg2, *arg3, *arg4, *arg5; + try + { + lua::stack st(L); + // get args + st.at(1, username); + st.at(2, text); + st.at(3, arg1); + st.at(4, arg2); + st.at(5, arg3); + st.at(6, arg4); + st.at(7, arg5); + if (t_account * account = accountlist_find_account(username)) + { + if (t_connection * c = account_get_conn(account)) + { + st.push(localize(c, text, arg1, arg2, arg3, arg4, arg5)); + } + } + } + catch (const std::exception& e) + { + eventlog(eventlog_level_error, __FUNCTION__, e.what()); + } + catch (...) + { + eventlog(eventlog_level_error, __FUNCTION__, "lua exception\n"); + } + return 1; + } } } #endif \ No newline at end of file diff --git a/src/bnetd/luafunctions.h b/src/bnetd/luafunctions.h index 0b81605cf..d99c2d181 100644 --- a/src/bnetd/luafunctions.h +++ b/src/bnetd/luafunctions.h @@ -58,6 +58,8 @@ namespace pvpgn extern int __icon_get_rank(lua_State* L); extern int __describe_command(lua_State* L); extern int __messagebox_show(lua_State* L); + + extern int __localize(lua_State* L); } } diff --git a/src/bnetd/luainterface.cpp b/src/bnetd/luainterface.cpp index ff30364cc..96e24a61f 100644 --- a/src/bnetd/luainterface.cpp +++ b/src/bnetd/luainterface.cpp @@ -147,6 +147,8 @@ namespace pvpgn { "describe_command", __describe_command }, { "messagebox_show", __messagebox_show }, + { "localize", __localize }, + { 0, 0 } }; vm.reg("api", api);