Skip to content

Commit 8823ae8

Browse files
authored
将阿拉伯语列为实验性支持语言 (#4851)
1 parent a7b952f commit 8823ae8

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public static SupportedLocale getLocale() {
4545
}
4646

4747
public static boolean isUpsideDown() {
48-
return LocaleUtils.getScript(locale.getLocale()).equals("Qabs");
48+
return LocaleUtils.getScript(locale.getDisplayLocale()).equals("Qabs");
4949
}
5050

5151
public static boolean isUseChinese() {
52-
return LocaleUtils.isChinese(locale.getLocale());
52+
return LocaleUtils.isChinese(locale.getDisplayLocale());
5353
}
5454

5555
public static ResourceBundle getResourceBundle() {

HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/SupportedLocale.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
public final class SupportedLocale {
4343
public static final SupportedLocale DEFAULT = new SupportedLocale();
4444

45+
public static boolean isExperimentalSupported(Locale locale) {
46+
return "ar".equals(locale.getLanguage());
47+
}
48+
4549
private static final ConcurrentMap<Locale, SupportedLocale> LOCALES = new ConcurrentHashMap<>();
4650

4751
public static List<SupportedLocale> getSupportedLocales() {
@@ -51,7 +55,11 @@ public static List<SupportedLocale> getSupportedLocales() {
5155
InputStream locales = SupportedLocale.class.getResourceAsStream("/assets/lang/languages.json");
5256
if (locales != null) {
5357
try (locales) {
54-
list.addAll(JsonUtils.fromNonNullJsonFully(locales, JsonUtils.listTypeOf(SupportedLocale.class)));
58+
for (SupportedLocale locale : JsonUtils.fromNonNullJsonFully(locales, JsonUtils.listTypeOf(SupportedLocale.class))) {
59+
if (!isExperimentalSupported(locale.getLocale())) {
60+
list.add(locale);
61+
}
62+
}
5563
} catch (Throwable e) {
5664
LOG.warning("Failed to load languages.json", e);
5765
}
@@ -73,6 +81,7 @@ public static SupportedLocale getLocaleByName(String name) {
7381
private final boolean isDefault;
7482
private final String name;
7583
private final Locale locale;
84+
private final Locale displayLocale;
7685
private final TextDirection textDirection;
7786

7887
private ResourceBundle resourceBundle;
@@ -85,16 +94,23 @@ public static SupportedLocale getLocaleByName(String name) {
8594
this.name = "def"; // TODO: Change to "default" after updating the Config format
8695

8796
String language = System.getenv("HMCL_LANGUAGE");
88-
this.locale = StringUtils.isBlank(language)
89-
? LocaleUtils.SYSTEM_DEFAULT
90-
: Locale.forLanguageTag(language);
97+
if (StringUtils.isBlank(language)) {
98+
this.locale = LocaleUtils.SYSTEM_DEFAULT;
99+
this.displayLocale = isExperimentalSupported(this.locale)
100+
? Locale.ENGLISH
101+
: this.locale;
102+
} else {
103+
this.locale = Locale.forLanguageTag(language);
104+
this.displayLocale = this.locale;
105+
}
91106
this.textDirection = LocaleUtils.getTextDirection(locale);
92107
}
93108

94109
SupportedLocale(Locale locale) {
95110
this.isDefault = false;
96111
this.name = locale.toLanguageTag();
97112
this.locale = locale;
113+
this.displayLocale = locale;
98114
this.textDirection = LocaleUtils.getTextDirection(locale);
99115
}
100116

@@ -110,6 +126,15 @@ public Locale getLocale() {
110126
return locale;
111127
}
112128

129+
/// Used to represent the text display language of HMCL.
130+
///
131+
/// Usually equivalent to [#getLocale()],
132+
/// but for [experimentally supported languages][#isExperimentalSupported(Locale)],
133+
/// it falls back to ENGLISH by default.
134+
public Locale getDisplayLocale() {
135+
return displayLocale;
136+
}
137+
113138
public TextDirection getTextDirection() {
114139
return textDirection;
115140
}
@@ -167,7 +192,7 @@ public String getDisplayName(SupportedLocale inLocale) {
167192
public ResourceBundle getResourceBundle() {
168193
ResourceBundle bundle = resourceBundle;
169194
if (resourceBundle == null)
170-
resourceBundle = bundle = ResourceBundle.getBundle("assets.lang.I18N", locale,
195+
resourceBundle = bundle = ResourceBundle.getBundle("assets.lang.I18N", displayLocale,
171196
DefaultResourceBundleControl.INSTANCE);
172197

173198
return bundle;
@@ -176,15 +201,15 @@ public ResourceBundle getResourceBundle() {
176201
public ResourceBundle getLocaleNamesBundle() {
177202
ResourceBundle bundle = localeNamesBundle;
178203
if (localeNamesBundle == null)
179-
localeNamesBundle = bundle = ResourceBundle.getBundle("assets.lang.LocaleNames", locale,
204+
localeNamesBundle = bundle = ResourceBundle.getBundle("assets.lang.LocaleNames", displayLocale,
180205
DefaultResourceBundleControl.INSTANCE);
181206

182207
return bundle;
183208
}
184209

185210
public List<Locale> getCandidateLocales() {
186211
if (candidateLocales == null)
187-
candidateLocales = List.copyOf(LocaleUtils.getCandidateLocales(locale));
212+
candidateLocales = List.copyOf(LocaleUtils.getCandidateLocales(displayLocale));
188213
return candidateLocales;
189214
}
190215

HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/translator/Translator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
/// @author Glavo
2929
public class Translator {
3030
protected final SupportedLocale supportedLocale;
31-
protected final Locale locale;
31+
protected final Locale displayLocale;
3232

3333
public Translator(SupportedLocale supportedLocale) {
3434
this.supportedLocale = supportedLocale;
35-
this.locale = supportedLocale.getLocale();
35+
this.displayLocale = supportedLocale.getDisplayLocale();
3636
}
3737

3838
public final SupportedLocale getSupportedLocale() {
3939
return supportedLocale;
4040
}
4141

42-
public final Locale getLocale() {
43-
return locale;
42+
public final Locale getDisplayLocale() {
43+
return displayLocale;
4444
}
4545

4646
public String getDisplayVersion(RemoteVersion remoteVersion) {

0 commit comments

Comments
 (0)