当前位置: 动力学知识库 > 问答 > 编程问答 >

How to get all Java supported Locales

问题描述:

When Google you will find lot of materials to find all the supported Locales by Java. But its all confusing.

For example [http://sanjaal.com/java/tag/java-locale-tutorial/] show an output of 210 locales. But when I run the same program I get only 155. I don;t get for example ta_IN. si_LK is not output by any program.

Can someone please clear the air?

I use JDK/JRE 1.7

http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html gives 111 entries.

I have a Spring Application which supports i18n and our customers can put their own localisations. What I am trying to do is to provide a list of all locales for them to select their one from.

Oh! this is confusing. Local.getISOCountries() provide LK as a country and Locale.getISOLanguages(); provide si as a language .... but si_LK which is a valid locale is not given in Locale.getAvailableLocales();

网友答案:
    Locale loc = new Locale("ta", "IN"); // ta_IN, si_LK
    System.out.printf("Name: %s%n"
            + "Country: %s; %s - %s%n"
            + "Language: %s; %s - %s%n"
            + "Script: %s - %s%n",
            loc.getDisplayName(Locale.ENGLISH),
            loc.getCountry(), loc.getISO3Country(), loc.getDisplayCountry(Locale.ENGLISH),
            loc.getLanguage(), loc.getISO3Language(), loc.getDisplayLanguage(Locale.ENGLISH),
            loc.getScript(), loc.getDisplayScript(Locale.ENGLISH));

Name: Tamil (India)
Country: IN; IND - India
Language: ta; tam - Tamil
Script:  - 

Name: Sinhalese (Sri Lanka)
Country: LK; LKA - Sri Lanka
Language: si; sin - Sinhalese
Script:  - 

Also it is possible to provide support for ones own locale (since Java 7 I believe). I made it for Esperanto, and it is doable (LocaleProvider). But in your case all might be there.


    SimpleDateFormat f = new SimpleDateFormat("EEEE", loc);
    System.out.println("Weekday: " + f.format(new Date()));

Unfortunately shows "Tuesday," so one needs to implement the language formats and such. I found a project for serbo-croatian/bosnian.

网友答案:

The code you found on internet use the next function to extract all the locales:

Locale list[] = DateFormat.getAvailableLocales();

If we read the documentation for that function:

Returns an array of all locales for which the get*Instance methods of this class can return localized instances. The returned array represents the union of locales supported by the Java runtime and by installed DateFormatProvider implementations. It must contain at least a Locale instance equal to Locale.US

So we can understand that the number of locales returned depends on your runtime version, and your DateFormatProvider.

For example in my machine with JDK 1.6.0_27 I get 152 results.

分享给朋友:
您可能感兴趣的文章:
随机阅读: