mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-24 03:33:46 -04:00
update
This commit is contained in:
parent
454bb8bb7d
commit
51945d837e
@ -142,9 +142,9 @@ public final class Locales {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Locale inJavaLocale = inLocale.getLocale();
|
Locale inJavaLocale = inLocale.getLocale();
|
||||||
if (LocaleUtils.isISO3Language(inJavaLocale.getLanguage())) {
|
if (inJavaLocale.getLanguage().length() > 2) {
|
||||||
String iso1 = LocaleUtils.getISO1Language(inJavaLocale);
|
String iso1 = LocaleUtils.getISO1Language(inJavaLocale);
|
||||||
if (LocaleUtils.isISO1Language(iso1)) {
|
if (iso1.length() <= 2) {
|
||||||
Locale.Builder builder = new Locale.Builder()
|
Locale.Builder builder = new Locale.Builder()
|
||||||
.setLocale(inJavaLocale)
|
.setLocale(inJavaLocale)
|
||||||
.setLanguage(iso1);
|
.setLanguage(iso1);
|
||||||
|
@ -30,7 +30,7 @@ import java.util.ResourceBundle;
|
|||||||
/// - For all Chinese locales, `zh-CN` is always added to the candidate list. If `zh-Hans` already exists in the candidate list,
|
/// - For all Chinese locales, `zh-CN` is always added to the candidate list. If `zh-Hans` already exists in the candidate list,
|
||||||
/// `zh-CN` is inserted before `zh`; otherwise, it is inserted after `zh`.
|
/// `zh-CN` is inserted before `zh`; otherwise, it is inserted after `zh`.
|
||||||
/// - For all Traditional Chinese locales, `zh-TW` is always added to the candidate list (before `zh`).
|
/// - For all Traditional Chinese locales, `zh-TW` is always added to the candidate list (before `zh`).
|
||||||
/// - For all [supported][LocaleUtils#toISO1Language(String)] ISO 639-3 language code (such as `eng`, `zho`, `lzh`, etc.),
|
/// - For all [supported][LocaleUtils#mapToISO1Language(String)] ISO 639-3 language code (such as `eng`, `zho`, `lzh`, etc.),
|
||||||
/// a candidate list with the language code replaced by the ISO 639-1 (Macro)language code is added to the end of the candidate list.
|
/// a candidate list with the language code replaced by the ISO 639-1 (Macro)language code is added to the end of the candidate list.
|
||||||
///
|
///
|
||||||
/// @author Glavo
|
/// @author Glavo
|
||||||
@ -41,7 +41,6 @@ public class DefaultResourceBundleControl extends ResourceBundle.Control {
|
|||||||
public DefaultResourceBundleControl() {
|
public DefaultResourceBundleControl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
|
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
|
||||||
return LocaleUtils.getCandidateLocales(locale);
|
return LocaleUtils.getCandidateLocales(locale);
|
||||||
|
@ -64,18 +64,24 @@ public final class LocaleUtils {
|
|||||||
: locale.stripExtensions().toLanguageTag();
|
: locale.stripExtensions().toLanguageTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isISO1Language(String language) {
|
|
||||||
return language.length() == 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isISO3Language(String language) {
|
|
||||||
return language.length() == 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull String getISO1Language(Locale locale) {
|
public static @NotNull String getISO1Language(Locale locale) {
|
||||||
String language = locale.getLanguage();
|
String language = locale.getLanguage();
|
||||||
if (language.isEmpty()) return "en";
|
if (language.isEmpty()) return "en";
|
||||||
return isISO3Language(language) ? toISO1Language(language) : language;
|
if (language.length() <= 2)
|
||||||
|
return language;
|
||||||
|
|
||||||
|
String lang = language;
|
||||||
|
while (lang != null) {
|
||||||
|
if (lang.length() <= 2)
|
||||||
|
return lang;
|
||||||
|
else {
|
||||||
|
String iso1 = mapToISO1Language(lang);
|
||||||
|
if (iso1 != null)
|
||||||
|
return iso1;
|
||||||
|
}
|
||||||
|
lang = getParentLanguage(lang);
|
||||||
|
}
|
||||||
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the script of the locale. If the script is empty and the language is Chinese,
|
/// Get the script of the locale. If the script is empty and the language is Chinese,
|
||||||
@ -288,6 +294,7 @@ public final class LocaleUtils {
|
|||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
|
/// Map ISO 639-3 language codes to ISO 639-1 language codes.
|
||||||
private static @Nullable String mapToISO1Language(String iso3Language) {
|
private static @Nullable String mapToISO1Language(String iso3Language) {
|
||||||
return switch (iso3Language) {
|
return switch (iso3Language) {
|
||||||
case "eng" -> "en";
|
case "eng" -> "en";
|
||||||
@ -309,23 +316,6 @@ public final class LocaleUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to convert ISO 639-3 language codes to ISO 639-1 language codes.
|
|
||||||
public static String toISO1Language(String languageTag) {
|
|
||||||
String lang = languageTag;
|
|
||||||
while (lang != null) {
|
|
||||||
if (lang.length() <= 2)
|
|
||||||
return lang;
|
|
||||||
else {
|
|
||||||
String iso1 = mapToISO1Language(lang);
|
|
||||||
if (iso1 != null)
|
|
||||||
return iso1;
|
|
||||||
}
|
|
||||||
lang = getParentLanguage(lang);
|
|
||||||
}
|
|
||||||
|
|
||||||
return languageTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEnglish(Locale locale) {
|
public static boolean isEnglish(Locale locale) {
|
||||||
return "en".equals(getISO1Language(locale));
|
return "en".equals(getISO1Language(locale));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user