Fix translation errors in 5.5.0-dev server messages

master
SmallJoker 2021-04-04 18:43:27 +02:00
parent c6eefaea1c
commit 648d45e70f
2 changed files with 15 additions and 3 deletions

View File

@ -4,7 +4,7 @@ if not core.register_on_receiving_chat_message then
end
local color_reset = "\x1b(c@#FFF)"
local c_pattern = "\x1b%(c@#[0-9a-fA-F]+%)"
local c_pattern = "\x1b%(c@#?[0-9a-fA-F]+%)"
core.register_on_receiving_chat_message(function(line)
local myname_l = "~[CAPS£"
@ -31,6 +31,10 @@ core.register_on_receiving_chat_message(function(line)
-- To keep the <Name> notation
chat_line = true
else
-- Translated server messages, actions
prefix, name, message = line:match("^(.*\x1bF)([^\x1b]+)(.*)")
end
if not message then
-- Server messages, actions
prefix, name, message = line:match("^(%*+ )(%S+) (.*)")
end

View File

@ -3,6 +3,10 @@ minetest = core
local callback
function esc(msg)
return msg:gsub("\x1b", "\\")
end
function core.colorize(x, text)
return "\x1b(c@" .. x .. ")" .. text .. "\x1b(c@#ffffff)"
end
@ -10,7 +14,7 @@ function core.get_color_escape_sequence(x)
return "\x1b(c@" .. x .. ")"
end
function core.display_chat_message(msg)
print("Out: " .. msg)
print("Out: " .. esc(msg))
end
function core.register_on_receiving_chat_message(func)
callback = func
@ -18,11 +22,15 @@ end
function core.strip_colors(msg)
return (msg:gsub("\x1b%([bc]@[^)]+%)", ""))
end
function core.sha1()
return ("FOOBARZ"):rep(5)
end
dofile("init.lua")
local test_table = {
"*** singleplayer joined the game",
"*** \x1b(T@__builtin)\x1bFsingleplayer\x1bE joined the game.\x1bE",
"* singleplayer needs action like a true survivor",
"<singleplayer> buzz baz",
"\x1b(c@#abcdef)[Admin] <singleplayer> foo bar\x1b(c@#ffffff)",
@ -32,7 +40,7 @@ local test_table = {
}
local time = os.clock()
for i, v in pairs(test_table) do
print("In: " .. v)
print("\nIn: " .. esc(v))
callback(v)
end
local end_time = (os.clock() - time) * 1000^2 / #test_table