4242public 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
0 commit comments