AppCompatDelegate.setApplicationLocales does not translate activity labels in Manifest for Android 12 and less

22 views Asked by At

In ANdroid java, I have this code to change language

private void translateToLanguage() {
        int positionLanguage = getSharedPreferences(LANGUAGE_SHARED_PREF, Context.MODE_PRIVATE).getInt(PREFKEY_LANGUAGE, 0);
        String[] languagesListCode = getResources().getStringArray(R.array.languages_array_code);
        if(!getResources().getConfiguration().getLocales().get(0).getLanguage().equals(languagesListCode[positionLanguage])) {
            LocaleListCompat appLocale = LocaleListCompat.forLanguageTags(languagesListCode[positionLanguage]);
            AppCompatDelegate.setApplicationLocales(appLocale);

        }
    }

It works perfectly for Android 13. However, for Android 12 and less, it works except that Activity labels sets in manifests are not translated (whereas it is in ANdroid 13). Do you know how to fix this issue?

0

There are 0 answers