Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
55 views
in Technique[技术] by (71.8m points)

java - How to list only configured languages in Android

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!

question from:https://stackoverflow.com/questions/65545652/how-to-list-only-configured-languages-in-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

...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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...