Possible Duplicate:
Change language programatically in Android
I am new to Android. In my application user can select a language from three languages. Based on the language selected by user, the entire application's language should be change. How can I do this?
You can change languages by opening the drop-down menu and selecting “Settings.” Click on “Language” and select the language you want displayed. English, French and Spanish are supported in the app.
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>
You can set the locale.
Resources res = context.getResources(); // Change locale settings in the app. DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = new Locale(language_code.toLowerCase()); res.updateConfiguration(conf, dm);
If you have language specific content - you can change that base on the setting. for more detail you can see Locale and this also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With