4

How to set Locale for Spanish Latin America?
I have stored all my strings in values-b+es+r419 folder for Spanish Latin America. But unable to set this language in locale.App is showing only default language, not changing the language of app.

Locale locale = new Locale("es","419"); 
Locale.setDefault(locale); 
Configuration config = new Configuration(); 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {         
    config.setLocale(locale); 
} else{ 
    config.locale=locale; 
} 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 
    context.createConfigurationContext(config); 
} else { 
    context.getResources()
           .updateConfiguration(config, context.getResources().getDisplayMetrics()); 
}
  • check this [answer](https://stackoverflow.com/a/42269965/886001) to change locale programmatically.. that way you'll be getting resources from the desired locale – ColdFire Apr 25 '18 at 14:40
  • Thanks for reply,But i want to know code for Spanish Latin America while setting locale by coding LanguageHelper.setAppLocale("fa", this); // therefore what is the reeplacement of "fa" for values-b+es+r419 – Amritpal singh Apr 25 '18 at 14:43
  • 1
    I see.. as provided in the previous link to set locale you use `configuration.setLocale(new Locale("es", "419"))`.. let me know if this helps – ColdFire Apr 25 '18 at 14:52
  • But my app language still not changing.It shows only default language. – Amritpal singh Apr 25 '18 at 15:09
  • in this case post the code you've tried so far.. so we can have more understanding about what's not working – ColdFire Apr 25 '18 at 15:20
  • Locale locale = locale = new Locale("es","419"); Locale.setDefault(locale); Configuration config = new Configuration(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){ config.setLocale(locale); } else{ config.locale=locale; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){ context.createConfigurationContext(config); } else { context.getResources().updateConfiguration(config,context.getResources().getDisplayMetrics()); } // here is my code – Amritpal singh Apr 25 '18 at 15:38
  • first don't create `new Configuration()` use `getResources().getConfiguration()` instead.. then you need to restart activity to fetch correct resources using `activity.recreate()` – ColdFire Apr 25 '18 at 15:46
  • and change `Locale locale = locale = new Locale("es","419"); ` to this `Locale locale = new Locale("es","419"); ` – ColdFire Apr 25 '18 at 15:50
  • I make these changes in my app but now it showing strings of spanish(es) language, not showing strings of Spanish latin America(es_419) – Amritpal singh Apr 26 '18 at 04:16
  • My app still not recognizing b+es+r419 – Amritpal singh Apr 26 '18 at 05:54
  • according to [documentation](https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources) your qualifier for values should be `b+es+419`.. you can find language tags [here](https://tools.ietf.org/html/bcp47) as well – ColdFire Apr 26 '18 at 08:04

0 Answers0