Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know a library containing all localized country names in java? [duplicate]

Tags:

java

Possible Duplicate:
Localized country names

Is there any java lib that contains all countries localized in the main european languages?

I've tried using java.util.Locale but it doesn't contain all the the countries (it's missing some like san marino, andorra, azerbeijan...)


EDIT

This:

for (Locale locale : Locale.getAvailableLocales())
    {
         System.out.println(locale.getCountry() + "  " + locale.getDisplayCountry());
    }

Outputs this: (my locale is english)

AE  United Arab Emirates
AL  Albania
AR  Argentina
AT  Austria
AU  Australia
BA  Bosnia and Herzegovina
BE  Belgium
BG  Bulgaria
BH  Bahrain
BO  Bolivia
BR  Brazil
BY  Belarus
CA  Canada
CH  Switzerland
CL  Chile
CN  China
CO  Colombia
CR  Costa Rica
CS  Serbia and Montenegro
CY  Cyprus
CZ  Czech Republic
DE  Germany
DK  Denmark
DO  Dominican Republic
DZ  Algeria
EC  Ecuador
EE  Estonia
EG  Egypt
ES  Spain
FI  Finland
FR  France
GB  United Kingdom
GR  Greece
GT  Guatemala
HK  Hong Kong
HN  Honduras
HR  Croatia
HU  Hungary
ID  Indonesia
IE  Ireland
IL  Israel
IN  India
IQ  Iraq
IS  Iceland
IT  Italy
JO  Jordan
JP  Japan
KR  South Korea
KW  Kuwait
LB  Lebanon
LT  Lithuania
LU  Luxembourg
LV  Latvia
LY  Libya
MA  Morocco
ME  Montenegro
MK  Macedonia
MT  Malta
MX  Mexico
MY  Malaysia
NI  Nicaragua
NL  Netherlands
NO  Norway
NZ  New Zealand
OM  Oman
PA  Panama
PE  Peru
PH  Philippines
PL  Poland
PR  Puerto Rico
PT  Portugal
PY  Paraguay
QA  Qatar
RO  Romania
RS  Serbia
RU  Russia
SA  Saudi Arabia
SD  Sudan
SE  Sweden
SG  Singapore
SI  Slovenia
SK  Slovakia
SV  El Salvador
SY  Syria
TH  Thailand
TN  Tunisia
TR  Turkey
TW  Taiwan
UA  Ukraine
US  United States
UY  Uruguay
VE  Venezuela
VN  Vietnam
YE  Yemen
ZA  South Africa

Before you click "close" read the questions:

This question is not a dupe of the candidate duplicated question! The other question is not related with java in any way! It even has objective-c code in it!

like image 686
fmsf Avatar asked Oct 19 '12 12:10

fmsf


1 Answers

You can use Locale.getISOCountries(). For example the following code prints the German names of all countries defined in ISO 3166.

Locale locale = Locale.GERMAN;      
for (String country : Locale.getISOCountries())
{
    System.out.println(new Locale("", country).getDisplayCountry(locale));
}

This uses the LocaleNames_xx.properties resource bundles. Here's the default version in the JDK repository.

Update, 13.05.2020: The Javadoc states that this will return a name for the locale's country that is appropriate for display to the user. While there is some overlap, the above code will not always return the ISO-3166 name. There is a JDK bug report discussing this. See my comments below for more details.

like image 102
martin Avatar answered Oct 15 '22 02:10

martin