TransWikia.com

How to list only configured languages in Android

Stack Overflow Asked on January 26, 2021

A few specific languages have been established within my Android application’s Resources (such as res/values-es/strings.xml). I’d like the user to have the ability to select from those possible languages in order to set their preferred language, should they want to.

The way I’d like to go about obtaining the list of languages is by automatic means (in case a new language is added later).

By itself, getResources().getAssets().getLocales() is not acceptable, as this lists all possible languages supported by the device. Instead, I want to acquire only those listed within res/.

How may I go about doing this? Is there a built-in function from the API, should I resort to hard-coding a string-array?

Minimum Android API: 21, Current Android API: 30, Language: Java

Thank you!

One Answer

...this lists all possible languages supported by the device. Instead, I want to acquire only those listed within res/.

That's not really a thing, sorry. Plus, it's not that simple:

  • You are using libraries, and some of those may have resources with translations whose languages may be a superset of the ones in your own source code

  • App Bundles will only ship a subset of your own languages to the user

The relationship of what the user has, compared to what is literally in your app module's res/ directory tree, is complex.

Is there a built-in function from the API, should I resort to hard-coding a string-array?

Yes, you should plan on maintaining your own language roster. You may need additional engineering work in the future for this (e.g., for App Bundles).

Correct answer by CommonsWare on January 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP