Getting the available languages of the application dynamically
Is it possible to find dynamically what are the languages supported by the application?
For example, I have strings for the following languages: English, French, Dutch and German.
They are defined in their corresponding res directories: values, values-fr
, values-nl
and values-de
.
I want to give the user the possibility to choose between them and for this I want to load them. But I don't want to hard-code the choices. I tried to use:
getApplication().getRe开发者_JAVA技巧sources().getAssets().getLocales()
But this method returns all the locales the phone supports.
Do you have any other idea?
From a android UI-guideline point of view, it is weird to offer the user an another mean than the one in the device's settings to change the locale. If your application invoke an another application, which locale will use this application?
Also I am not sure, there is a mean to browse the resources after the build process, the way resources are processed, organized and packed is a black-box, no application should try to rely on a given organization/format because this could change in the future.
精彩评论