Add multi code lang support for translations

This commit is contained in:
M M Arif 2024-03-12 13:01:32 +05:00
parent e16284c352
commit 6149ab57e7
2 changed files with 21 additions and 2 deletions

View File

@ -326,7 +326,17 @@ public class SettingsAppearanceActivity extends BaseActivity {
private static String getLanguageDisplayName(String langCode) {
Locale english = new Locale("en");
Locale translated = new Locale(langCode);
String[] multiCodeLang = langCode.split("-");
String countryCode;
if (langCode.contains("-")) {
langCode = multiCodeLang[0];
countryCode = multiCodeLang[1];
} else {
countryCode = "";
}
Locale translated = new Locale(langCode, countryCode);
return String.format(
"%s (%s)",
translated.getDisplayName(translated), translated.getDisplayName(english));

View File

@ -316,9 +316,18 @@ public class AppUtil {
public static void setAppLocale(Resources resource, String locCode) {
String[] multiCodeLang = locCode.split("-");
String countryCode;
if (locCode.contains("-")) {
locCode = multiCodeLang[0];
countryCode = multiCodeLang[1];
} else {
countryCode = "";
}
DisplayMetrics dm = resource.getDisplayMetrics();
Configuration config = resource.getConfiguration();
config.setLocale(new Locale(locCode.toLowerCase()));
config.setLocale(new Locale(locCode.toLowerCase(), countryCode));
resource.updateConfiguration(config, dm);
}