From 8521eb4278baee724dc70e8dd58e4af2d8e9a0d8 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sun, 29 Nov 2020 21:26:49 +0100 Subject: [PATCH] locale fixes --- utils/print_override.lua | 1 + utils/server.lua | 97 ++++++++++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 23 deletions(-) diff --git a/utils/print_override.lua b/utils/print_override.lua index f0ce493b..671a7e66 100644 --- a/utils/print_override.lua +++ b/utils/print_override.lua @@ -9,6 +9,7 @@ function print(str, tag) else locale_string[2] = '[PRINT]' end + locale_string[3] = str log(locale_string) end diff --git a/utils/server.lua b/utils/server.lua index 5e1fb5c3..06a79a65 100644 --- a/utils/server.lua +++ b/utils/server.lua @@ -79,45 +79,76 @@ Public.events = {on_server_started = Event.generate_event_name('on_server_starte -- @usage -- local Server = require 'utils.server' -- Server.to_discord('Hello from scenario script!') -function Public.to_discord(message) - raw_print(discord_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_discord(message, locale) + if locale then + print(message, discord_tag) + else + raw_print(discord_tag .. message) + end end --- Sends a message to the linked discord channel. The message is not sanitized of markdown. -- @param message message to send. -function Public.to_discord_raw(message) - raw_print(discord_raw_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_discord_raw(message, locale) + if locale then + print(message, discord_raw_tag) + else + raw_print(discord_raw_tag .. message) + end end --- Sends a message to the linked discord channel. The message is sanitized of markdown server side, then made bold. -- @param message message to send. -function Public.to_discord_bold(message) - raw_print(discord_bold_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_discord_bold(message, locale) + if locale then + print(message, discord_bold_tag) + else + raw_print(discord_bold_tag .. message) + end end --- Sends a message to the linked admin discord channel. The message is sanitized of markdown server side. -- @param message message to send. -function Public.to_admin(message) - raw_print(discord_admin_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_admin(message, locale) + if locale then + print(message, discord_admin_tag) + else + raw_print(discord_admin_tag .. message) + end end --- Sends a message to the linked banend discord channel. The message is sanitized of markdown server side. -- @param message message to send. -function Public.to_banned(message) - raw_print(discord_banned_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_banned(message, locale) + if locale then + print(message, discord_banned_tag) + else + raw_print(discord_banned_tag .. message) + end end --- Sends a message to the linked admin discord channel. The message is not sanitized of markdown. -- @param message message to send. -function Public.to_admin_raw(message) - raw_print(discord_admin_raw_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_admin_raw(message, locale) + if locale then + print(message, discord_admin_raw_tag) + else + raw_print(discord_admin_raw_tag .. message) + end end --- Sends a embed message to the linked discord channel. The message is sanitized of markdown server side. -- @param message the content of the embed. -function Public.to_discord_embed(message, loc) - if loc then - somefunc that includes loc +-- @param locale if the message should be handled as localized. +function Public.to_discord_embed(message, locale) + if locale then + print(message, discord_embed_tag) else raw_print(discord_embed_tag .. message) end @@ -125,26 +156,46 @@ end --- Sends a embed message to the linked discord channel. The message is not sanitized of markdown. -- @param message the content of the embed. -function Public.to_discord_embed_raw(message) - raw_print(discord_embed_raw_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_discord_embed_raw(message, locale) + if locale then + print(message, discord_embed_raw_tag) + else + raw_print(discord_embed_raw_tag .. message) + end end --- Sends a embed message to the linked admin discord channel. The message is sanitized of markdown server side. -- @param message the content of the embed. -function Public.to_admin_embed(message) - raw_print(discord_admin_embed_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_admin_embed(message, locale) + if locale then + print(message, discord_admin_embed_tag) + else + raw_print(discord_admin_embed_tag .. message) + end end --- Sends a embed message to the linked banned discord channel. The message is sanitized of markdown server side. -- @param message the content of the embed. -function Public.to_banned_embed(message) - raw_print(discord_banned_embed_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_banned_embed(message, locale) + if locale then + print(message, discord_banned_embed_tag) + else + raw_print(discord_banned_embed_tag .. message) + end end --- Sends a embed message to the linked admin discord channel. The message is not sanitized of markdown. -- @param message the content of the embed. -function Public.to_admin_embed_raw(message) - raw_print(discord_admin_embed_raw_tag .. message) +-- @param locale if the message should be handled as localized. +function Public.to_admin_embed_raw(message, locale) + if locale then + print(message, discord_admin_embed_raw_tag) + else + raw_print(discord_admin_embed_raw_tag .. message) + end end --- Stops and saves the factorio server and starts the named scenario.