3

On an android device I can load different languages.

Example:

English (Set as default language)
French
Italian

How can I get this list programmatically?

I know that I can get the language with this code:

Locale.getDefault().getDisplayLanguage()

Or is there a way to set the fallback language of my android app to the second language of the system?


EDIT://

Szenario:

Selected Android System Languages:

  • English (Set as default)
  • French
  • Italian

Supported App Languages:

  • string.xml (German) -> set as default
  • string-fr.xml (French)
  • string-it.xml (Italian)

Current App behavior:

  • Displays the app with the German translation.

Expected new App behavior:

  • Displays the app with the French translation because French is on the 2nd position in my Android System Language list.
Edric
  • 24,639
  • 13
  • 81
  • 91
Lingo
  • 580
  • 2
  • 7
  • 26
  • By default strings.xml will contain your default language. For example if you have a language-it.xml and the device's language is DE it will fall back to default one strings.xml – ArbenMaloku Jan 13 '20 at 14:24
  • Will you try with managing strings.xml with different languages constants ? – niceumang Jan 13 '20 at 14:25
  • @ArbenMaloku Excatly but if my strings.xml (default language) is german and in my system I just selected english french and italian. (english is not translated in the app). The app will be displayed in german but I dont want that because its not a selected system language. In this case I expect a french translation. – Lingo Jan 13 '20 at 14:32
  • @Niceumang edited my first post with a scenario explanation – Lingo Jan 13 '20 at 14:41
  • @Lingo On this case I would suggest you to have a settings option, so the user can choose between languages your app provides. Or alternatively you can have an array with your languages you provide and then check if device language exists in the array and apply that one, otherwise use the default one. – ArbenMaloku Jan 13 '20 at 14:58

1 Answers1

2

This will return all locales available on the device.

Locale.getAvailableLocales()
  • This one returns all 700+ languages which android supports. In my System Settings on my device i just added english,french and italian – Lingo Jan 13 '20 at 14:29