How can I change language of my application [duplicate]

Use this to change the language programmatically:

Locale locale = new Locale("en_US"); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);

Write the country code of the language in place of "en_US" for whatever language you want. For example, for Japanese, ja_JP; for Arabic, ar. Check this link for a list.

And make a folder in res/values-ja for Japanese or res/values-ar for Arabic..

And make a string.xml file, and put whatever languages you want on your layout. It will fetch the default language from values folder otherwise if you want it manually, then it will fetch from your external folder values-ar, etc.

An example of res/values-ar for Arabic:

<?xml version="1.0" encoding="UTF-8"?>
  <resources>
    <string name="label">حسب</string>
    <string name="name">بحث</string> 
    <string name="search">بحث :</string>
 </resource>

Leave a Comment