H Raval H Raval - 3 months ago 8
Android Question

change app laguage as device language change

please help me as i am new to localization.

i want to change my app language as device language change...for ex. if device language set to Hindi my app also should change like facebook....

for this what should i do? create string.xml for all possibilities? or is there any library? I am asking for simplification if any...

well i know this code is used to set local

Locale locale = new Locale("pt_PT");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getApplicationContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());


but i cant understand how to meet all language support.please help me....

Answer
  1. Create a directory called values-<desired-locale> at the same level with default values directory. Examples: values-de for German, values-es for Spanish.
  2. Create a strings.xml file inside that directory and populate it with translations of your texts inside default strings.xml.
  3. Voila! System will use correct strings.xml depending on the device locale.