From 49aed23f3d7703ae274672f65d4f1d32067d9b48 Mon Sep 17 00:00:00 2001 From: TotalyNotOndre <40639199+TotalyNotOndre@users.noreply.github.com> Date: Sat, 3 Sep 2022 03:53:26 +0300 Subject: [PATCH] Plugin Manager localisation * Confugure Plugin Manager to use localised strings * Add localisation strings for plugin manager --- .../emu/grasscutter/plugin/PluginManager.java | 33 ++++++++++--------- src/main/resources/languages/en-US.json | 16 +++++++++ src/main/resources/languages/es-ES.json | 16 +++++++++ src/main/resources/languages/fr-FR.json | 16 +++++++++ src/main/resources/languages/ja-JP.json | 18 +++++++++- src/main/resources/languages/ko-KR.json | 16 +++++++++ src/main/resources/languages/pl-PL.json | 16 +++++++++ src/main/resources/languages/ro-RO.json | 16 +++++++++ src/main/resources/languages/ru-RU.json | 16 +++++++++ src/main/resources/languages/zh-CN.json | 16 +++++++++ src/main/resources/languages/zh-TW.json | 16 +++++++++ 11 files changed, 178 insertions(+), 17 deletions(-) diff --git a/src/main/java/emu/grasscutter/plugin/PluginManager.java b/src/main/java/emu/grasscutter/plugin/PluginManager.java index 31bbf501e..5d1b5f396 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginManager.java +++ b/src/main/java/emu/grasscutter/plugin/PluginManager.java @@ -9,6 +9,7 @@ import lombok.*; import javax.annotation.Nullable; import static emu.grasscutter.config.Configuration.PLUGIN; +import static emu.grasscutter.utils.Language.translate; import java.io.*; import java.lang.reflect.Method; @@ -44,7 +45,7 @@ public final class PluginManager { private void loadPlugins() { File pluginsDir = new File(Utils.toFilePath(PLUGIN())); if (!pluginsDir.exists() && !pluginsDir.mkdirs()) { - Grasscutter.getLogger().error("Failed to create plugins directory: " + pluginsDir.getAbsolutePath()); + Grasscutter.getLogger().error(translate("plugin.directory_failed", pluginsDir.getAbsolutePath())); return; } @@ -63,7 +64,7 @@ public final class PluginManager { try { pluginNames[plugins.indexOf(plugin)] = plugin.toURI().toURL(); } catch (MalformedURLException exception) { - Grasscutter.getLogger().warn("Unable to load plugin.", exception); + Grasscutter.getLogger().warn(translate("plugin.unable_to_load"), exception); } }); @@ -86,7 +87,7 @@ public final class PluginManager { PluginConfig pluginConfig = JsonUtils.loadToClass(fileReader, PluginConfig.class); // Check if the plugin config is valid. if (!pluginConfig.validate()) { - Grasscutter.getLogger().warn("Plugin " + plugin.getName() + " has an invalid config file."); + Grasscutter.getLogger().warn(translate("plugin.invalid_config", plugin.getName())); return; } @@ -120,12 +121,12 @@ public final class PluginManager { // Load the plugin. this.loadPlugin(pluginInstance, PluginIdentifier.fromPluginConfig(pluginConfig), loader); } catch (ClassNotFoundException ignored) { - Grasscutter.getLogger().warn("Plugin " + plugin.getName() + " has an invalid main class."); + Grasscutter.getLogger().warn(translate("plugin.invalid_main_class", plugin.getName())); } catch (FileNotFoundException ignored) { - Grasscutter.getLogger().warn("Plugin " + plugin.getName() + " lacks a valid config file."); + Grasscutter.getLogger().warn(translate("plugin.missing_config", plugin.getName())); } } catch (Exception exception) { - Grasscutter.getLogger().error("Failed to load plugin: " + plugin.getName(), exception); + Grasscutter.getLogger().error(translate("plugin.failed_to_load_plugin", plugin.getName()), exception); } } @@ -134,7 +135,7 @@ public final class PluginManager { while (!dependencies.isEmpty()) { // Check if the depth is too high. if (depth >= maxDepth) { - Grasscutter.getLogger().error("Failed to load plugins with dependencies."); + Grasscutter.getLogger().error(translate("plugin.failed_to_load_dependencies")); break; } @@ -154,7 +155,7 @@ public final class PluginManager { // Load the plugin. this.loadPlugin(pluginData.getPlugin(), pluginData.getIdentifier(), pluginData.getClassLoader()); } catch (Exception exception) { - Grasscutter.getLogger().error("Failed to load a plugin.", exception); depth++; + Grasscutter.getLogger().error(translate("plugin.failed_to_load"), exception); depth++; } } } @@ -165,7 +166,7 @@ public final class PluginManager { * @param plugin The plugin instance. */ private void loadPlugin(Plugin plugin, PluginIdentifier identifier, URLClassLoader classLoader) { - Grasscutter.getLogger().info("Loading plugin: " + identifier.name); + Grasscutter.getLogger().info(translate("plugin.loading_plugin", identifier.name)); // Add the plugin's identifier. try { @@ -175,7 +176,7 @@ public final class PluginManager { method.invoke(plugin, identifier, classLoader); method.setAccessible(false); } catch (Exception ignored) { - Grasscutter.getLogger().warn("Failed to add plugin identifier: " + identifier.name); + Grasscutter.getLogger().warn(translate("plugin.failed_add_id", identifier.name)); } // Add the plugin to the list of loaded plugins. @@ -187,7 +188,7 @@ public final class PluginManager { try { plugin.onLoad(); } catch (Throwable exception) { - Grasscutter.getLogger().error("Failed to load plugin: " + identifier.name, exception); + Grasscutter.getLogger().error(translate("plugin.failed_to_load_plugin", identifier.name), exception); } } @@ -196,11 +197,11 @@ public final class PluginManager { */ public void enablePlugins() { this.plugins.forEach((name, plugin) -> { - Grasscutter.getLogger().info("Enabling plugin: " + name); + Grasscutter.getLogger().info(translate("plugin.enabling_plugin", name)); try { plugin.onEnable(); } catch (Throwable exception) { - Grasscutter.getLogger().error("Failed to enable plugin: " + name, exception); + Grasscutter.getLogger().error(translate("plugin.enabling_failed", name), exception); } }); } @@ -210,7 +211,7 @@ public final class PluginManager { */ public void disablePlugins() { this.plugins.forEach((name, plugin) -> { - Grasscutter.getLogger().info("Disabling plugin: " + name); + Grasscutter.getLogger().info(translate("plugin.disabling_plugin", name)); this.disablePlugin(plugin); }); } @@ -277,7 +278,7 @@ public final class PluginManager { // Call the plugin's onEnable method. plugin.onEnable(); } catch (Exception exception) { - Grasscutter.getLogger().error("Failed to enable plugin: " + plugin.getName(), exception); + Grasscutter.getLogger().error(translate("plugin.enabling_failed", plugin.getName()), exception); } } @@ -291,7 +292,7 @@ public final class PluginManager { // Call the plugin's onDisable method. plugin.onDisable(); } catch (Exception exception) { - Grasscutter.getLogger().error("Failed to disable plugin: " + plugin.getName(), exception); + Grasscutter.getLogger().error(translate("plugin.disabling_failed", plugin.getName()), exception); } // Un-register all listeners. diff --git a/src/main/resources/languages/en-US.json b/src/main/resources/languages/en-US.json index 2d9671626..a77afd3c9 100644 --- a/src/main/resources/languages/en-US.json +++ b/src/main/resources/languages/en-US.json @@ -382,5 +382,21 @@ "handbook": "GM Handbook", "gacha_mapping": "Gacha mapping JSON" } + }, + "plugin": { + "directory_failed": "Failed to create plugins directory: ", + "unable_to_load": "Unable to load plugin.", + "invalid_config": "Plugin %s has an invalid config file.", + "invalid_main_class": "Plugin %s has an invalid main class.", + "missing_config": "Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "Failed to load plugin: %s", + "failed_to_load": "Failed to load a plugin.", + "failed_to_load_dependencies": "Failed to load plugins with dependencies.", + "loading_plugin": "Loading plugin: %s", + "failed_add_id": "Failed to add plugin identifier: %s", + "enabling_plugin": "Enabling plugin: %s", + "enabling_failed": "Failed to enable plugin: %s", + "disabling_plugin": "Disabling plugin: %s", + "disabling_failed": "Failed to disable plugin: %s" } } diff --git a/src/main/resources/languages/es-ES.json b/src/main/resources/languages/es-ES.json index 4be287adc..31a85fac7 100644 --- a/src/main/resources/languages/es-ES.json +++ b/src/main/resources/languages/es-ES.json @@ -382,5 +382,21 @@ "handbook": "🇺🇸GM Handbook", "gacha_mapping": "JSON de mapeo del Gacha" } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" } } diff --git a/src/main/resources/languages/fr-FR.json b/src/main/resources/languages/fr-FR.json index 4b78ef542..4a7261709 100644 --- a/src/main/resources/languages/fr-FR.json +++ b/src/main/resources/languages/fr-FR.json @@ -382,5 +382,21 @@ "handbook": "Manuel GM", "gacha_mapping": "🇺🇸Gacha mapping JSON" } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" } } diff --git a/src/main/resources/languages/ja-JP.json b/src/main/resources/languages/ja-JP.json index 5079632b5..fbeea3b94 100644 --- a/src/main/resources/languages/ja-JP.json +++ b/src/main/resources/languages/ja-JP.json @@ -382,6 +382,22 @@ "handbook": "GM Handbook", "gacha_mapping": "ガチャマップ JSON" } - } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" + } } \ No newline at end of file diff --git a/src/main/resources/languages/ko-KR.json b/src/main/resources/languages/ko-KR.json index 5e5d74b1c..144b96116 100644 --- a/src/main/resources/languages/ko-KR.json +++ b/src/main/resources/languages/ko-KR.json @@ -382,5 +382,21 @@ "handbook": "🇺🇸GM Handbook", "gacha_mapping": "🇺🇸Gacha mapping JSON" } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" } } diff --git a/src/main/resources/languages/pl-PL.json b/src/main/resources/languages/pl-PL.json index 88b045ab9..c069a6377 100644 --- a/src/main/resources/languages/pl-PL.json +++ b/src/main/resources/languages/pl-PL.json @@ -382,5 +382,21 @@ "handbook": "🇺🇸GM Handbook", "gacha_mapping": "Losowanie w formacie JSON" } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" } } diff --git a/src/main/resources/languages/ro-RO.json b/src/main/resources/languages/ro-RO.json index b231be8fd..b982e004d 100644 --- a/src/main/resources/languages/ro-RO.json +++ b/src/main/resources/languages/ro-RO.json @@ -382,5 +382,21 @@ "handbook": "Manual GM", "gacha_mapping": "🇺🇸Gacha mapping JSON" } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" } } diff --git a/src/main/resources/languages/ru-RU.json b/src/main/resources/languages/ru-RU.json index 7e2886f9e..35b3caa60 100644 --- a/src/main/resources/languages/ru-RU.json +++ b/src/main/resources/languages/ru-RU.json @@ -382,5 +382,21 @@ "handbook": "Справочник гейм-мастера", "gacha_mapping": "Мапирование системы гача в JSON" } + }, + "plugin": { + "directory_failed": "Ошибка создания директории плагинов: ", + "unable_to_load": "Невозможно загрудить плагин.", + "invalid_config": "Плагин %s имеет недопустимый файл конфигурации.", + "invalid_main_class": "Плагин %s имеет неверный главный класс.", + "missing_config": "Плагин %s не имеет корректного файла конфигурации.", + "failed_to_load_plugin": "Ошибка загрузки плагина: %s", + "failed_to_load": "Не удалось загрузить Плагин.", + "failed_to_load_dependencies": "Не удалось загрузитьзависимости Плагина.", + "loading_plugin": "Загрузка Плагина: %s", + "failed_add_id": "Ошибка присвоения идентификатора Плагину: %s", + "enabling_plugin": "Включаем Плагин: %s", + "enabling_failed": "Ошибка включения Плагина: %s", + "disabling_plugin": "Отключаем Плагин: %s", + "disabling_failed": "Ошибка отключения Плагина: %s" } } diff --git a/src/main/resources/languages/zh-CN.json b/src/main/resources/languages/zh-CN.json index db98c3903..d53acba68 100644 --- a/src/main/resources/languages/zh-CN.json +++ b/src/main/resources/languages/zh-CN.json @@ -382,5 +382,21 @@ "handbook": "GM手册", "gacha_mapping": "祈愿物品映射JSON" } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" } } diff --git a/src/main/resources/languages/zh-TW.json b/src/main/resources/languages/zh-TW.json index 955c2fad3..88ba532b3 100644 --- a/src/main/resources/languages/zh-TW.json +++ b/src/main/resources/languages/zh-TW.json @@ -382,5 +382,21 @@ "handbook": "🇺🇸GM Handbook", "gacha_mapping": "祈願物品映射到JSON上" } + }, + "plugin": { + "directory_failed": "🇺🇸Failed to create plugins directory: ", + "unable_to_load": "🇺🇸Unable to load plugin.", + "invalid_config": "🇺🇸Plugin %s has an invalid config file.", + "invalid_main_class": "🇺🇸Plugin %s has an invalid main class.", + "missing_config": "🇺🇸Plugin %s lacks a valid config file.", + "failed_to_load_plugin": "🇺🇸Failed to load plugin: %s", + "failed_to_load": "🇺🇸Failed to load a plugin.", + "failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.", + "loading_plugin": "🇺🇸Loading plugin: %s", + "failed_add_id": "🇺🇸Failed to add plugin identifier: %s", + "enabling_plugin": "🇺🇸Enabling plugin: %s", + "enabling_failed": "🇺🇸Failed to enable plugin: %s", + "disabling_plugin": "🇺🇸Disabling plugin: %s", + "disabling_failed": "🇺🇸Failed to disable plugin: %s" } }