0

I have an App where I would like to add localization. However, since the app is text heavy and the localization will be a community project, it is likely that the translations may not always be up to date.

As a result, I would prefer to make the localized optional, rather than forcing users to work with a version of mixed translated/non-translated text.

I assume this can be done using Configuration and Locale, but I haven't experimented with this yet. I'm sure I'm not the first person to need to do this, so what would be the recommended way to handle this from those of you who have done any work with Locales? Potential pitfalls?

Michael A.
  • 4,163
  • 3
  • 28
  • 47
  • Yes, you can change the [`Locale`](http://developer.android.com/reference/java/util/Locale.html) within the app itself, so you can have a setting that controls it. This has been detailed [here](http://stackoverflow.com/questions/2264874/changing-locale-within-the-app-itself), or more simply [here](http://stackoverflow.com/questions/4985805/set-locale-programatically). – Cat Aug 04 '12 at 00:10
  • Bit late replying on this, but feel free to submit this as an answer, and I'll approve it. – Michael A. Feb 08 '13 at 07:08
  • Been a while indeed! I've posted it as an answer. :) – Cat Feb 08 '13 at 15:27

1 Answers1

1

From comments:

You can modify the Locale within the app itself by using Locale.setDefault() and Resources.updateConfiguration():

// From https://stackoverflow.com/a/4986481/1438733
Locale locale = new Locale("en"); // For English; see below for more codes
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
      getBaseContext().getResources().getDisplayMetrics());

(Note: A list of ISO 639-1 codes can be found on Wikipedia.)

A somewhat more complex and detailed post on the matter can be found here.

Community
  • 1
  • 1
Cat
  • 66,919
  • 24
  • 133
  • 141