1

Ok i have an application with 2 different languages (english and german), how to change them from my application? When i click the Language button im using intent to com.android.settings.LocalePicker and from there i select the language. So instead of that i want to select English and German options from dialog box. I know how to create the dialog box, but don't know how to change the locale.

nCounTr
  • 25
  • 2
  • 9
  • just to know... how are you doing the localization? where are you saving the different languages text? – Cristian Jul 01 '10 at 21:38
  • if you want the strings to be in german, you use folder values-de, or for french values-fr, italian-it and so on, and you put your strings.xml with the translated values for the strings. Note that for some languages it's different, let's say if u use macedonian than u need to put the strings.xml into values-mk and values-en-rMK, or for simplified-chinese values-zh-rCN, traditional-chinese values-zh-rTW. You can find more info in android sdk/dev docs. – nCounTr Jul 01 '10 at 21:53

2 Answers2

2

Application resources are fetched using the system local which isn't changeable from within an application.

The system settings screen uses a class (ActivityManagerNative) which isn't available via the SDK and thus can not be guaranteed to work between releases, and hence shouldn't be used in your code.

So your options are;

  • Don't offer the functionality in your app
  • Implement your own system for determining what setting the user has selected in your app and pulling the appropriate resources using your own code.
Al Sutton
  • 3,904
  • 1
  • 22
  • 17
2

try this :

  1. create a normal android dialog with radio button selection of English & German
  2. OnCheckedChange ()

write this to change the Language

Locale myLocale = new Locale(/*String selected*/);
Locale.setDefault(myLocale );

Configuration config2 = new Configuration();
config2.locale = myLocale ;
getBaseContext().getResources().updateConfiguration(config2,
  getBaseContext().getResources().getDisplayMetrics());   
Deepak Swami
  • 3,838
  • 1
  • 31
  • 46
Faheem
  • 21
  • 1