4

How do I localize application so it uses specific locale regardless of what locale set on device? I want make it possible for users to set language of their choice.

So far I have code like this in my Application class:

@Override public void onCreate() { //Set locale String l = Preferences.getLocale(getApplicationContext()); if (!l.equals("")) { Locale locale = new Locale(l); Locale.setDefault(locale); Configuration config = getBaseContext().getResources().getConfiguration(); config.locale = locale; getBaseContext().getResources().updateConfiguration( config, getBaseContext().getResources().getDisplayMetrics()); } LogData.InsertMessage(getApplicationContext(), "Application started"); } 

Problem that I have is that it seems like I display in set locale just fine (TextViews) But Menu captions and toasts will fall to default locale.

Is there any 1-2-3 on how to get it working properly? I uses 2.2 version

2
  • Why would you do such a thing? Do you expect your users to have their device set to one language and want your app to use a different one? Commented May 30, 2011 at 21:16
  • @Noah Just today we had an issue. All users in and but some phones like IVO do not allow anything but English/Spanish. Allowing localizing at app level really helps those people. Commented Jun 30, 2011 at 22:50

1 Answer 1

1

Ok, I figured why I had this problem.. I needed to override onConfigurationChanged in my application class. That is much more elegant solution than to specify locale on each Activity.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.