user3623874
user3623874

Reputation: 519

Change language in Android app to unsupported language

I want to allow the user of my Android app to change the language of the app. I know that I need to write code that would change the locale (e.g., from English to Russian). However, what if I want to change from English to a language that doesn't have locale? Can I create a locale just for this app and have folders like "values-xx", where "xx" would be a new locale?

Thanks

Upvotes: 1

Views: 919

Answers (1)

user3623874
user3623874

Reputation: 519

I did it myself. I changed the locale using this code:

    Resources res = context.getResources();
    Configuration configuration = res.getConfiguration();

    configuration.locale = new Locale("XX"); //"XX" is language code, even if language is unsupported
    res.updateConfiguration(configuration, res.getDisplayMetrics());

I also needed to create a new "values-xx" folder and put resource files there.

Upvotes: 2

Related Questions