将阿拉伯语列为实验性支持语言 (#4851)
This commit is contained in:
@@ -45,11 +45,11 @@ public final class I18n {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUpsideDown() {
|
public static boolean isUpsideDown() {
|
||||||
return LocaleUtils.getScript(locale.getLocale()).equals("Qabs");
|
return LocaleUtils.getScript(locale.getDisplayLocale()).equals("Qabs");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUseChinese() {
|
public static boolean isUseChinese() {
|
||||||
return LocaleUtils.isChinese(locale.getLocale());
|
return LocaleUtils.isChinese(locale.getDisplayLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceBundle getResourceBundle() {
|
public static ResourceBundle getResourceBundle() {
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
|||||||
public final class SupportedLocale {
|
public final class SupportedLocale {
|
||||||
public static final SupportedLocale DEFAULT = new SupportedLocale();
|
public static final SupportedLocale DEFAULT = new SupportedLocale();
|
||||||
|
|
||||||
|
public static boolean isExperimentalSupported(Locale locale) {
|
||||||
|
return "ar".equals(locale.getLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
private static final ConcurrentMap<Locale, SupportedLocale> LOCALES = new ConcurrentHashMap<>();
|
private static final ConcurrentMap<Locale, SupportedLocale> LOCALES = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static List<SupportedLocale> getSupportedLocales() {
|
public static List<SupportedLocale> getSupportedLocales() {
|
||||||
@@ -51,7 +55,11 @@ public final class SupportedLocale {
|
|||||||
InputStream locales = SupportedLocale.class.getResourceAsStream("/assets/lang/languages.json");
|
InputStream locales = SupportedLocale.class.getResourceAsStream("/assets/lang/languages.json");
|
||||||
if (locales != null) {
|
if (locales != null) {
|
||||||
try (locales) {
|
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) {
|
} catch (Throwable e) {
|
||||||
LOG.warning("Failed to load languages.json", e);
|
LOG.warning("Failed to load languages.json", e);
|
||||||
}
|
}
|
||||||
@@ -73,6 +81,7 @@ public final class SupportedLocale {
|
|||||||
private final boolean isDefault;
|
private final boolean isDefault;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Locale locale;
|
private final Locale locale;
|
||||||
|
private final Locale displayLocale;
|
||||||
private final TextDirection textDirection;
|
private final TextDirection textDirection;
|
||||||
|
|
||||||
private ResourceBundle resourceBundle;
|
private ResourceBundle resourceBundle;
|
||||||
@@ -85,9 +94,15 @@ public final class SupportedLocale {
|
|||||||
this.name = "def"; // TODO: Change to "default" after updating the Config format
|
this.name = "def"; // TODO: Change to "default" after updating the Config format
|
||||||
|
|
||||||
String language = System.getenv("HMCL_LANGUAGE");
|
String language = System.getenv("HMCL_LANGUAGE");
|
||||||
this.locale = StringUtils.isBlank(language)
|
if (StringUtils.isBlank(language)) {
|
||||||
? LocaleUtils.SYSTEM_DEFAULT
|
this.locale = LocaleUtils.SYSTEM_DEFAULT;
|
||||||
: Locale.forLanguageTag(language);
|
this.displayLocale = isExperimentalSupported(this.locale)
|
||||||
|
? Locale.ENGLISH
|
||||||
|
: this.locale;
|
||||||
|
} else {
|
||||||
|
this.locale = Locale.forLanguageTag(language);
|
||||||
|
this.displayLocale = this.locale;
|
||||||
|
}
|
||||||
this.textDirection = LocaleUtils.getTextDirection(locale);
|
this.textDirection = LocaleUtils.getTextDirection(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +110,7 @@ public final class SupportedLocale {
|
|||||||
this.isDefault = false;
|
this.isDefault = false;
|
||||||
this.name = locale.toLanguageTag();
|
this.name = locale.toLanguageTag();
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
|
this.displayLocale = locale;
|
||||||
this.textDirection = LocaleUtils.getTextDirection(locale);
|
this.textDirection = LocaleUtils.getTextDirection(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +126,15 @@ public final class SupportedLocale {
|
|||||||
return locale;
|
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() {
|
public TextDirection getTextDirection() {
|
||||||
return textDirection;
|
return textDirection;
|
||||||
}
|
}
|
||||||
@@ -167,7 +192,7 @@ public final class SupportedLocale {
|
|||||||
public ResourceBundle getResourceBundle() {
|
public ResourceBundle getResourceBundle() {
|
||||||
ResourceBundle bundle = resourceBundle;
|
ResourceBundle bundle = resourceBundle;
|
||||||
if (resourceBundle == null)
|
if (resourceBundle == null)
|
||||||
resourceBundle = bundle = ResourceBundle.getBundle("assets.lang.I18N", locale,
|
resourceBundle = bundle = ResourceBundle.getBundle("assets.lang.I18N", displayLocale,
|
||||||
DefaultResourceBundleControl.INSTANCE);
|
DefaultResourceBundleControl.INSTANCE);
|
||||||
|
|
||||||
return bundle;
|
return bundle;
|
||||||
@@ -176,7 +201,7 @@ public final class SupportedLocale {
|
|||||||
public ResourceBundle getLocaleNamesBundle() {
|
public ResourceBundle getLocaleNamesBundle() {
|
||||||
ResourceBundle bundle = localeNamesBundle;
|
ResourceBundle bundle = localeNamesBundle;
|
||||||
if (localeNamesBundle == null)
|
if (localeNamesBundle == null)
|
||||||
localeNamesBundle = bundle = ResourceBundle.getBundle("assets.lang.LocaleNames", locale,
|
localeNamesBundle = bundle = ResourceBundle.getBundle("assets.lang.LocaleNames", displayLocale,
|
||||||
DefaultResourceBundleControl.INSTANCE);
|
DefaultResourceBundleControl.INSTANCE);
|
||||||
|
|
||||||
return bundle;
|
return bundle;
|
||||||
@@ -184,7 +209,7 @@ public final class SupportedLocale {
|
|||||||
|
|
||||||
public List<Locale> getCandidateLocales() {
|
public List<Locale> getCandidateLocales() {
|
||||||
if (candidateLocales == null)
|
if (candidateLocales == null)
|
||||||
candidateLocales = List.copyOf(LocaleUtils.getCandidateLocales(locale));
|
candidateLocales = List.copyOf(LocaleUtils.getCandidateLocales(displayLocale));
|
||||||
return candidateLocales;
|
return candidateLocales;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,19 +28,19 @@ import java.util.Locale;
|
|||||||
/// @author Glavo
|
/// @author Glavo
|
||||||
public class Translator {
|
public class Translator {
|
||||||
protected final SupportedLocale supportedLocale;
|
protected final SupportedLocale supportedLocale;
|
||||||
protected final Locale locale;
|
protected final Locale displayLocale;
|
||||||
|
|
||||||
public Translator(SupportedLocale supportedLocale) {
|
public Translator(SupportedLocale supportedLocale) {
|
||||||
this.supportedLocale = supportedLocale;
|
this.supportedLocale = supportedLocale;
|
||||||
this.locale = supportedLocale.getLocale();
|
this.displayLocale = supportedLocale.getDisplayLocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final SupportedLocale getSupportedLocale() {
|
public final SupportedLocale getSupportedLocale() {
|
||||||
return supportedLocale;
|
return supportedLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Locale getLocale() {
|
public final Locale getDisplayLocale() {
|
||||||
return locale;
|
return displayLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayVersion(RemoteVersion remoteVersion) {
|
public String getDisplayVersion(RemoteVersion remoteVersion) {
|
||||||
|
|||||||
Reference in New Issue
Block a user