I'm developing a project where I need to automatically determinate which is the user language used to created the content.
We're actually using Locale.getDefault().getLanguage()
but this can not be the right choice because, for istance, I live in Italy, I write content in Italian but my default Locale on my phone is en_US.
So I tought that maybe I could determinate it from the SIM Country (and fallback to user Locale when the device does not have one) but there's no one-to-one relation from a Country to a Language. For istance, US has en_US and es_US.
Do you have any suggestion? Should I ask the user for their current content's Locale?
What's the reason you need the user language?
I too have my locale set to en_US, and I have that because I prefer to have menus etc in English. (The translation of menus and settings etc feels strained in my native language.)
Chances are that your users will be annoyed (I know I would) if you use anything other than Locale.getDefault().getLanguage()
for whatever you're using the language for.
That being said, if you really want to use a local language, I suggest you figure out the country code by some heuristics based on
and use a hard coded lookup table from country code to (one of) the official language code(s). There are open databases with this information, see for example these resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With