How do I display all available locales?
Author: Deron Eriksson
Description: This Java tutorial describes how to display all available locales.
Tutorial created using:
Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)
You can get an array of all the available locales via a call to
Locale locales[] = Locale.getAvailableLocales();
The AvailableLocales class gets an array of available locales, sorts the array by the toString() values of the locales, and then displays the values returned by several of the methods on the Locale objects. It writes the results to a file in an HTMLW table format.
package test;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
public class AvailableLocales {
public static void main(String[] args) throws Exception {
Locale locales[] = Locale.getAvailableLocales();
sortLocalesOnToString(locales);
FileWriter fw = new FileWriter("available-locales.htm");
fw.write("<table border=1 cellpadding=2 cellspacing=0>");
fw.write("<tr><th>toString</th><th>Country</th><th>" + "DisplayCountry</th><th>DisplayLanguage</th><th>"
+ "DisplayName</th><th>DisplayVariant</th><th>" + "ISO3Country</th><th>ISO3Language</th><th>"
+ "Language</th><th>Variant</th></tr>\n");
for (Locale locale : locales) {
fw.write("<tr><td>" + locale.toString() + " </td><td>" + locale.getCountry() + " </td><td>"
+ locale.getDisplayCountry() + " </td><td>" + locale.getDisplayLanguage() + " </td><td>"
+ locale.getDisplayName() + " </td><td>" + locale.getDisplayVariant() + " </td><td>"
+ locale.getISO3Country() + " </td><td>" + locale.getISO3Language() + " </td><td>"
+ locale.getLanguage() + " </td><td>" + locale.getVariant() + " </td></tr>\n");
}
fw.write("</table>");
fw.flush();
fw.close();
}
public static void sortLocalesOnToString(Locale[] locales) {
Comparator<Locale> localeComparator = new Comparator<Locale>() {
public int compare(Locale locale1, Locale locale2) {
return locale1.toString().compareTo(locale2.toString());
}
};
Arrays.sort(locales, localeComparator);
}
}
The generated available-locales.htm file is shown here:
toString | Country | DisplayCountry | DisplayLanguage | DisplayName | DisplayVariant | ISO3Country | ISO3Language | Language | Variant |
ar | | | Arabic | Arabic | | | ara | ar | |
ar_AE | AE | United Arab Emirates | Arabic | Arabic (United Arab Emirates) | | ARE | ara | ar | |
ar_BH | BH | Bahrain | Arabic | Arabic (Bahrain) | | BHR | ara | ar | |
ar_DZ | DZ | Algeria | Arabic | Arabic (Algeria) | | DZA | ara | ar | |
ar_EG | EG | Egypt | Arabic | Arabic (Egypt) | | EGY | ara | ar | |
ar_IQ | IQ | Iraq | Arabic | Arabic (Iraq) | | IRQ | ara | ar | |
ar_JO | JO | Jordan | Arabic | Arabic (Jordan) | | JOR | ara | ar | |
ar_KW | KW | Kuwait | Arabic | Arabic (Kuwait) | | KWT | ara | ar | |
ar_LB | LB | Lebanon | Arabic | Arabic (Lebanon) | | LBN | ara | ar | |
ar_LY | LY | Libya | Arabic | Arabic (Libya) | | LBY | ara | ar | |
ar_MA | MA | Morocco | Arabic | Arabic (Morocco) | | MAR | ara | ar | |
ar_OM | OM | Oman | Arabic | Arabic (Oman) | | OMN | ara | ar | |
ar_QA | QA | Qatar | Arabic | Arabic (Qatar) | | QAT | ara | ar | |
ar_SA | SA | Saudi Arabia | Arabic | Arabic (Saudi Arabia) | | SAU | ara | ar | |
ar_SD | SD | Sudan | Arabic | Arabic (Sudan) | | SDN | ara | ar | |
ar_SY | SY | Syria | Arabic | Arabic (Syria) | | SYR | ara | ar | |
ar_TN | TN | Tunisia | Arabic | Arabic (Tunisia) | | TUN | ara | ar | |
ar_YE | YE | Yemen | Arabic | Arabic (Yemen) | | YEM | ara | ar | |
be | | | Belarusian | Belarusian | | | bel | be | |
be_BY | BY | Belarus | Belarusian | Belarusian (Belarus) | | BLR | bel | be | |
bg | | | Bulgarian | Bulgarian | | | bul | bg | |
bg_BG | BG | Bulgaria | Bulgarian | Bulgarian (Bulgaria) | | BGR | bul | bg | |
ca | | | Catalan | Catalan | | | cat | ca | |
ca_ES | ES | Spain | Catalan | Catalan (Spain) | | ESP | cat | ca | |
cs | | | Czech | Czech | | | ces | cs | |
cs_CZ | CZ | Czech Republic | Czech | Czech (Czech Republic) | | CZE | ces | cs | |
da | | | Danish | Danish | | | dan | da | |
da_DK | DK | Denmark | Danish | Danish (Denmark) | | DNK | dan | da | |
de | | | German | German | | | deu | de | |
de_AT | AT | Austria | German | German (Austria) | | AUT | deu | de | |
de_CH | CH | Switzerland | German | German (Switzerland) | | CHE | deu | de | |
de_DE | DE | Germany | German | German (Germany) | | DEU | deu | de | |
de_LU | LU | Luxembourg | German | German (Luxembourg) | | LUX | deu | de | |
el | | | Greek | Greek | | | ell | el | |
el_GR | GR | Greece | Greek | Greek (Greece) | | GRC | ell | el | |
en | | | English | English | | | eng | en | |
en_AU | AU | Australia | English | English (Australia) | | AUS | eng | en | |
en_CA | CA | Canada | English | English (Canada) | | CAN | eng | en | |
en_GB | GB | United Kingdom | English | English (United Kingdom) | | GBR | eng | en | |
en_IE | IE | Ireland | English | English (Ireland) | | IRL | eng | en | |
en_IN | IN | India | English | English (India) | | IND | eng | en | |
en_NZ | NZ | New Zealand | English | English (New Zealand) | | NZL | eng | en | |
en_US | US | United States | English | English (United States) | | USA | eng | en | |
en_ZA | ZA | South Africa | English | English (South Africa) | | ZAF | eng | en | |
es | | | Spanish | Spanish | | | spa | es | |
es_AR | AR | Argentina | Spanish | Spanish (Argentina) | | ARG | spa | es | |
es_BO | BO | Bolivia | Spanish | Spanish (Bolivia) | | BOL | spa | es | |
es_CL | CL | Chile | Spanish | Spanish (Chile) | | CHL | spa | es | |
es_CO | CO | Colombia | Spanish | Spanish (Colombia) | | COL | spa | es | |
es_CR | CR | Costa Rica | Spanish | Spanish (Costa Rica) | | CRI | spa | es | |
es_DO | DO | Dominican Republic | Spanish | Spanish (Dominican Republic) | | DOM | spa | es | |
es_EC | EC | Ecuador | Spanish | Spanish (Ecuador) | | ECU | spa | es | |
es_ES | ES | Spain | Spanish | Spanish (Spain) | | ESP | spa | es | |
es_GT | GT | Guatemala | Spanish | Spanish (Guatemala) | | GTM | spa | es | |
es_HN | HN | Honduras | Spanish | Spanish (Honduras) | | HND | spa | es | |
es_MX | MX | Mexico | Spanish | Spanish (Mexico) | | MEX | spa | es | |
es_NI | NI | Nicaragua | Spanish | Spanish (Nicaragua) | | NIC | spa | es | |
es_PA | PA | Panama | Spanish | Spanish (Panama) | | PAN | spa | es | |
es_PE | PE | Peru | Spanish | Spanish (Peru) | | PER | spa | es | |
es_PR | PR | Puerto Rico | Spanish | Spanish (Puerto Rico) | | PRI | spa | es | |
es_PY | PY | Paraguay | Spanish | Spanish (Paraguay) | | PRY | spa | es | |
es_SV | SV | El Salvador | Spanish | Spanish (El Salvador) | | SLV | spa | es | |
es_UY | UY | Uruguay | Spanish | Spanish (Uruguay) | | URY | spa | es | |
es_VE | VE | Venezuela | Spanish | Spanish (Venezuela) | | VEN | spa | es | |
et | | | Estonian | Estonian | | | est | et | |
et_EE | EE | Estonia | Estonian | Estonian (Estonia) | | EST | est | et | |
fi | | | Finnish | Finnish | | | fin | fi | |
fi_FI | FI | Finland | Finnish | Finnish (Finland) | | FIN | fin | fi | |
fr | | | French | French | | | fra | fr | |
fr_BE | BE | Belgium | French | French (Belgium) | | BEL | fra | fr | |
fr_CA | CA | Canada | French | French (Canada) | | CAN | fra | fr | |
fr_CH | CH | Switzerland | French | French (Switzerland) | | CHE | fra | fr | |
fr_FR | FR | France | French | French (France) | | FRA | fra | fr | |
fr_LU | LU | Luxembourg | French | French (Luxembourg) | | LUX | fra | fr | |
hi_IN | IN | India | Hindi | Hindi (India) | | IND | hin | hi | |
hr | | | Croatian | Croatian | | | hrv | hr | |
hr_HR | HR | Croatia | Croatian | Croatian (Croatia) | | HRV | hrv | hr | |
hu | | | Hungarian | Hungarian | | | hun | hu | |
hu_HU | HU | Hungary | Hungarian | Hungarian (Hungary) | | HUN | hun | hu | |
is | | | Icelandic | Icelandic | | | isl | is | |
is_IS | IS | Iceland | Icelandic | Icelandic (Iceland) | | ISL | isl | is | |
it | | | Italian | Italian | | | ita | it | |
it_CH | CH | Switzerland | Italian | Italian (Switzerland) | | CHE | ita | it | |
it_IT | IT | Italy | Italian | Italian (Italy) | | ITA | ita | it | |
iw | | | Hebrew | Hebrew | | | heb | iw | |
iw_IL | IL | Israel | Hebrew | Hebrew (Israel) | | ISR | heb | iw | |
ja | | | Japanese | Japanese | | | jpn | ja | |
ja_JP | JP | Japan | Japanese | Japanese (Japan) | | JPN | jpn | ja | |
ko | | | Korean | Korean | | | kor | ko | |
ko_KR | KR | South Korea | Korean | Korean (South Korea) | | KOR | kor | ko | |
lt | | | Lithuanian | Lithuanian | | | lit | lt | |
lt_LT | LT | Lithuania | Lithuanian | Lithuanian (Lithuania) | | LTU | lit | lt | |
lv | | | Latvian | Latvian | | | lav | lv | |
lv_LV | LV | Latvia | Latvian | Latvian (Latvia) | | LVA | lav | lv | |
mk | | | Macedonian | Macedonian | | | mkd | mk | |
mk_MK | MK | Macedonia | Macedonian | Macedonian (Macedonia) | | MKD | mkd | mk | |
nl | | | Dutch | Dutch | | | nld | nl | |
nl_BE | BE | Belgium | Dutch | Dutch (Belgium) | | BEL | nld | nl | |
nl_NL | NL | Netherlands | Dutch | Dutch (Netherlands) | | NLD | nld | nl | |
no | | | Norwegian | Norwegian | | | nor | no | |
no_NO | NO | Norway | Norwegian | Norwegian (Norway) | | NOR | nor | no | |
no_NO_NY | NO | Norway | Norwegian | Norwegian (Norway,Nynorsk) | Nynorsk | NOR | nor | no | NY |
pl | | | Polish | Polish | | | pol | pl | |
pl_PL | PL | Poland | Polish | Polish (Poland) | | POL | pol | pl | |
pt | | | Portuguese | Portuguese | | | por | pt | |
pt_BR | BR | Brazil | Portuguese | Portuguese (Brazil) | | BRA | por | pt | |
pt_PT | PT | Portugal | Portuguese | Portuguese (Portugal) | | PRT | por | pt | |
ro | | | Romanian | Romanian | | | ron | ro | |
ro_RO | RO | Romania | Romanian | Romanian (Romania) | | ROU | ron | ro | |
ru | | | Russian | Russian | | | rus | ru | |
ru_RU | RU | Russia | Russian | Russian (Russia) | | RUS | rus | ru | |
sk | | | Slovak | Slovak | | | slk | sk | |
sk_SK | SK | Slovakia | Slovak | Slovak (Slovakia) | | SVK | slk | sk | |
sl | | | Slovenian | Slovenian | | | slv | sl | |
sl_SI | SI | Slovenia | Slovenian | Slovenian (Slovenia) | | SVN | slv | sl | |
sq | | | Albanian | Albanian | | | sqi | sq | |
sq_AL | AL | Albania | Albanian | Albanian (Albania) | | ALB | sqi | sq | |
sr | | | Serbian | Serbian | | | srp | sr | |
sr_BA | BA | Bosnia and Herzegovina | Serbian | Serbian (Bosnia and Herzegovina) | | BIH | srp | sr | |
sr_CS | CS | Serbia and Montenegro | Serbian | Serbian (Serbia and Montenegro) | | SCG | srp | sr | |
sv | | | Swedish | Swedish | | | swe | sv | |
sv_SE | SE | Sweden | Swedish | Swedish (Sweden) | | SWE | swe | sv | |
th | | | Thai | Thai | | | tha | th | |
th_TH | TH | Thailand | Thai | Thai (Thailand) | | THA | tha | th | |
th_TH_TH | TH | Thailand | Thai | Thai (Thailand,TH) | TH | THA | tha | th | TH |
tr | | | Turkish | Turkish | | | tur | tr | |
tr_TR | TR | Turkey | Turkish | Turkish (Turkey) | | TUR | tur | tr | |
uk | | | Ukrainian | Ukrainian | | | ukr | uk | |
uk_UA | UA | Ukraine | Ukrainian | Ukrainian (Ukraine) | | UKR | ukr | uk | |
vi | | | Vietnamese | Vietnamese | | | vie | vi | |
vi_VN | VN | Vietnam | Vietnamese | Vietnamese (Vietnam) | | VNM | vie | vi | |
zh | | | Chinese | Chinese | | | zho | zh | |
zh_CN | CN | China | Chinese | Chinese (China) | | CHN | zho | zh | |
zh_HK | HK | Hong Kong | Chinese | Chinese (Hong Kong) | | HKG | zho | zh | |
zh_TW | TW | Taiwan | Chinese | Chinese (Taiwan) | | TWN | zho | zh | |
|