1

My app supports multiple languages(values-es, values-de...) But how can add option to override that

For example:

user has set its system language to English so my app will use default values folder.

I want to add option so that it can select any of the languages available in my app.

If user selects German(in my app not in system settings) it will use strings from values-de

Is there a way to do that?

Kai
  • 38,985
  • 14
  • 88
  • 103
pedja
  • 3,285
  • 5
  • 36
  • 48
  • 1
    See: http://stackoverflow.com/questions/11155623/android-restrict-language-in-an-application/11208833#11208833 – Gunnar Karlsson Nov 16 '12 at 13:35
  • 1
    http://developer.android.com/guide/topics/resources/localization.html – faradaj Nov 16 '12 at 13:36
  • Thanks **Configuration configuration = context.getResources().getConfiguration(); configuration.locale = new Locale(selectedLanguage); context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics());** This worked from first link – pedja Nov 16 '12 at 13:52
  • I knew I was forgetting something. I was just about to edit my answer with that then I saw the comment. Glad you got it working :) – codeMagic Nov 16 '12 at 13:56

1 Answers1

1

I have just done this for my app. Everything I have read says that it is not a good idea as the Android framework doesn't support it and there may be bugs in the future. Nonetheless, I was told this is how we wanted to do it and so I did. So far, mine is working fine for Spanish. You will need to add

android:configChanges="orientation|locale">

in all of your activities. You may not need the orientation but I did so that the language would stay if the device is turned. You also may have to do some other work such as setting the language in your onCofigChanged in activities...at least I did. There may be a better way to do it but this is how I got it to work. Good luck

codeMagic
  • 44,549
  • 13
  • 77
  • 93