优化语言设置中简体/繁体中文选项的显示方式 (#4410)
This commit is contained in:
@@ -39,7 +39,6 @@ import org.jackhuang.hmcl.ui.construct.ComponentSublist;
|
|||||||
import org.jackhuang.hmcl.ui.construct.MultiFileItem;
|
import org.jackhuang.hmcl.ui.construct.MultiFileItem;
|
||||||
import org.jackhuang.hmcl.ui.construct.OptionToggleButton;
|
import org.jackhuang.hmcl.ui.construct.OptionToggleButton;
|
||||||
import org.jackhuang.hmcl.util.i18n.I18n;
|
import org.jackhuang.hmcl.util.i18n.I18n;
|
||||||
import org.jackhuang.hmcl.util.i18n.Locales;
|
|
||||||
import org.jackhuang.hmcl.util.i18n.Locales.SupportedLocale;
|
import org.jackhuang.hmcl.util.i18n.Locales.SupportedLocale;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -183,8 +182,10 @@ public abstract class SettingsView extends StackPane {
|
|||||||
SupportedLocale currentLocale = I18n.getLocale();
|
SupportedLocale currentLocale = I18n.getLocale();
|
||||||
cboLanguage = new JFXComboBox<>();
|
cboLanguage = new JFXComboBox<>();
|
||||||
cboLanguage.setConverter(stringConverter(locale -> {
|
cboLanguage.setConverter(stringConverter(locale -> {
|
||||||
if (locale.isSameLanguage(currentLocale) || locale == Locales.DEFAULT)
|
if (locale.isDefault())
|
||||||
return locale.getDisplayName(currentLocale);
|
return locale.getDisplayName(currentLocale);
|
||||||
|
else if (locale.isSameLanguage(currentLocale))
|
||||||
|
return locale.getDisplayName(locale);
|
||||||
else
|
else
|
||||||
return locale.getDisplayName(currentLocale) + " - " + locale.getDisplayName(locale);
|
return locale.getDisplayName(currentLocale) + " - " + locale.getDisplayName(locale);
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -44,13 +44,8 @@ public final class Locales {
|
|||||||
|
|
||||||
public static final SupportedLocale DEFAULT = new SupportedLocale("def", getDefaultLocale()) {
|
public static final SupportedLocale DEFAULT = new SupportedLocale("def", getDefaultLocale()) {
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName(SupportedLocale inLocale) {
|
public boolean isDefault() {
|
||||||
try {
|
return true;
|
||||||
return inLocale.getResourceBundle().getString("lang.default");
|
|
||||||
} catch (Throwable e) {
|
|
||||||
LOG.warning("Failed to get localized name for default locale", e);
|
|
||||||
return "Default";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,19 +87,7 @@ public final class Locales {
|
|||||||
/**
|
/**
|
||||||
* Wenyan (Classical Chinese)
|
* Wenyan (Classical Chinese)
|
||||||
*/
|
*/
|
||||||
public static final SupportedLocale WENYAN = new SupportedLocale("lzh", Locale.forLanguageTag("lzh")) {
|
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 List<SupportedLocale> LOCALES = List.of(DEFAULT, EN, ES, JA, RU, UK, ZH_HANS, ZH_HANT, WENYAN);
|
public static final List<SupportedLocale> 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;
|
this.locale = locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDefault() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -143,6 +130,26 @@ public final class Locales {
|
|||||||
public String getDisplayName(SupportedLocale inLocale) {
|
public String getDisplayName(SupportedLocale inLocale) {
|
||||||
if (inLocale.locale.getLanguage().equals("lzh"))
|
if (inLocale.locale.getLanguage().equals("lzh"))
|
||||||
inLocale = ZH_HANT;
|
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());
|
return locale.getDisplayName(inLocale.getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user