Ilya Gazman
Ilya Gazman

Reputation: 32221

Android: Change to unsupported locale

I been trying to change locale using the next code:

private void changeLocal(Locale locale){
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
          getBaseContext().getResources().getDisplayMetrics());
    refresh();
}

private void refresh() {
    finish();
    Intent myIntent = new Intent(this, getClass());
    startActivity(myIntent);
}

It works for French but not for Hebrew. So I looked in to device supported locales by calling Locale.getAvailableLocales() and I found out that French is there but Hebrew not.

If I put hardcoded Hebrew text I can see it, so it is installed, but I do not know how to force the device to use it.

Please help me force the device using Hebrew.

P.S Wasn't been able to make this work without the refresh even when adding

android:configChanges="locale|layoutDirection"

to my Manifest it does not call the onConfigurationChanged of my Activity

Upvotes: 0

Views: 496

Answers (1)

Phantômaxx
Phantômaxx

Reputation: 38098

Since there are 2 distinct standards, you have to double your values folder.

Add your Hebrew strings to these folders:

values-he

and

values-iw

Some devices will use one folder. Other devices will use the other one.

Note that he is actually deprecated. So, most devices will use iw

Upvotes: 1

Related Questions