Accessing locale information in Java is a matter of using the Locale class. It comes with a number of pre-defined convenient constants that cover commonly used locales. There are 22 of these and include basic countries such as: FRANCE, UK, US and JAPAN and basic languages such as: FRENCH, ENGLISH and JAPANESE.
It is possible, however, to list all the locales supported by your JVM using the LocaleServiceProvider class as demonstrated by the following code snippet.
System.out.println("All Locale Information");
System.out.println("\nDisplayName,Country,Display Country,ISO3 Country Code,Language,"
+ "Display Language,ISO3 Language Code,Display Varient,Varient, File Suffix");
Locale[] locales = Locale.getAvailableLocales();
for (Locale locale : locales) {
String country = locale.getCountry();
String displayCountry = locale.getDisplayCountry();
String displayLanguage = locale.getDisplayLanguage();
String displayName = locale.getDisplayName();
String displayVarient = locale.getDisplayVariant();
String iso3CountryCode = locale.getISO3Country();
String iso3LanguageCode = locale.getISO3Language();
String language = locale.getLanguage();
String varient = locale.getVariant();
String separator = ",";
System.out.println(displayName + separator + country + separator + displayCountry
+ separator + iso3CountryCode + separator + language + separator
+ displayLanguage + separator + iso3LanguageCode + separator
+ displayVarient + separator + varient + separator + locale.toString());
}
If you want to see this code’s output, which are the locales supported by my machine, then it’s available on a this page.
No comments:
Post a comment