From a7b952fc4ddec5a5ec23842010ca6ff1b92e4795 Mon Sep 17 00:00:00 2001 From: ZZZank <47418975+ZZZank@users.noreply.github.com> Date: Sun, 23 Nov 2025 20:32:32 +0800 Subject: [PATCH] add `@PropertyKey` to i18n methods for easier translation<->key navigation (#4831) --- HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java | 5 +++-- .../java/org/jackhuang/hmcl/util/i18n/SupportedLocale.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java index a3d4c32ab..e47ecd89c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java @@ -21,6 +21,7 @@ import org.jackhuang.hmcl.download.RemoteVersion; import org.jackhuang.hmcl.download.game.GameRemoteVersion; import org.jackhuang.hmcl.util.i18n.translator.Translator; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.PropertyKey; import java.io.IOException; import java.io.InputStream; @@ -59,11 +60,11 @@ public final class I18n { return locale.getTranslator(); } - public static String i18n(String key, Object... formatArgs) { + public static String i18n(@PropertyKey(resourceBundle = "assets.lang.I18N") String key, Object... formatArgs) { return locale.i18n(key, formatArgs); } - public static String i18n(String key) { + public static String i18n(@PropertyKey(resourceBundle = "assets.lang.I18N") String key) { return locale.i18n(key); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/SupportedLocale.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/SupportedLocale.java index 820b5c0c2..c8d55a1da 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/SupportedLocale.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/SupportedLocale.java @@ -24,6 +24,7 @@ import com.google.gson.stream.JsonWriter; import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.i18n.translator.Translator; +import org.jetbrains.annotations.PropertyKey; import java.io.IOException; import java.io.InputStream; @@ -187,7 +188,7 @@ public final class SupportedLocale { return candidateLocales; } - public String i18n(String key, Object... formatArgs) { + public String i18n(@PropertyKey(resourceBundle = "assets.lang.I18N") String key, Object... formatArgs) { try { return String.format(getResourceBundle().getString(key), formatArgs); } catch (MissingResourceException e) { @@ -199,7 +200,7 @@ public final class SupportedLocale { return key + Arrays.toString(formatArgs); } - public String i18n(String key) { + public String i18n(@PropertyKey(resourceBundle = "assets.lang.I18N") String key) { try { return getResourceBundle().getString(key); } catch (MissingResourceException e) {