Folks working on localization, often ends up in situations they need to see a list of what the Locale specific information looks like in Java. They need a sample of each locale and not just a simple list of supported locales.
Here's a simple implementation (+/-) thrown together after googling the basics of the Java API, that renders a table which has samples of localized in each and every locale supported by Java.
Often with such code, the printout on the java console in eclipse works fine but the populated dates, numbers and currencies in different languages, cannot be seen in the browser. I ripped of the Unicode escaping code after some googling to fix this issue. I don’t know how great the algorithm is but it does the job as far as I can tell.
Another unique feature of the generated table is that XXX is thrown in as a placeholder where ever the row represents a language and not a region so it does not have a currency associated with it.
Here's a simple implementation (+/-) thrown together after googling the basics of the Java API, that renders a table which has samples of localized in each and every locale supported by Java.
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Date;
import java.util.Locale;
public class CurrencyFormatterExample {
private static PrintWriter pw;
public static void format(Locale currentLocale) {
Double price = new Double(1234.56);
NumberFormat currencyFormatter;
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.MEDIUM, currentLocale);
String currencyOut;
currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
currencyOut = currencyFormatter.format(price);
Currency currency = currencyFormatter.getCurrency();
String dateFormat = df.format(new Date());
pw.print("<tr><td>" + currentLocale.toString() + "</td>" +
"<td>" + currencyOut + "</td>" +
"<td>" + currency.getCurrencyCode() + "</td>" +
"<td>" + currency.getSymbol(currentLocale) + "</td>" +
"<td>" + unicodeEscape(currency.getSymbol(currentLocale)) + "</td>" +
"<td>" + dateFormat + "</td></tr>");
System.out.println(currentLocale.toString() + "\t\t" + currencyOut + "\t\t" + dateFormat);
}
public static void main(String args[]) throws UnsupportedEncodingException {
try {
pw = new PrintWriter("format.html", "UTF-8");
pw.print("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head>");
pw.print("<body><table>");
pw.print("<tr><th>LOCALE</th>" +
"<th>FORMATTED PRICE</th>" +
"<th>CURRENCY CODE</th>" +
"<th>CURRENCY SYMBOL</th>" +
"<th>UNICODE ESCAPED CURRENCY SYMBOL</th>" +
"<th>FORMATTED DATE</th></tr>");
Locale[] locales = Locale.getAvailableLocales();
for (int i = 0; i < locales.length; i++) {
CurrencyFormatterExample.format(locales[i]);
}
pw.print("</table></body></html?");
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private static final char[] hexChar = {
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
};
private static String unicodeEscape(String s) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if ((c >> 7) > 0) {
sb.append("\\u");
sb.append(hexChar[(c >> 12) & 0xF]);
sb.append(hexChar[(c >> 8) & 0xF]);
sb.append(hexChar[(c >> 4) & 0xF]);
sb.append(hexChar[c & 0xF]);
}
else {
sb.append(c);
}
}
return sb.toString();
}
}
Often with such code, the printout on the java console in eclipse works fine but the populated dates, numbers and currencies in different languages, cannot be seen in the browser. I ripped of the Unicode escaping code after some googling to fix this issue. I don’t know how great the algorithm is but it does the job as far as I can tell.
Another unique feature of the generated table is that XXX is thrown in as a placeholder where ever the row represents a language and not a region so it does not have a currency associated with it.
LOCALE | FORMATTED PRICE | CURRENCY CODE | CURRENCY SYMBOL | UNICODE ESCAPED CURRENCY SYMBOL | FORMATTED DATE |
---|---|---|---|---|---|
ja_JP | ¥1,235 | JPY | ¥ | \uFFE5 | 2010/10/22 10:53:17 |
es_PE | S/1.234,56 | PEN | S/ | S/ | 22 de octubre de 2010 10:53:17 AM |
en | ¤1,234.56 | XXX | XXX | XXX | October 22, 2010 10:53:17 AM |
ja_JP_JP | ¥1,235 | JPY | ¥ | \uFFE5 | H22.10.22 10:53:17 |
es_PA | B1,234.56 | PAB | B | B | 22 de octubre de 2010 10:53:17 AM |
sr_BA | КМ. 1.234,56 | BAM | КМ. | \u041A\u041C. | 22. октобар 2010. 10:53:17 |
mk | ¤ 1.234,56 | XXX | XXX | XXX | 22, октомври 2010 10:53: |
es_GT | Q1,234.56 | GTQ | Q | Q | 22 de octubre de 2010 10:53:17 AM |
ar_AE | د.إ. 1,234.56 | AED | د.إ. | \u062F.\u0625.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
no_NO | kr 1 234,56 | NOK | kr | kr | 22. oktober 2010 10:53:17 |
sq_AL | Lek1.234,56 | ALL | Lek | Lek | 2010-10-22 10:53:17.PD |
bg | ¤ 1 234,56 | XXX | XXX | XXX | Петък, 2010, Октомври 22 10:53:17 |
ar_IQ | د.ع. 1,234.56 | IQD | د.ع. | \u062F.\u0639.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
ar_YE | ر.ي. 1,234.56 | YER | ر.ي. | \u0631.\u064A.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
hu | ¤ 1 234,56 | XXX | XXX | XXX | 2010. október 22. 10:53:17 |
pt_PT | 1.234,56 € | EUR | € | \u20AC | 22 de Outubro de 2010 10:53:17 |
el_CY | €1.234,56 | EUR | € | \u20AC | 22 Οκτώβριος 2010 10:53:17 ΠΜ |
ar_QA | ر.ق. 1,234.56 | QAR | ر.ق. | \u0631.\u0642.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
mk_MK | Den 1.234,56 | MKD | Den | Den | 22, октомври 2010 10:53: |
sv | ¤ 1 234,56 | XXX | XXX | XXX | den 22 oktober 2010 10:53:17 |
de_CH | SFr. 1'234.56 | CHF | SFr. | SFr. | 22. Oktober 2010 10:53:17 |
en_US | $1,234.56 | USD | $ | $ | October 22, 2010 10:53:17 AM |
fi_FI | 1 234,56 € | EUR | € | \u20AC | 22. lokakuuta 2010 10:53:17 |
is | ¤ 1.234,56 | XXX | XXX | XXX | 22. október 2010 10:53:17 |
cs | ¤ 1 234,56 | XXX | XXX | XXX | 22. říjen 2010 10:53:17 |
en_MT | €1,234.56 | EUR | € | \u20AC | 22 October 2010 10:53:17 |
sl_SI | € 1.234,56 | EUR | € | \u20AC | Petek, 22 oktober 2010 10:53:17 |
sk_SK | 1 234,56 Sk | SKK | Sk | Sk | Piatok, 2010, október 22 10:53:17 |
it | ¤ 1.234,56 | XXX | XXX | XXX | 22 ottobre 2010 10.53.17 |
tr_TR | 1.234,56 YTL | TRY | YTL | YTL | 22 Ekim 2010 Cuma 10:53:17 |
zh | ¤ 1,234.56 | XXX | XXX | XXX | 2010年10月22日 10:53:17 |
th | ¤ 1,234.56 | XXX | XXX | XXX | 22 ตุลาคม 2010, 10:53:17 |
ar_SA | ر.س. 1,234.56 | SAR | ر.س. | \u0631.\u0633.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
no | ¤ 1 234,56 | XXX | XXX | XXX | 22. oktober 2010 10:53:17 |
en_GB | £1,234.56 | GBP | £ | \u00A3 | 22 October 2010 10:53:17 |
sr_CS | CSD 1.234,56 | CSD | CSD | CSD | 22.10.2010. 10.53.17 |
lt | ¤ 1 234,56 | XXX | XXX | XXX | Penktadienis, 2010, Spalio 22 10.53.17 |
ro | ¤ 1.234,56 | XXX | XXX | XXX | 22 octombrie 2010 10:53:17 |
en_NZ | $1,234.56 | NZD | $ | $ | 22 October 2010 10:53:17 AM |
no_NO_NY | kr 1 234,56 | NOK | kr | kr | 22. oktober 2010 10:53:17 |
lt_LT | 1 234,56 Lt | LTL | Lt | Lt | Penktadienis, 2010, Spalio 22 10.53.17 |
es_NI | $C1,234.56 | NIO | $C | $C | 22 de octubre de 2010 10:53:17 AM |
nl | ¤ 1.234,56 | XXX | XXX | XXX | 22 oktober 2010 10:53:17 |
ga_IE | €1,234.56 | EUR | € | \u20AC | 22 Deireadh Fómhair 2010 10:53:17 |
fr_BE | 1.234,56 € | EUR | € | \u20AC | 22 octobre 2010 10:53:17 |
es_ES | 1.234,56 € | EUR | € | \u20AC | 22 de octubre de 2010 10:53:17 |
ar_LB | ل.ل. 1,234.56 | LBP | ل.ل. | \u0644.\u0644.\u200F | 22 تشرين الأول, 2010 10:53:17 ص |
ko | ¤ 1,234.56 | XXX | XXX | XXX | 2010년 10월 22일 (금) 오전 10:53:17 |
fr_CA | 1 234,56 $ | CAD | $ | $ | 22 octobre 2010 10:53:17 |
et_EE | 1 234,56 kr | EEK | kr | kr | reede, 22. Oktoober 2010. a 10:53:17 |
ar_KW | د.ك. 1,234.56 | KWD | د.ك. | \u062F.\u0643.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
sr_RS | RSD 1.234,56 | RSD | RSD | RSD | 22.10.2010. 10.53.17 |
es_US | US$1,234.56 | USD | US$ | US$ | 22 de octubre de 2010 10:53:17 a.m. |
es_MX | $1,234.56 | MXN | $ | $ | 22 de octubre de 2010 10:53:17 AM |
ar_SD | ج.س. 1,234.56 | SDG | ج.س. | \u062C.\u0633.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
in_ID | Rp1.234,56 | IDR | Rp | Rp | 22 Oktober 2010 10:53:17 |
ru | ¤ 1 234,56 | XXX | XXX | XXX | 22 Октябрь 2010 г. 10:53:17 |
lv | ¤ 1 234,56 | XXX | XXX | XXX | piektdiena, 2010, 22 oktobris 10:53:17 |
es_UY | NU$ 1.234,56 | UYU | NU$ | NU$ | 22 de octubre de 2010 10:53:17 AM |
lv_LV | 1 234,56 Ls | LVL | Ls | Ls | piektdiena, 2010, 22 oktobris 10:53:17 |
iw | ¤ 1,234.56 | XXX | XXX | XXX | 10:53:17 22 אוקטובר 2010 |
pt_BR | R$ 1.234,56 | BRL | R$ | R$ | 22 de Outubro de 2010 10:53:17 |
ar_SY | ل.س. 1,234.56 | SYP | ل.س. | \u0644.\u0633.\u200F | 22 تشرين الأول, 2010 10:53:17 ص |
hr | ¤ 1.234,56 | XXX | XXX | XXX | 2010. listopad 22 10:53:17 |
et | ¤ 1 234,56 | XXX | XXX | XXX | reede, 22. Oktoober 2010. a 10:53:17 |
es_DO | RD$1,234.56 | DOP | RD$ | RD$ | 22 de octubre de 2010 10:53:17 AM |
fr_CH | SFr. 1'234.56 | CHF | SFr. | SFr. | 22. octobre 2010 10:53:17 |
hi_IN | रू १,२३४.५६ | INR | रू | \u0930\u0942 | २२ अक्तूबर, २०१० १०:५३:१७ पूर्वाह्न |
es_VE | BsF.1.234,56 | VEF | BsF. | BsF. | 22 de octubre de 2010 10:53:17 AM |
ar_BH | د.ب. 1,234.56 | BHD | د.ب. | \u062F.\u0628.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
en_PH | Php1,234.56 | PHP | Php | Php | October 22, 2010 10:53:17 AM |
ar_TN | د.ت. 1,234.56 | TND | د.ت. | \u062F.\u062A.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
fi | ¤ 1 234,56 | XXX | XXX | XXX | 22. lokakuuta 2010 10:53:17 |
de_AT | € 1.234,56 | EUR | € | \u20AC | 22. Oktober 2010 10:53:17 |
es | ¤1.234,56 | XXX | XXX | XXX | 22 de octubre de 2010 10:53:17 |
nl_NL | € 1.234,56 | EUR | € | \u20AC | 22 oktober 2010 10:53:17 |
es_EC | $1.234,56 | USD | $ | $ | 22 de octubre de 2010 10:53:17 AM |
zh_TW | NT$1,234.56 | TWD | NT$ | NT$ | 2010年10月22日 上午 10:53:17 |
ar_JO | د.أ. 1,234.56 | JOD | د.أ. | \u062F.\u0623.\u200F | 22 تشرين الأول, 2010 10:53:17 ص |
be | ¤ 1 234,56 | XXX | XXX | XXX | пятніца, 22, кастрычніка 2010 10.53.17 |
is_IS | 1.235, kr. | ISK | kr. | kr. | 22. október 2010 10:53:17 |
es_CO | $1.234,56 | COP | $ | $ | 22 de octubre de 2010 10:53:17 AM |
es_CR | C1,234.56 | CRC | C | C | 22 de octubre de 2010 10:53:17 AM |
es_CL | Ch$1.235 | CLP | Ch$ | Ch$ | 22 de octubre de 2010 10:53:17 AM |
ar_EG | ج.م. 1,234.56 | EGP | ج.م. | \u062C.\u0645.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
en_ZA | R 1,234.56 | ZAR | R | R | 22 October 2010 10:53:17 AM |
th_TH | ฿1,234.56 | THB | ฿ | \u0E3F | 22 ตุลาคม 2553, 10:53:17 |
el_GR | 1.234,56 € | EUR | € | \u20AC | 22 Οκτώβριος 2010 10:53:17 πμ |
it_IT | € 1.234,56 | EUR | € | \u20AC | 22 ottobre 2010 10.53.17 |
ca | ¤ 1.234,56 | XXX | XXX | XXX | 22 / octubre / 2010 10:53:17 |
hu_HU | 1 234,56 Ft | HUF | Ft | Ft | 2010. október 22. 10:53:17 |
fr | 1 234,56 ¤ | XXX | XXX | XXX | 22 octobre 2010 10:53:17 |
en_IE | €1,234.56 | EUR | € | \u20AC | 22 October 2010 10:53:17 |
uk_UA | 1.234,56 грв. | UAH | грв. | \u0433\u0440\u0432. | 22 жовтня 2010 10:53:17 |
pl_PL | 1 234,56 zł | PLN | zł | z\u0142 | 22 październik 2010 10:53:17 |
fr_LU | 1 234,56 € | EUR | € | \u20AC | 22 octobre 2010 10:53:17 |
nl_BE | 1.234,56 € | EUR | € | \u20AC | 22 oktober 2010 10:53:17 |
en_IN | Rs.1,234.56 | INR | Rs. | Rs. | 22 October, 2010 10:53:17 AM |
ca_ES | € 1.234,56 | EUR | € | \u20AC | 22 / octubre / 2010 10:53:17 |
ar_MA | د.م. 1,234.56 | MAD | د.م. | \u062F.\u0645.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
es_BO | B$1.234,56 | BOB | B$ | B$ | 22 de octubre de 2010 10:53:17 AM |
en_AU | $1,234.56 | AUD | $ | $ | 22 October 2010 10:53:17 AM |
sr | ¤ 1.234,56 | XXX | XXX | XXX | 22.10.2010. 10.53.17 |
zh_SG | S$1,234.56 | SGD | S$ | S$ | 22 十月 2010 上午 10:53 |
pt | ¤ 1.234,56 | XXX | XXX | XXX | 22 de Outubro de 2010 10:53:17 |
uk | ¤ 1.234,56 | XXX | XXX | XXX | 22 жовтня 2010 10:53:17 |
es_SV | C1,234.56 | SVC | C | C | 22 de octubre de 2010 10:53:17 AM |
ru_RU | 1 234,56 руб. | RUB | руб. | \u0440\u0443\u0431. | 22 Октябрь 2010 г. 10:53:17 |
ko_KR | ₩1,235 | KRW | ₩ | \uFFE6 | 2010년 10월 22일 (금) 오전 10:53:17 |
vi | ¤ 1.234,56 | XXX | XXX | XXX | 10:53:17 Ngày 22 tháng 10 năm 2010 |
ar_DZ | د.ج. 1,234.56 | DZD | د.ج. | \u062F.\u062C.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
vi_VN | 1.234,56 đ | VND | đ | \u0111 | 10:53:17 Ngày 22 tháng 10 năm 2010 |
sr_ME | € 1.234,56 | EUR | € | \u20AC | 22.10.2010. 10.53.17 |
sq | ¤ 1.234,56 | XXX | XXX | XXX | 2010-10-22 10:53:17.PD |
ar_LY | د.ل. 1,234.56 | LYD | د.ل. | \u062F.\u0644.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
ar | ¤ 1,234.56 | XXX | XXX | XXX | 22 أكتوبر, 2010 10:53:17 ص |
zh_CN | ¥1,234.56 | CNY | ¥ | \uFFE5 | 2010年10月22日 10:53:17 |
be_BY | Руб1 235 | BYR | Руб | \u0420\u0443\u0431 | пятніца, 22, кастрычніка 2010 10.53.17 |
zh_HK | HK$1,234.56 | HKD | HK$ | HK$ | 2010年10月22日 星期五 上午10:53:17 |
ja | ¤ 1,234.56 | XXX | XXX | XXX | 2010/10/22 10:53:17 |
iw_IL | 1,234.56 ש"ח | ILS | ש"ח | \u05E9"\u05D7 | 10:53:17 22 אוקטובר 2010 |
bg_BG | лв.1 234,56 | BGN | лв. | \u043B\u0432. | Петък, 2010, Октомври 22 10:53:17 |
in | ¤1.234,56 | XXX | XXX | XXX | 2010 Oktober 22 10:53:17 |
mt_MT | €1,234.56 | EUR | € | \u20AC | 22 ta’ Ottubru 2010 10:53:17 |
es_PY | G1.235 | PYG | G | G | 22 de octubre de 2010 10:53:17 AM |
sl | ¤ 1.234,56 | XXX | XXX | XXX | Petek, 22 oktober 2010 10:53:17 |
fr_FR | 1 234,56 € | EUR | € | \u20AC | 22 octobre 2010 10:53:17 |
cs_CZ | 1 234,56 Kč | CZK | Kč | K\u010D | 22. říjen 2010 10:53:17 |
it_CH | SFr. 1'234.56 | CHF | SFr. | SFr. | 22. ottobre 2010 10:53:17 |
ro_RO | 1.234,56 LEI | RON | LEI | LEI | 22 octombrie 2010 10:53:17 |
es_PR | $1,234.56 | USD | $ | $ | 22 de octubre de 2010 10:53:17 AM |
en_CA | $1,234.56 | CAD | $ | $ | October 22, 2010 10:53:17 AM |
de_DE | 1.234,56 € | EUR | € | \u20AC | 22. Oktober 2010 10:53:17 |
ga | ¤ 1,234.56 | XXX | XXX | XXX | 2010 Deireadh Fómhair 22 10:53:17 |
de_LU | 1.234,56 € | EUR | € | \u20AC | 22. Oktober 2010 10:53:17 |
de | ¤ 1.234,56 | XXX | XXX | XXX | 22. Oktober 2010 10:53:17 |
es_AR | $1.234,56 | ARS | $ | $ | 22 de octubre de 2010 10:53:17 |
sk | ¤ 1 234,56 | XXX | XXX | XXX | Piatok, 2010, október 22 10:53:17 |
ms_MY | RM1,234.56 | MYR | RM | RM | 22 Oktober 2010 10:53:17 AM |
hr_HR | Kn 1.234,56 | HRK | Kn | Kn | 2010. listopad 22 10:53:17 |
en_SG | $1,234.56 | SGD | $ | $ | October 22, 2010 10:53:17 AM |
da | ¤ 1.234,56 | XXX | XXX | XXX | 22. oktober 2010 10:53:17 |
mt | ¤ 1,234.56 | XXX | XXX | XXX | 22 ta’ Ottubru 2010 10:53:17 |
pl | ¤ 1 234,56 | XXX | XXX | XXX | 22 październik 2010 10:53:17 |
ar_OM | ر.ع. 1,234.56 | OMR | ر.ع. | \u0631.\u0639.\u200F | 22 أكتوبر, 2010 10:53:17 ص |
tr | 1.234,56 ¤ | XXX | XXX | XXX | 22 Ekim 2010 Cuma 10:53:17 |
th_TH_TH | ฿๑,๒๓๔.๕๖ | THB | ฿ | \u0E3F | ๒๒ ตุลาคม ๒๕๕๓, ๑๐:๕๓:๑๗ |
el | ¤ 1.234,56 | XXX | XXX | XXX | 22 Οκτώβριος 2010 10:53:17 πμ |
ms | ¤ 1,234.56 | XXX | XXX | XXX | 2010 Oktober 22 10:53:17 |
sv_SE | 1 234,56 kr | SEK | kr | kr | den 22 oktober 2010 10:53:17 |
da_DK | kr 1.234,56 | DKK | kr | kr | 22. oktober 2010 10:53:17 |
es_HN | L1,234.56 | HNL | L | L | 22 de octubre de 2010 10:53:17 AM |
0 comments:
Post a Comment