Search code examples
androidlocale

How to show Locale List based on the Resource availability


I am developing an application that fetches all the system available locales and show in a listview to be selected by user to change the application language(just like android's language change option).

But I have a few res/values folder in my application resources like values (default), values-bn, values-zh, values-ar. SO I want these 4 languages to be shown in the list. How can I do this? I need to do this programmatically.

Suppose, I have 4 folders values, values-bn, values-en, values-zh

Then I only show,

Bengali
English
Chinese  

Solution

  • OK, so what you want to do is have four languages: English, Bengali, Chinese, and Arabic, have I got that right? (Your question is internally inconsistent so it's hard to tell).

    And you want to have a set of fallback values for when a string is missing in one of those four languages. The fallback values are in English, although the system won't know or care about that.

    So what you want to do is put the strings for the four languages in the values-en, values-bn, values-zh, and values-ar directories and the fallback strings in the values directory.

    In fact, since your fallback strings are in English, you could just put them in the values directory and have an empty resources file in the values-en directory. English would still show up in the list.

    But why not just put the English versions of the strings in the values-en directory?