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 e47ecd89c..15bff4be8 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 @@ -45,11 +45,11 @@ public final class I18n { } public static boolean isUpsideDown() { - return LocaleUtils.getScript(locale.getLocale()).equals("Qabs"); + return LocaleUtils.getScript(locale.getDisplayLocale()).equals("Qabs"); } public static boolean isUseChinese() { - return LocaleUtils.isChinese(locale.getLocale()); + return LocaleUtils.isChinese(locale.getDisplayLocale()); } public static ResourceBundle getResourceBundle() { 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 c8d55a1da..97d98b25f 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 @@ -42,6 +42,10 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG; public final class SupportedLocale { public static final SupportedLocale DEFAULT = new SupportedLocale(); + public static boolean isExperimentalSupported(Locale locale) { + return "ar".equals(locale.getLanguage()); + } + private static final ConcurrentMap LOCALES = new ConcurrentHashMap<>(); public static List getSupportedLocales() { @@ -51,7 +55,11 @@ public final class SupportedLocale { InputStream locales = SupportedLocale.class.getResourceAsStream("/assets/lang/languages.json"); if (locales != null) { try (locales) { - list.addAll(JsonUtils.fromNonNullJsonFully(locales, JsonUtils.listTypeOf(SupportedLocale.class))); + for (SupportedLocale locale : JsonUtils.fromNonNullJsonFully(locales, JsonUtils.listTypeOf(SupportedLocale.class))) { + if (!isExperimentalSupported(locale.getLocale())) { + list.add(locale); + } + } } catch (Throwable e) { LOG.warning("Failed to load languages.json", e); } @@ -73,6 +81,7 @@ public final class SupportedLocale { private final boolean isDefault; private final String name; private final Locale locale; + private final Locale displayLocale; private final TextDirection textDirection; private ResourceBundle resourceBundle; @@ -85,9 +94,15 @@ public final class SupportedLocale { this.name = "def"; // TODO: Change to "default" after updating the Config format String language = System.getenv("HMCL_LANGUAGE"); - this.locale = StringUtils.isBlank(language) - ? LocaleUtils.SYSTEM_DEFAULT - : Locale.forLanguageTag(language); + if (StringUtils.isBlank(language)) { + this.locale = LocaleUtils.SYSTEM_DEFAULT; + this.displayLocale = isExperimentalSupported(this.locale) + ? Locale.ENGLISH + : this.locale; + } else { + this.locale = Locale.forLanguageTag(language); + this.displayLocale = this.locale; + } this.textDirection = LocaleUtils.getTextDirection(locale); } @@ -95,6 +110,7 @@ public final class SupportedLocale { this.isDefault = false; this.name = locale.toLanguageTag(); this.locale = locale; + this.displayLocale = locale; this.textDirection = LocaleUtils.getTextDirection(locale); } @@ -110,6 +126,15 @@ public final class SupportedLocale { return locale; } + /// Used to represent the text display language of HMCL. + /// + /// Usually equivalent to [#getLocale()], + /// but for [experimentally supported languages][#isExperimentalSupported(Locale)], + /// it falls back to ENGLISH by default. + public Locale getDisplayLocale() { + return displayLocale; + } + public TextDirection getTextDirection() { return textDirection; } @@ -167,7 +192,7 @@ public final class SupportedLocale { public ResourceBundle getResourceBundle() { ResourceBundle bundle = resourceBundle; if (resourceBundle == null) - resourceBundle = bundle = ResourceBundle.getBundle("assets.lang.I18N", locale, + resourceBundle = bundle = ResourceBundle.getBundle("assets.lang.I18N", displayLocale, DefaultResourceBundleControl.INSTANCE); return bundle; @@ -176,7 +201,7 @@ public final class SupportedLocale { public ResourceBundle getLocaleNamesBundle() { ResourceBundle bundle = localeNamesBundle; if (localeNamesBundle == null) - localeNamesBundle = bundle = ResourceBundle.getBundle("assets.lang.LocaleNames", locale, + localeNamesBundle = bundle = ResourceBundle.getBundle("assets.lang.LocaleNames", displayLocale, DefaultResourceBundleControl.INSTANCE); return bundle; @@ -184,7 +209,7 @@ public final class SupportedLocale { public List getCandidateLocales() { if (candidateLocales == null) - candidateLocales = List.copyOf(LocaleUtils.getCandidateLocales(locale)); + candidateLocales = List.copyOf(LocaleUtils.getCandidateLocales(displayLocale)); return candidateLocales; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/translator/Translator.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/translator/Translator.java index 3441797cb..477871fc8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/translator/Translator.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/translator/Translator.java @@ -28,19 +28,19 @@ import java.util.Locale; /// @author Glavo public class Translator { protected final SupportedLocale supportedLocale; - protected final Locale locale; + protected final Locale displayLocale; public Translator(SupportedLocale supportedLocale) { this.supportedLocale = supportedLocale; - this.locale = supportedLocale.getLocale(); + this.displayLocale = supportedLocale.getDisplayLocale(); } public final SupportedLocale getSupportedLocale() { return supportedLocale; } - public final Locale getLocale() { - return locale; + public final Locale getDisplayLocale() { + return displayLocale; } public String getDisplayVersion(RemoteVersion remoteVersion) {