add @PropertyKey to i18n methods for easier translation<->key navigation (#4831)

This commit is contained in:
ZZZank
2025-11-23 20:32:32 +08:00
committed by GitHub
parent 63ceb3c6c8
commit a7b952fc4d
2 changed files with 6 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.download.game.GameRemoteVersion; import org.jackhuang.hmcl.download.game.GameRemoteVersion;
import org.jackhuang.hmcl.util.i18n.translator.Translator; import org.jackhuang.hmcl.util.i18n.translator.Translator;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.PropertyKey;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -59,11 +60,11 @@ public final class I18n {
return locale.getTranslator(); 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); 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); return locale.i18n(key);
} }

View File

@@ -24,6 +24,7 @@ import com.google.gson.stream.JsonWriter;
import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.i18n.translator.Translator; import org.jackhuang.hmcl.util.i18n.translator.Translator;
import org.jetbrains.annotations.PropertyKey;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -187,7 +188,7 @@ public final class SupportedLocale {
return candidateLocales; return candidateLocales;
} }
public String i18n(String key, Object... formatArgs) { public String i18n(@PropertyKey(resourceBundle = "assets.lang.I18N") String key, Object... formatArgs) {
try { try {
return String.format(getResourceBundle().getString(key), formatArgs); return String.format(getResourceBundle().getString(key), formatArgs);
} catch (MissingResourceException e) { } catch (MissingResourceException e) {
@@ -199,7 +200,7 @@ public final class SupportedLocale {
return key + Arrays.toString(formatArgs); return key + Arrays.toString(formatArgs);
} }
public String i18n(String key) { public String i18n(@PropertyKey(resourceBundle = "assets.lang.I18N") String key) {
try { try {
return getResourceBundle().getString(key); return getResourceBundle().getString(key);
} catch (MissingResourceException e) { } catch (MissingResourceException e) {