Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change language of my application [duplicate]

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?

like image 472
Manisha Patel Avatar asked Jun 24 '11 07:06

Manisha Patel


People also ask

How do I change language in Amway app?

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.


2 Answers

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> 
like image 105
Hulk Avatar answered Sep 22 '22 18:09

Hulk


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

like image 45
Android Avatar answered Sep 20 '22 18:09

Android