From cdeacc16bff11a4ec25a208299cc6c79ee08fa6b Mon Sep 17 00:00:00 2001 From: SantaSpeen Date: Wed, 26 Jul 2023 18:40:44 +0300 Subject: [PATCH] Final of i18n --- src/modules/EventsSystem/events_system.py | 38 ++++++------------- .../PluginsLoader/lua_plugins_loader.py | 15 +++----- src/modules/i18n/files/cn.json | 9 ++++- src/modules/i18n/files/en.json | 7 ++++ src/modules/i18n/files/ru.json | 7 ++++ src/modules/i18n/i18n-builtins.pyi | 7 +++- src/modules/i18n/i18n.py | 26 +++++++++++++ 7 files changed, 72 insertions(+), 37 deletions(-) diff --git a/src/modules/EventsSystem/events_system.py b/src/modules/EventsSystem/events_system.py index 94fbb1b..23ef1b5 100644 --- a/src/modules/EventsSystem/events_system.py +++ b/src/modules/EventsSystem/events_system.py @@ -56,12 +56,12 @@ class EventsSystem: "onInit": [], # onServerStarted "onShutdown": [], # onServerStopped "onPlayerAuth": [], # onPlayerAuthenticated - "onPlayerConnecting": [], # TODO lua onPlayerConnecting - "onPlayerJoining": [], # TODO lua onPlayerJoining + "onPlayerConnecting": [], # No + "onPlayerJoining": [], # No "onPlayerJoin": [], # onPlayerJoin - "onPlayerDisconnect": [], # TODO lua onPlayerDisconnect + "onPlayerDisconnect": [], # onPlayerDisconnect "onChatMessage": [], # onChatReceive - "onVehicleSpawn": [], # "onCarSpawn + "onVehicleSpawn": [], # onCarSpawn "onVehicleEdited": [], # onCarEdited "onVehicleDeleted": [], # onCarDelete "onVehicleReset": [], # onCarReset @@ -85,9 +85,7 @@ class EventsSystem: return if not callable(event_func): - # TODO: i18n - self.log.error(f"Cannot add event '{event_name}'. " - f"Use `KuiToi.add_event({event_name}', function)` instead. Skipping it...") + self.log.error(i18n.events_not_callable.format(event_name, f"kt.add_event(\"{event_name}\", function)")) return if async_event or inspect.iscoroutinefunction(event_func): if event_name not in self.__async_events: @@ -112,12 +110,10 @@ class EventsSystem: data = await func(event_data) funcs_data.append(data) except Exception as e: - # TODO: i18n - self.log.error(f'Error while calling "{event_name}"; In function: "{func.__name__}"') + self.log.error(i18n.events_calling_error.format(event_name, func.__name__)) self.log.exception(e) else: - # TODO: i18n - self.log.warning(f"Event {event_name} does not exist, maybe ev.call_event()?. Just skipping it...") + self.log.warning(i18n.events_not_found.format(event_name, "kt.call_event()")) return funcs_data @@ -132,12 +128,10 @@ class EventsSystem: event_data = {"event_name": event_name, "args": args, "kwargs": kwargs} funcs_data.append(func(event_data)) except Exception as e: - # TODO: i18n - self.log.error(f'Error while calling "{event_name}"; In function: "{func.__name__}"') + self.log.error(i18n.events_calling_error.format(event_name, func.__name__)) self.log.exception(e) else: - # TODO: i18n - self.log.warning(f"Event {event_name} does not exist, maybe ev.call_async_event()?. Just skipping it...") + self.log.warning(i18n.events_not_found.format(event_name, "kt.call_async_event()")) return funcs_data @@ -151,21 +145,13 @@ class EventsSystem: try: func = lua.globals()[func_name] if not func: - self.log.warning(f"Cannot trigger local event: '{func_name}' not found!") + self.log.warning(i18n.events_lua_function_not_found.format("", func_name)) continue fd = func(*args) funcs_data.append(fd) except Exception as e: - # TODO: i18n - self.log.error(f'Error: "{e}" - while calling lua event "{event_name}" with arguments: {args} - ' - f'in function: "{func_name}"') - # self.log.exception(e) + self.log.error(i18n.events_lua_calling_error.format(f"{e}", event_name, func_name, f"{args}")) else: - # TODO: i18n - self.log.warning(f"Event {event_name} does not exist, maybe ev.call_lua_event() or MP.Trigger<>Event()?. " - f"Just skipping it...") + self.log.warning(i18n.events_not_found.format(event_name, "ev.call_lua_event(), MP.Trigger<>Event()")) return funcs_data - - - diff --git a/src/modules/PluginsLoader/lua_plugins_loader.py b/src/modules/PluginsLoader/lua_plugins_loader.py index dd0d910..6136656 100644 --- a/src/modules/PluginsLoader/lua_plugins_loader.py +++ b/src/modules/PluginsLoader/lua_plugins_loader.py @@ -43,7 +43,7 @@ class EventTimer: self.mp.TriggerLocalEvent(self.event_name) -# noinspection PyPep8Naming +# noinspection PyPep8Naming,PyProtectedMember class MP: def __init__(self, name: str, lua: LuaRuntime): @@ -117,19 +117,15 @@ class MP: try: func = self._lua.globals()[func_name] if not func: - self.log.warning(f"Cannot trigger local event: '{func_name}' not found!") + self.log.warning(i18n.events_lua_function_not_found.format(i18n.events_lua_local, func_name)) continue fd = func(*args) funcs_data.append(fd) except Exception as e: - # TODO: i18n - self.log.error(f'Error: "{e}" - while calling lua event "{event_name}" with arguments: {args} - ' - f'in function: "{func_name}"') - # self.log.exception(e) + self.log.error(i18n.events_lua_calling_error.format(f"{e}", event_name, func_name, f"{args}")) + else: - # TODO: i18n - self.log.warning(f"Event {event_name} does not exist, maybe ev.call_lua_event() or MP.Trigger<>Event()?. " - f"Just skipping it...") + self.log.warning(i18n.events_not_found.format(event_name, "ev.call_lua_event(), MP.Trigger<>Event()")) return self._lua.table_from(funcs_data) @@ -563,6 +559,7 @@ class FS: return os.path.join(*args) +# noinspection PyProtectedMember class LuaPluginsLoader: def __init__(self, plugins_dir): diff --git a/src/modules/i18n/files/cn.json b/src/modules/i18n/files/cn.json index ee3128f..5b232a0 100644 --- a/src/modules/i18n/files/cn.json +++ b/src/modules/i18n/files/cn.json @@ -57,7 +57,14 @@ "client_event_invalid_data": "从事件返回的数据无效:{}", "client_player_disconnected": "离开服务器。游戏时间:{}分钟。", - "": "Events system", + "": "事件系统", + + "events_not_callable": "无法添加事件\"{}\"。请改用\"{}\"。跳过...", + "events_not_found": "事件\"{}\"未注册。也许{}?跳过...", + "events_calling_error": "调用函数\"{}\"时出错。", + "events_lua_function_not_found": "无法调用{}lua事件 - 未找到\"{}\"。", + "events_lua_local": "本地 ", + "events_lua_calling_error": "错误:\"{}\" - 调用lua事件\"{}\"时出错,函数:\"{}\",参数:{}", "": "插件加载器", diff --git a/src/modules/i18n/files/en.json b/src/modules/i18n/files/en.json index 1b6d8e7..a6f64da 100644 --- a/src/modules/i18n/files/en.json +++ b/src/modules/i18n/files/en.json @@ -59,6 +59,13 @@ "": "Events system", + "events_not_callable": "Unable to add event \"{}\". Use \"{}\" instead. Skipping...", + "events_not_found": "Event \"{}\" is not registered. Maybe {}? Skipping...", + "events_calling_error": "Error calling \"{}\" in function \"{}\".", + "events_lua_function_not_found": "Unable to call {}lua event - \"{}\" not found.", + "events_lua_local": "local ", + "events_lua_calling_error": "Error: \"{}\" - calling lua event \"{}\", function: \"{}\", arguments: {}", + "": "Plugins loader", "plugins_not_found_load": "Function \"def load():\" not found.", diff --git a/src/modules/i18n/files/ru.json b/src/modules/i18n/files/ru.json index 782a5f2..7ea766c 100644 --- a/src/modules/i18n/files/ru.json +++ b/src/modules/i18n/files/ru.json @@ -59,6 +59,13 @@ "": "Events system", + "events_not_callable": "Невозможно добавить ивент \"{}\". Использую лучше \"{}\". Скип...", + "events_not_found": "Ивент \"{}\" не зарегистрирован. Может {}? Скип...", + "events_calling_error": "Ошибка во время вызова \"{}\" в функции \"{}\".", + "events_lua_function_not_found": "Невозможно вызвать {}lua ивент - \"{}\" не найдена.", + "events_lua_local": "локальный ", + "events_lua_calling_error": "Ошибка: \"{}\" - во время вызова lua ивента \"{}\", функция: \"{}\" , аргументы: {}", + "": "Plugins loader", "plugins_not_found_load": "Функция \"def load():\" не найдена.", diff --git a/src/modules/i18n/i18n-builtins.pyi b/src/modules/i18n/i18n-builtins.pyi index 26a8a71..d406264 100644 --- a/src/modules/i18n/i18n-builtins.pyi +++ b/src/modules/i18n/i18n-builtins.pyi @@ -62,7 +62,12 @@ class i18n: # Events system - + events_not_callable: str + events_not_found: str + events_calling_error: str + events_lua_function_not_found: str + events_lua_local: str + events_lua_calling_error: str # Plugins loader diff --git a/src/modules/i18n/i18n.py b/src/modules/i18n/i18n.py index 9377993..eaa44e7 100644 --- a/src/modules/i18n/i18n.py +++ b/src/modules/i18n/i18n.py @@ -106,6 +106,32 @@ class MultiLanguage: "client_event_invalid_data": "Invalid data returned from event: {}", "client_player_disconnected": "Left the server. Playtime: {} min", + "": "Events system", + + "events_not_callable": "Unable to add event \"{}\". Use \"{}\" instead. Skipping...", + "events_not_found": "Event \"{}\" is not registered. Maybe {}? Skipping...", + "events_calling_error": "Error calling \"{}\" in function \"{}\".", + "events_lua_function_not_found": "Unable to call {}lua event - \"{}\" not found.", + "events_lua_local": "local ", + "events_lua_calling_error": "Error: \"{}\" - calling lua event \"{}\", function: \"{}\", arguments: {}", + + "": "Plugins loader", + + "plugins_not_found_load": "Function \"def load():\" not found.", + "plugins_not_found_start": "Function \"def start():\" not found.", + "plugins_not_found_unload": "Function \"def unload():\" not found.", + "plugins_kt_invalid": "\"kt\" variable does not belong to the KuiToi class.", + "plugins_invalid": "Plugin \"{}\" cannot be run in KuiToi.", + "plugins_error_loading": "An error occurred while loading the plugin {}: {}", + + "": "Lua plugins loader", + + "plugins_lua_enabled": "You have enabled Lua plugin support.", + "plugins_lua_nuances_warning": "There are some nuances when working with Kuiti. If you have a suggestion for their solution, and it is related to KuiToi, please contact the developer.", + "plugins_lua_legacy_config_create_warning": "Some BeamMP plugins require a properly configured ServerConfig.toml file to function.", + "plugins_lua_legacy_config_create": "Creating it.", + "plugins_lua_unload": "Stopping Lua plugin: {}", + "": "Command: man", "man_message_man": "man - Shows the help page for COMMAND.\nUsage: man COMMAND", "help_message_man": "Shows the help page for COMMAND.",