Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Is there any way to change the default language of android to new language?

Tags:

java

android

I'm trying to know whether it is possible to change the default android OS language to other. For which the language is not in the settings for instance: how to set the device 's language to burmese programmatically.

like image 217
Pattabi Raman Avatar asked Mar 13 '12 06:03

Pattabi Raman


2 Answers

Use this to change the language by 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 countrycode of language in place of "en_US" whatever language you want...like for japanese--"ja_JP" For Arabic--"ar" or check this link for code of country--

http://code.google.com/apis/igoogle/docs/i18n.html

And make a folder in res/values-ja for japanese or res/values-ar for arabic..

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

Its example of res/values-ar for arabic--

<?xml version="1.0" encoding="UTF-8"?>
  <resources>
    <string name="spinner_label">تصفية حسب</string>
    <string name="app_name">2011 فرق</string> 
    <string name="search">بحث :</string>
</resource>

Hope It will help you..

like image 169
Hulk Avatar answered Oct 02 '22 23:10

Hulk


you can change the locale to whatever you want and the system need support it.

try this:

public static void changeLocale(Locale locale) {
    try {
        Class<?> activityManagerNative = Class.forName("android.app.ActivityManagerNative");

        Object am = activityManagerNative.getMethod("getDefault").invoke(activityManagerNative);

        Object config = am.getClass().getMethod("getConfiguration").invoke(am);
        config.getClass().getDeclaredField("locale").set(config, locale);
        config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true);

        am.getClass().getMethod("updateConfiguration", android.content.res.Configuration.class).invoke(am, config);
        Log.i(LOG_TAG, "send change locale request");
    } catch (Exception e) {
        Log.e(LOG_TAG, "change locale error:", e);
    }
}
like image 36
idiottiger Avatar answered Oct 02 '22 23:10

idiottiger