Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multi language android application?

Tags:

android

locale

I have to make my Android application in 3 languages ie German, English and dutch. i have made three folders in my android application names values-de and values-nl within the res directory. now when the user selects a specific language i perform the following code:

Resources res = getResources();
Configuration newConfig = new Configuration(res.getConfiguration());
newConfig.locale = Locale.ENGLISH;
res.updateConfiguration(newConfig, null);

all the strings in the different values folders have the same name, i.e a string with name add_site in the values folder has the same name in the values-de folder but with a different value. My application is not loading the German value when i set the locale to German? what could be the problem?

thank you for you help.

like image 285
user590849 Avatar asked Mar 18 '11 05:03

user590849


People also ask

Can I change the language of one app in Android?

Change the language setting for a specific app On your Android phone, open your Settings app. App languages. Select the app you want to change. Choose a language.


1 Answers

Try putting this in onCreate() just after the call to super.onCreate:

Locale locale = new Locale("de");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
      getBaseContext().getResources().getDisplayMetrics());

EDIT: Here's another approach. It seems to be very flexible, but there seems to be some disagreement in the comments whether it works on all Android versions.

like image 96
Ted Hopp Avatar answered Sep 23 '22 01:09

Ted Hopp