How to find country
from its Locale-language
?
e.g; if I set the local language
to en
then I expect to get US
as country.
Locale locale = new Locale("en");
locale.getCountry() // returns null
The issue is that I only have the country code such as: fr,de,en
and now I just want to find the right country locale from these codes.
Use of LocaleUse getCountry to get the country (or region) code and getLanguage to get the language code. You can use getDisplayCountry to get the name of the country suitable for displaying to the user. Similarly, you can use getDisplayLanguage to get the name of the language suitable for displaying to the user.
The getLanguage() method of Locale class in Java is used to get language code for the specified locale. This will either be an empty string or a lowercase ISO 639 code. Parameters: This method does not take any parameters.
A locale is a location-based language setting that determines which conversational settings and strings to display. The user specifies their locale using settings on their device. They may change this setting whenever they wish, including during a conversation with a Business Messages agent.
Find the System Locale with the System Information appPress the Win + R hotkeys together on the keyboard and type the following command in your Run box: msinfo32 . Click the System Summary section on the left. On the right, see the Locale value.
en
is English. en_US
is US English. en_GB
is, I think, UK English. Presumably using en_US would do what you want. There's a list of all the supported locales here: http://www.oracle.com/technetwork/java/javase/locales-137662.html
You can't get the country from "en" because as you can see, multiple countries may share a language. Which one would you pick?
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