4
votes

I have a samsung galaxy y duos and a Google Nexus 5 with me. I have my application running on both phones. I have to provide this app in two languages (Kannada & English). I choose the language by switching the locale (By convention).

Nexus 5 has the locale "kn" in its locale list and Y Duos does not have "kn" in it. But when I try to use String.xml inside values-kn folder, the Kannada texts are being rendered properly in Y Duos even though it has no "kn" locale in it.

I have a piece of code which looks for "kn" locale and enable/disable Kannada language feature. It is given below.

public boolean isLocalePresent(Locale newLocale) {
    Locale[] locales = Locale.getAvailableLocales();
    for (Locale locale : locales) {
        if (locale.getLanguage().equals(newLocale.getLanguage()) {
            return true;
        }
    }
    return false;
}

I call it as follows;

if (isLocalePresent(new Locale("kn"))) {
    // change default locale to "kn"
}

Could anyone please tell me how can I make my app use Kannada texts in all phones that can render Kannada text.? How can I know that whether the phone supports Kannada text rendering even if "kn" locale is absent in the Locale list.?

1
hi, were you able to make kannada as locale? i am struggling with same problem.. can u help?karthi
The locale is not available on all phones. But you can create a new locale with language as "kn" and set it as default locale in your app. The problem still exists. I did not get a proper solution buddy.rahulrvp

1 Answers

1
votes

I had the same problem. Tried some options, and with below code in my Application

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        setLocale(new Locale("kn"));
    }

    public void setLocale(Locale newLocale) {
        Locale.setDefault(newLocale);
        android.content.res.Configuration config = new android.content.res.Configuration();
        config.locale = newLocale;
        getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    }
}

things are working as expected.