Added hard-coded Chinese language exceptions
@@ -16,11 +16,24 @@ public class LocaleUtils {
public static String getLanguageNameFromCode(@NonNull String languageCode) throws InvalidLocaleException {
final String lowercaseLanguage = languageCode.toLowerCase(Locale.ROOT);
+
+ switch (lowercaseLanguage) {
+ /* Chinese languages are special cases. The server uses different codes when compared
+ to Android's locale library. Additionally, zh_CN and zh_TW are not languageCodes that
+ Android's locale recognizes as exceptions. */
+ case "zh_cn":
+ case "zh_hans":
+ return Locale.SIMPLIFIED_CHINESE.getDisplayLanguage();
+ case "zh_tw":
+ case "zh_hant":
+ return Locale.TRADITIONAL_CHINESE.getDisplayLanguage();
+ default:
if (!isValidBcp47Alpha(lowercaseLanguage, 2, 3)) {
throw new InvalidLocaleException("Invalid language: " + languageCode);
}
return new Locale(languageCode).getDisplayLanguage();
}
+ }
// Copied from Locale.Builder in API 21
@@ -36,7 +49,6 @@ public class LocaleUtils {
return false;
}
}
-
return true;
}
}
