Skip to content Skip to sidebar Skip to footer

Changing Locale Programmatically Not Working In Some Devices

I've the following piece of code: /** * Sets a new Locale for the APP. * @param newLocale - Valid new locale. */ private static void setLocale( String newLocale ) { Locale l

Solution 1:

This is the code I am using for localisation. It is used by + 1m people and never heard of any complaint about not changing strings so I hope it will work for you as well:

On top of class:

Locale myLocale;

Function:

    public void setLocale(String lang) { 
        myLocale = new Locale(lang); 
        Resources res = getResources(); 
        DisplayMetrics dm = res.getDisplayMetrics(); 
        Configuration conf = res.getConfiguration(); 
        conf.locale = myLocale; 
        res.updateConfiguration(conf, dm);
        reloadUI(); // you may not need this, in my activity ui must be refreshed immediately so it has a function like this.
    }

Function Call:

//example for setting English
setLocale("en_gb");

Solution 2:

Well,

User Sir SC provided an answer which worked. But my code, also worked. The issue we were facing, was about a single device ignoring this locale change. So AFAIK, it's just a single device, and it might be caused because of a buggy ROM, as it was a Genymotion Emulator.

So overall, the answer is:

  • The code OP posted, is valid and working. So is the code from Sir SC.

Cheers.


Post a Comment for "Changing Locale Programmatically Not Working In Some Devices"