Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Local country from the language?

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.

like image 816
tokhi Avatar asked Sep 05 '13 11:09

tokhi


People also ask

How do I get a country locale?

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.

How do I get language code from locale?

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.

How is locale determined?

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.

What is my current locale?

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.


1 Answers

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?

like image 134
Eric Stein Avatar answered Nov 06 '22 19:11

Eric Stein