Michael A.
Michael A.

Reputation: 4193

User configurable localization in an App

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?

Upvotes: 0

Views: 132

Answers (1)

Cat
Cat

Reputation: 67502

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.

Upvotes: 1

Related Questions