From 68dbe6945bade011bb39b8b8cc2b9c4d02d239ec Mon Sep 17 00:00:00 2001 From: Glavo Date: Sun, 7 Sep 2025 21:06:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=AD=E8=A8=80=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E7=AE=80=E4=BD=93/=E7=B9=81=E4=BD=93?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E9=80=89=E9=A1=B9=E7=9A=84=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=20(#4410)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jackhuang/hmcl/ui/main/SettingsView.java | 5 +- .../org/jackhuang/hmcl/util/i18n/Locales.java | 47 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java index 2ed61a480..66c4960a2 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java @@ -39,7 +39,6 @@ import org.jackhuang.hmcl.ui.construct.ComponentSublist; import org.jackhuang.hmcl.ui.construct.MultiFileItem; import org.jackhuang.hmcl.ui.construct.OptionToggleButton; import org.jackhuang.hmcl.util.i18n.I18n; -import org.jackhuang.hmcl.util.i18n.Locales; import org.jackhuang.hmcl.util.i18n.Locales.SupportedLocale; import java.util.Arrays; @@ -183,8 +182,10 @@ public abstract class SettingsView extends StackPane { SupportedLocale currentLocale = I18n.getLocale(); cboLanguage = new JFXComboBox<>(); cboLanguage.setConverter(stringConverter(locale -> { - if (locale.isSameLanguage(currentLocale) || locale == Locales.DEFAULT) + if (locale.isDefault()) return locale.getDisplayName(currentLocale); + else if (locale.isSameLanguage(currentLocale)) + return locale.getDisplayName(locale); else return locale.getDisplayName(currentLocale) + " - " + locale.getDisplayName(locale); })); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java index dc7c7283d..995b5b8f6 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java @@ -44,13 +44,8 @@ public final class Locales { public static final SupportedLocale DEFAULT = new SupportedLocale("def", getDefaultLocale()) { @Override - public String getDisplayName(SupportedLocale inLocale) { - try { - return inLocale.getResourceBundle().getString("lang.default"); - } catch (Throwable e) { - LOG.warning("Failed to get localized name for default locale", e); - return "Default"; - } + public boolean isDefault() { + return true; } }; @@ -92,19 +87,7 @@ public final class Locales { /** * Wenyan (Classical Chinese) */ - public static final SupportedLocale WENYAN = new SupportedLocale("lzh", Locale.forLanguageTag("lzh")) { - - @Override - public String getDisplayName(SupportedLocale inLocale) { - if (LocaleUtils.isChinese(inLocale.locale)) - return "文言"; - - String name = super.getDisplayName(inLocale); - return name.equals("lzh") || name.equals("Literary Chinese") - ? "Chinese (Classical)" - : name; - } - }; + public static final SupportedLocale WENYAN = new SupportedLocale("lzh", Locale.forLanguageTag("lzh")); public static final List LOCALES = List.of(DEFAULT, EN, ES, JA, RU, UK, ZH_HANS, ZH_HANT, WENYAN); @@ -132,6 +115,10 @@ public final class Locales { this.locale = locale; } + public boolean isDefault() { + return false; + } + public String getName() { return name; } @@ -143,6 +130,26 @@ public final class Locales { public String getDisplayName(SupportedLocale inLocale) { if (inLocale.locale.getLanguage().equals("lzh")) inLocale = ZH_HANT; + + if (isDefault()) { + try { + return inLocale.getResourceBundle().getString("lang.default"); + } catch (Throwable e) { + LOG.warning("Failed to get localized name for default locale", e); + return "Default"; + } + } + + if (this.locale.getLanguage().equals("lzh")) { + if (LocaleUtils.isChinese(inLocale.locale)) + return "文言"; + + String name = locale.getDisplayName(inLocale.getLocale()); + return name.equals("lzh") || name.equals("Literary Chinese") + ? "Chinese (Classical)" + : name; + } + return locale.getDisplayName(inLocale.getLocale()); }