ICU-5976 Added some more test cases. Add more configuration options for ICU SPI implementation. Changed the way to populate available locales.
X-SVN-Rev: 24109
This commit is contained in:
parent
e56b3c7948
commit
885290e875
@ -98,7 +98,7 @@
|
||||
<copy file="${jar.file}" todir="${ext.dir}"/>
|
||||
|
||||
<java classname="com.ibm.icu.dev.test.localespi.TestAll" fork="yes" failonerror="true">
|
||||
<jvmarg line="-Djava.ext.dirs=${ext.dir}"/>
|
||||
<jvmarg line="-Djava.ext.dirs=${java.ext.dirs}${path.separator}${ext.dir}"/>
|
||||
<arg value="-n" />
|
||||
<classpath>
|
||||
<pathelement path="${build.dir}" />
|
||||
|
@ -21,8 +21,11 @@ public class BreakIteratorTest extends TestFmwk {
|
||||
private static final int LINE_BRK = 2;
|
||||
private static final int SENTENCE_BRK = 3;
|
||||
|
||||
/*
|
||||
* Check if getInstance returns the ICU implementation.
|
||||
*/
|
||||
public void TestGetInstance() {
|
||||
for (Locale loc : TestUtil.getICULocales()) {
|
||||
for (Locale loc : BreakIterator.getAvailableLocales()) {
|
||||
checkGetInstance(CHARACTER_BRK, loc);
|
||||
checkGetInstance(WORD_BRK, loc);
|
||||
checkGetInstance(LINE_BRK, loc);
|
||||
@ -55,30 +58,42 @@ public class BreakIteratorTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
|
||||
if (TestUtil.isICUOnly(loc)) {
|
||||
if (!(brkitr instanceof com.ibm.icu.impl.jdkadapter.BreakIteratorICU)) {
|
||||
boolean isIcuImpl = (brkitr instanceof com.ibm.icu.impl.jdkadapter.BreakIteratorICU);
|
||||
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: " + method + " returned JDK BreakIterator for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (brkitr instanceof com.ibm.icu.impl.jdkadapter.BreakIteratorICU) {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: " + method + " returned ICU BreakIterator for locale " + loc);
|
||||
} else {
|
||||
}
|
||||
BreakIterator brkitrIcu = null;
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
switch (type) {
|
||||
case CHARACTER_BRK:
|
||||
brkitr = BreakIterator.getCharacterInstance(iculoc);
|
||||
brkitrIcu = BreakIterator.getCharacterInstance(iculoc);
|
||||
break;
|
||||
case WORD_BRK:
|
||||
brkitr = BreakIterator.getWordInstance(iculoc);
|
||||
brkitrIcu = BreakIterator.getWordInstance(iculoc);
|
||||
break;
|
||||
case LINE_BRK:
|
||||
brkitr = BreakIterator.getLineInstance(iculoc);
|
||||
brkitrIcu = BreakIterator.getLineInstance(iculoc);
|
||||
break;
|
||||
case SENTENCE_BRK:
|
||||
brkitr = BreakIterator.getSentenceInstance(iculoc);
|
||||
brkitrIcu = BreakIterator.getSentenceInstance(iculoc);
|
||||
break;
|
||||
}
|
||||
if (!(brkitr instanceof com.ibm.icu.impl.jdkadapter.BreakIteratorICU)) {
|
||||
if (isIcuImpl) {
|
||||
if (!brkitr.equals(brkitrIcu)) {
|
||||
// BreakIterator.getXXXInstance returns a cached BreakIterator instance.
|
||||
// BreakIterator does not override Object#equals, so the result may not be
|
||||
// consistent.
|
||||
// logln("INFO: " + method + " returned ICU BreakIterator for locale " + loc
|
||||
// + ", but different from the one for locale " + iculoc);
|
||||
}
|
||||
} else {
|
||||
if (!(brkitrIcu instanceof com.ibm.icu.impl.jdkadapter.BreakIteratorICU)) {
|
||||
errln("FAIL: " + method + " returned JDK BreakIterator for locale " + iculoc);
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,32 @@ public class CollatorTest extends TestFmwk {
|
||||
new CollatorTest().run(args);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if getInstance returns the ICU implementation.
|
||||
*/
|
||||
public void TestGetInstance() {
|
||||
for (Locale loc : TestUtil.getICULocales()) {
|
||||
for (Locale loc : Collator.getAvailableLocales()) {
|
||||
Collator coll = Collator.getInstance(loc);
|
||||
if (TestUtil.isICUOnly(loc)) {
|
||||
if (!(coll instanceof com.ibm.icu.impl.jdkadapter.CollatorICU)) {
|
||||
|
||||
boolean isIcuImpl = (coll instanceof com.ibm.icu.impl.jdkadapter.CollatorICU);
|
||||
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: getInstance returned JDK Collator for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (coll instanceof com.ibm.icu.impl.jdkadapter.CollatorICU) {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: getInstance returned ICU Collator for locale " + loc);
|
||||
} else {
|
||||
}
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
coll = Collator.getInstance(iculoc);
|
||||
if (!(coll instanceof com.ibm.icu.impl.jdkadapter.CollatorICU)) {
|
||||
Collator collIcu = Collator.getInstance(iculoc);
|
||||
if (isIcuImpl) {
|
||||
if (!coll.equals(collIcu)) {
|
||||
errln("FAIL: getInstance returned ICU Collator for locale " + loc
|
||||
+ ", but different from the one for locale " + iculoc);
|
||||
}
|
||||
} else {
|
||||
if (!(collIcu instanceof com.ibm.icu.impl.jdkadapter.CollatorICU)) {
|
||||
errln("FAIL: getInstance returned JDK Collator for locale " + iculoc);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.localespi;
|
||||
|
||||
import java.util.Currency;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
|
||||
public class CurrencyNameTest extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new CurrencyNameTest().run(args);
|
||||
}
|
||||
|
||||
public void TestCurrencySymbols() {
|
||||
// Make a set of unique currencies
|
||||
HashSet<Currency> currencies = new HashSet<Currency>();
|
||||
for (Locale l : Locale.getAvailableLocales()) {
|
||||
if (l.getCountry().length() == 0) {
|
||||
continue;
|
||||
}
|
||||
Currency currency = Currency.getInstance(l);
|
||||
if (currency == null) {
|
||||
continue;
|
||||
}
|
||||
currencies.add(currency);
|
||||
}
|
||||
|
||||
for (Currency currency : currencies) {
|
||||
String currencyCode = currency.getCurrencyCode();
|
||||
com.ibm.icu.util.Currency currencyIcu = com.ibm.icu.util.Currency.getInstance(currencyCode);
|
||||
if (currencyIcu == null) {
|
||||
logln("INFO: Currency code " + currencyCode + " is not supported by ICU");
|
||||
continue;
|
||||
}
|
||||
for (Locale loc : Locale.getAvailableLocales()) {
|
||||
String curSymbol = currency.getSymbol(loc);
|
||||
String curSymbolIcu = currencyIcu.getSymbol(loc);
|
||||
|
||||
if (curSymbolIcu.equals(currencyCode)) {
|
||||
// No data in ICU
|
||||
if (!curSymbol.equals(currencyCode)) {
|
||||
logln("INFO: JDK has currency symbol " + curSymbol + " for locale " +
|
||||
loc + ", but ICU does not");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!curSymbol.equals(curSymbolIcu)) {
|
||||
if (!curSymbol.equals(curSymbolIcu)) {
|
||||
errln("FAIL: Currency symbol for " + currencyCode + " by ICU is " + curSymbolIcu
|
||||
+ ", but got " + curSymbol + " in locale " + loc);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!curSymbol.equals(curSymbolIcu)) {
|
||||
logln("INFO: Currency symbol for " + currencyCode + " by ICU is " + curSymbolIcu
|
||||
+ ", but " + curSymbol + " by JDK in locale " + loc);
|
||||
}
|
||||
// Try explicit ICU locale (xx_yy_ICU)
|
||||
Locale locIcu = TestUtil.toICUExtendedLocale(loc);
|
||||
curSymbol = currency.getSymbol(locIcu);
|
||||
if (!curSymbol.equals(curSymbolIcu)) {
|
||||
errln("FAIL: Currency symbol for " + currencyCode + " by ICU is " + curSymbolIcu
|
||||
+ ", but got " + curSymbol + " in locale " + locIcu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,24 +16,67 @@ public class DateFormatSymbolsTest extends TestFmwk {
|
||||
new DateFormatSymbolsTest().run(args);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if getInstance returns the ICU implementation.
|
||||
*/
|
||||
public void TestGetInstance() {
|
||||
for (Locale loc : TestUtil.getICULocales()) {
|
||||
for (Locale loc : DateFormatSymbols.getAvailableLocales()) {
|
||||
DateFormatSymbols dfs = DateFormatSymbols.getInstance(loc);
|
||||
if (TestUtil.isICUOnly(loc)) {
|
||||
if (!(dfs instanceof com.ibm.icu.impl.jdkadapter.DateFormatSymbolsICU)) {
|
||||
|
||||
boolean isIcuImpl = (dfs instanceof com.ibm.icu.impl.jdkadapter.DateFormatSymbolsICU);
|
||||
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: getInstance returned JDK DateFormatSymbols for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (dfs instanceof com.ibm.icu.impl.jdkadapter.DateFormatSymbolsICU) {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: getInstance returned ICU DateFormatSymbols for locale " + loc);
|
||||
} else {
|
||||
}
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
dfs = DateFormatSymbols.getInstance(iculoc);
|
||||
if (!(dfs instanceof com.ibm.icu.impl.jdkadapter.DateFormatSymbolsICU)) {
|
||||
DateFormatSymbols dfsIcu = DateFormatSymbols.getInstance(iculoc);
|
||||
if (isIcuImpl) {
|
||||
if (!dfs.equals(dfsIcu)) {
|
||||
errln("FAIL: getInstance returned ICU DateFormatSymbols for locale " + loc
|
||||
+ ", but different from the one for locale " + iculoc);
|
||||
}
|
||||
} else {
|
||||
if (!(dfsIcu instanceof com.ibm.icu.impl.jdkadapter.DateFormatSymbolsICU)) {
|
||||
errln("FAIL: getInstance returned JDK DateFormatSymbols for locale " + iculoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing Nynorsk locales
|
||||
*/
|
||||
public void TestNynorsk() {
|
||||
Locale nnNO = new Locale("nn", "NO");
|
||||
Locale noNONY = new Locale("no", "NO", "NY");
|
||||
|
||||
DateFormatSymbols dfs_nnNO = DateFormatSymbols.getInstance(nnNO);
|
||||
DateFormatSymbols dfs_nnNO_ICU = DateFormatSymbols.getInstance(TestUtil.toICUExtendedLocale(nnNO));
|
||||
DateFormatSymbols dfs_noNONY_ICU = DateFormatSymbols.getInstance(TestUtil.toICUExtendedLocale(noNONY));
|
||||
|
||||
// Weekday names should be identical for these three.
|
||||
// If data is taken from no/nb, then this check will fail.
|
||||
String[] dow_nnNO = dfs_nnNO.getWeekdays();
|
||||
String[] dow_nnNO_ICU = dfs_nnNO_ICU.getWeekdays();
|
||||
String[] dow_noNONY_ICU = dfs_noNONY_ICU.getWeekdays();
|
||||
|
||||
for (int i = 1; i < dow_nnNO.length; i++) {
|
||||
if (!dow_nnNO[i].equals(dow_nnNO_ICU[i])) {
|
||||
errln("FAIL: Different weekday name - index=" + i
|
||||
+ ", nn_NO:" + dow_nnNO[i] + ", nn_NO_ICU:" + dow_nnNO_ICU[i]);
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < dow_nnNO.length; i++) {
|
||||
if (!dow_nnNO[i].equals(dow_noNONY_ICU[i])) {
|
||||
errln("FAIL: Different weekday name - index=" + i
|
||||
+ ", nn_NO:" + dow_nnNO[i] + ", no_NO_NY_ICU:" + dow_nnNO_ICU[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
package com.ibm.icu.dev.test.localespi;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
@ -17,8 +18,11 @@ public class DateFormatTest extends TestFmwk {
|
||||
new DateFormatTest().run(args);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if getInstance returns the ICU implementation.
|
||||
*/
|
||||
public void TestGetInstance() {
|
||||
for (Locale loc : TestUtil.getICULocales()) {
|
||||
for (Locale loc : DateFormat.getAvailableLocales()) {
|
||||
checkGetInstance(DateFormat.FULL, DateFormat.LONG, loc);
|
||||
checkGetInstance(DateFormat.MEDIUM, -1, loc);
|
||||
checkGetInstance(1, DateFormat.SHORT, loc);
|
||||
@ -38,26 +42,59 @@ public class DateFormatTest extends TestFmwk {
|
||||
df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, loc);
|
||||
method = "getDateTimeInstance";
|
||||
}
|
||||
if (TestUtil.isICUOnly(loc)) {
|
||||
if (!(df instanceof com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU)) {
|
||||
|
||||
boolean isIcuImpl = (df instanceof com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU);
|
||||
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: " + method + " returned JDK DateFormat for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (df instanceof com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU) {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: " + method + " returned ICU DateFormat for locale " + loc);
|
||||
} else {
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
if (dstyle < 0) {
|
||||
df = DateFormat.getTimeInstance(DateFormat.SHORT, iculoc);
|
||||
} else if (tstyle < 0) {
|
||||
df = DateFormat.getDateInstance(DateFormat.MEDIUM, iculoc);
|
||||
} else {
|
||||
df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, iculoc);
|
||||
}
|
||||
if (!(df instanceof com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU)) {
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
DateFormat dfIcu;
|
||||
if (dstyle < 0) {
|
||||
dfIcu = DateFormat.getTimeInstance(DateFormat.SHORT, iculoc);
|
||||
} else if (tstyle < 0) {
|
||||
dfIcu = DateFormat.getDateInstance(DateFormat.MEDIUM, iculoc);
|
||||
} else {
|
||||
dfIcu = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, iculoc);
|
||||
}
|
||||
if (isIcuImpl) {
|
||||
if (!df.equals(dfIcu)) {
|
||||
errln("FAIL: " + method + " returned ICU DateFormat for locale " + loc
|
||||
+ ", but different from the one for locale " + iculoc);
|
||||
}
|
||||
} else {
|
||||
if (!(dfIcu instanceof com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU)) {
|
||||
errln("FAIL: " + method + " returned JDK DateFormat for locale " + iculoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if ICU DateFormatProvider uses Thai native digit for Locale
|
||||
* th_TH_TH.
|
||||
*/
|
||||
public void TestThaiDigit() {
|
||||
Locale thTHTH = new Locale("th", "TH", "TH");
|
||||
String pattern = "yyyy-MM-dd";
|
||||
|
||||
DateFormat dfmt = DateFormat.getDateInstance(DateFormat.FULL, thTHTH);
|
||||
DateFormat dfmtIcu = DateFormat.getDateInstance(DateFormat.FULL, TestUtil.toICUExtendedLocale(thTHTH));
|
||||
|
||||
((java.text.SimpleDateFormat)dfmt).applyPattern(pattern);
|
||||
((java.text.SimpleDateFormat)dfmtIcu).applyPattern(pattern);
|
||||
|
||||
Date d = new Date();
|
||||
String str1 = dfmt.format(d);
|
||||
String str2 = dfmtIcu.format(d);
|
||||
|
||||
if (!str1.equals(str2)) {
|
||||
errln("FAIL: ICU DateFormat returned a result different from JDK for th_TH_TH");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,31 +10,43 @@ import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.text.DateFormatSymbols;
|
||||
|
||||
public class DecimalFormatSymbolsTest extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new DecimalFormatSymbolsTest().run(args);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if getInstance returns the ICU implementation.
|
||||
*/
|
||||
public void TestGetInstance() {
|
||||
for (Locale loc : TestUtil.getICULocales()) {
|
||||
for (Locale loc : DateFormatSymbols.getAvailableLocales()) {
|
||||
DecimalFormatSymbols decfs = DecimalFormatSymbols.getInstance(loc);
|
||||
if (TestUtil.isICUOnly(loc)) {
|
||||
if (!(decfs instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatSymbolsICU)) {
|
||||
|
||||
boolean isIcuImpl = (decfs instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatSymbolsICU);
|
||||
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: getInstance returned JDK DecimalFormatSymbols for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (decfs instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatSymbolsICU) {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: getInstance returned ICU DecimalFormatSymbols for locale " + loc);
|
||||
} else {
|
||||
}
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
decfs = DecimalFormatSymbols.getInstance(iculoc);
|
||||
if (!(decfs instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatSymbolsICU)) {
|
||||
DecimalFormatSymbols decfsIcu = DecimalFormatSymbols.getInstance(iculoc);
|
||||
if (isIcuImpl) {
|
||||
if (!decfs.equals(decfsIcu)) {
|
||||
errln("FAIL: getInstance returned ICU DecimalFormatSymbols for locale " + loc
|
||||
+ ", but different from the one for locale " + iculoc);
|
||||
}
|
||||
} else {
|
||||
if (!(decfsIcu instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatSymbolsICU)) {
|
||||
errln("FAIL: getInstance returned JDK DecimalFormatSymbols for locale " + iculoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,166 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.localespi;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class LocaleNameTest extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new LocaleNameTest().run(args);
|
||||
}
|
||||
|
||||
public void TestLanguageNames() {
|
||||
Locale[] locales = Locale.getAvailableLocales();
|
||||
StringBuffer icuid = new StringBuffer();
|
||||
for (Locale inLocale : locales) {
|
||||
ULocale inULocale = ULocale.forLocale(inLocale);
|
||||
Locale inLocaleICU = TestUtil.toICUExtendedLocale(inLocale);
|
||||
for (Locale forLocale : locales) {
|
||||
if (forLocale.getLanguage().length() == 0) {
|
||||
continue;
|
||||
}
|
||||
icuid.setLength(0);
|
||||
icuid.append(forLocale.getLanguage());
|
||||
String country = forLocale.getCountry();
|
||||
String variant = forLocale.getVariant();
|
||||
if (country.length() != 0) {
|
||||
icuid.append("_");
|
||||
icuid.append(country);
|
||||
}
|
||||
if (variant.length() != 0) {
|
||||
if (country.length() == 0) {
|
||||
icuid.append("_");
|
||||
}
|
||||
icuid.append("_");
|
||||
icuid.append(variant);
|
||||
}
|
||||
ULocale forULocale = new ULocale(icuid.toString());
|
||||
String icuname = ULocale.getDisplayLanguage(forULocale.getLanguage(), inULocale);
|
||||
if (icuname.equals(forULocale.getLanguage()) || icuname.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = forLocale.getDisplayLanguage(inLocale);
|
||||
if (TestUtil.isICUExtendedLocale(inLocale)) {
|
||||
// The name should be taken from ICU
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: Language name by ICU is " + icuname + ", but got " + name
|
||||
+ " for locale " + forLocale + " in locale " + inLocale);
|
||||
}
|
||||
} else {
|
||||
if (!name.equals(icuname)) {
|
||||
logln("INFO: Language name by JDK is " + name + ", but " + icuname +
|
||||
" by ICU, for locale " + forLocale + " in locale " + inLocale);
|
||||
}
|
||||
// Try explicit ICU locale (xx_yy_ICU)
|
||||
name = forLocale.getDisplayLanguage(inLocaleICU);
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: Language name by ICU is " + icuname + ", but got " + name
|
||||
+ " for locale " + forLocale + " in locale " + inLocaleICU);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TestCountryNames() {
|
||||
Locale[] locales = Locale.getAvailableLocales();
|
||||
for (Locale inLocale : locales) {
|
||||
ULocale inULocale = ULocale.forLocale(inLocale);
|
||||
Locale inLocaleICU = TestUtil.toICUExtendedLocale(inLocale);
|
||||
for (Locale forLocale : locales) {
|
||||
if (forLocale.getCountry().length() == 0) {
|
||||
continue;
|
||||
}
|
||||
// ULocale#forLocale preserves country always
|
||||
ULocale forULocale = ULocale.forLocale(forLocale);
|
||||
String icuname = ULocale.getDisplayCountry(forULocale.getCountry(), inULocale);
|
||||
if (icuname.equals(forULocale.getCountry()) || icuname.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = forLocale.getDisplayCountry(inLocale);
|
||||
if (TestUtil.isICUExtendedLocale(inLocale)) {
|
||||
// The name should be taken from ICU
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: Country name by ICU is " + icuname + ", but got " + name
|
||||
+ " for locale " + forLocale + " in locale " + inLocale);
|
||||
}
|
||||
} else {
|
||||
// The name might be taken from JDK
|
||||
if (!name.equals(icuname)) {
|
||||
logln("INFO: Country name by JDK is " + name + ", but " + icuname +
|
||||
" in ICU, for locale " + forLocale + " in locale " + inLocale);
|
||||
}
|
||||
// Try explicit ICU locale (xx_yy_ICU)
|
||||
name = forLocale.getDisplayCountry(inLocaleICU);
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: Country name by ICU is " + icuname + ", but got " + name
|
||||
+ " for locale " + forLocale + " in locale " + inLocaleICU);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TestVariantNames() {
|
||||
Locale[] locales = Locale.getAvailableLocales();
|
||||
StringBuffer icuid = new StringBuffer();
|
||||
for (Locale inLocale : locales) {
|
||||
ULocale inULocale = ULocale.forLocale(inLocale);
|
||||
Locale inLocaleICU = TestUtil.toICUExtendedLocale(inLocale);
|
||||
for (Locale forLocale : locales) {
|
||||
if (forLocale.getVariant().length() == 0) {
|
||||
continue;
|
||||
}
|
||||
icuid.setLength(0);
|
||||
icuid.append(forLocale.getLanguage());
|
||||
String country = forLocale.getCountry();
|
||||
String variant = forLocale.getVariant();
|
||||
if (country.length() != 0) {
|
||||
icuid.append("_");
|
||||
icuid.append(country);
|
||||
}
|
||||
if (variant.length() != 0) {
|
||||
if (country.length() == 0) {
|
||||
icuid.append("_");
|
||||
}
|
||||
icuid.append("_");
|
||||
icuid.append(variant);
|
||||
}
|
||||
ULocale forULocale = new ULocale(icuid.toString());
|
||||
String icuname = ULocale.getDisplayVariant(forULocale.getVariant(), inULocale);
|
||||
if (icuname.equals(forULocale.getVariant()) || icuname.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = forLocale.getDisplayVariant(inLocale);
|
||||
if (TestUtil.isICUExtendedLocale(inLocale)) {
|
||||
// The name should be taken from ICU
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: Variant name by ICU is " + icuname + ", but got " + name
|
||||
+ " for locale " + forLocale + " in locale " + inLocale);
|
||||
}
|
||||
} else {
|
||||
if (!name.equals(icuname)) {
|
||||
logln("INFO: Variant name by JDK is " + name + ", but " + icuname +
|
||||
" in ICU, for locale " + forLocale + " in locale " + inLocale);
|
||||
}
|
||||
// Try explicit ICU locale (xx_yy_ICU)
|
||||
name = forLocale.getDisplayVariant(inLocaleICU);
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: Variant name by ICU is " + icuname + ", but got " + name
|
||||
+ " for locale " + forLocale + " in locale " + inLocaleICU);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -22,8 +22,11 @@ public class NumberFormatTest extends TestFmwk {
|
||||
private static final int PERCENT_TYPE = 3;
|
||||
private static final int CURRENCY_TYPE = 4;
|
||||
|
||||
/*
|
||||
* Check if getInstance returns the ICU implementation.
|
||||
*/
|
||||
public void TestGetInstance() {
|
||||
for (Locale loc : TestUtil.getICULocales()) {
|
||||
for (Locale loc : NumberFormat.getAvailableLocales()) {
|
||||
checkGetInstance(DEFAULT_TYPE, loc);
|
||||
checkGetInstance(NUMBER_TYPE, loc);
|
||||
checkGetInstance(INTEGER_TYPE, loc);
|
||||
@ -33,8 +36,8 @@ public class NumberFormatTest extends TestFmwk {
|
||||
}
|
||||
|
||||
private void checkGetInstance(int type, Locale loc) {
|
||||
NumberFormat nf = null;
|
||||
String method = null;
|
||||
NumberFormat nf;
|
||||
String method;
|
||||
|
||||
switch (type) {
|
||||
case DEFAULT_TYPE:
|
||||
@ -62,38 +65,41 @@ public class NumberFormatTest extends TestFmwk {
|
||||
return;
|
||||
}
|
||||
|
||||
if (TestUtil.isICUOnly(loc)) {
|
||||
if (!(nf instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU)) {
|
||||
boolean isIcuImpl = (nf instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU);
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: " + method + " returned JDK NumberFormat for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (nf instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU) {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: " + method + " returned ICU NumberFormat for locale " + loc);
|
||||
} else {
|
||||
}
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
NumberFormat nfIcu = null;
|
||||
switch (type) {
|
||||
case DEFAULT_TYPE:
|
||||
nf = NumberFormat.getInstance(iculoc);
|
||||
method = "getInstance";
|
||||
nfIcu = NumberFormat.getInstance(iculoc);
|
||||
break;
|
||||
case NUMBER_TYPE:
|
||||
nf = NumberFormat.getNumberInstance(iculoc);
|
||||
method = "getNumberInstance";
|
||||
nfIcu = NumberFormat.getNumberInstance(iculoc);
|
||||
break;
|
||||
case INTEGER_TYPE:
|
||||
nf = NumberFormat.getIntegerInstance(iculoc);
|
||||
method = "getIntegerInstance";
|
||||
nfIcu = NumberFormat.getIntegerInstance(iculoc);
|
||||
break;
|
||||
case PERCENT_TYPE:
|
||||
nf = NumberFormat.getPercentInstance(iculoc);
|
||||
method = "getPercentInstance";
|
||||
nfIcu = NumberFormat.getPercentInstance(iculoc);
|
||||
break;
|
||||
case CURRENCY_TYPE:
|
||||
nf = NumberFormat.getCurrencyInstance(iculoc);
|
||||
method = "getCurrencyInstance";
|
||||
nfIcu = NumberFormat.getCurrencyInstance(iculoc);
|
||||
break;
|
||||
}
|
||||
if (!(nf instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU)) {
|
||||
if (isIcuImpl) {
|
||||
if (!nf.equals(nfIcu)) {
|
||||
errln("FAIL: " + method + " returned ICU NumberFormat for locale " + loc
|
||||
+ ", but different from the one for locale " + iculoc);
|
||||
}
|
||||
} else {
|
||||
if (!(nfIcu instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU)) {
|
||||
errln("FAIL: " + method + " returned JDK NumberFormat for locale " + iculoc);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ public class TestAll extends TestGroup {
|
||||
"DateFormatTest",
|
||||
"DecimalFormatSymbolsTest",
|
||||
"NumberFormatTest",
|
||||
"CurrencyNameTest",
|
||||
"LocaleNameTest",
|
||||
"TimeZoneNameTest",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -6,55 +6,13 @@
|
||||
*/
|
||||
package com.ibm.icu.dev.test.localespi;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
|
||||
public class TestUtil {
|
||||
|
||||
private static final Locale[] JDK_LOCALES = Locale.getAvailableLocales();
|
||||
private static final Locale[] ICU_LOCALES = ICUResourceBundle.getAvailableLocales();
|
||||
private static final Locale[] ICU_ONLY_LOCALES;
|
||||
private static final Set<Locale> JDK_LOCALE_SET = new HashSet<Locale>();
|
||||
private static final Set<Locale> ICU_LOCALE_SET = new HashSet<Locale>();
|
||||
private static final Set<Locale> ICU_ONLY_LOCALE_SET = new HashSet<Locale>();
|
||||
|
||||
private static final String ICU_VARIANT = "ICU";
|
||||
private static final String ICU_VARIANT_SUFFIX = "_ICU";
|
||||
|
||||
static {
|
||||
for (Locale jdkloc : JDK_LOCALES) {
|
||||
JDK_LOCALE_SET.add(jdkloc);
|
||||
}
|
||||
|
||||
for (Locale iculoc : ICU_LOCALES) {
|
||||
ICU_LOCALE_SET.add(iculoc);
|
||||
if (!JDK_LOCALE_SET.contains(iculoc)) {
|
||||
ICU_ONLY_LOCALE_SET.add(iculoc);
|
||||
}
|
||||
}
|
||||
ICU_ONLY_LOCALES = ICU_ONLY_LOCALE_SET.toArray(new Locale[0]);
|
||||
}
|
||||
|
||||
public static boolean isICUOnly(Locale locale) {
|
||||
return ICU_ONLY_LOCALE_SET.contains(locale);
|
||||
}
|
||||
|
||||
public static Locale[] getICUOnlyLocales() {
|
||||
return Arrays.copyOf(ICU_ONLY_LOCALES, ICU_ONLY_LOCALES.length);
|
||||
}
|
||||
|
||||
public static Locale[] getJDKLocales() {
|
||||
return Arrays.copyOf(JDK_LOCALES, JDK_LOCALES.length);
|
||||
}
|
||||
|
||||
public static Locale[] getICULocales() {
|
||||
return Arrays.copyOf(ICU_LOCALES, ICU_LOCALES.length);
|
||||
}
|
||||
|
||||
public static Locale toICUExtendedLocale(Locale locale) {
|
||||
if (isICUExtendedLocale(locale)) {
|
||||
return locale;
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.localespi;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class TimeZoneNameTest extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new TimeZoneNameTest().run(args);
|
||||
}
|
||||
|
||||
public void TestTimeZoneNames() {
|
||||
if (skipIfBeforeICU(4,0,0)) {
|
||||
// This test does not work well - likely caused by #6321
|
||||
return;
|
||||
}
|
||||
String[] tzids = TimeZone.getAvailableIDs();
|
||||
for (String tzid : tzids) {
|
||||
TimeZone tz = TimeZone.getTimeZone(tzid);
|
||||
com.ibm.icu.util.TimeZone tzIcu = com.ibm.icu.util.TimeZone.getTimeZone(tzid);
|
||||
for (Locale loc : Locale.getAvailableLocales()) {
|
||||
checkDisplayName(false, TimeZone.SHORT, tz, tzIcu, loc);
|
||||
checkDisplayName(true, TimeZone.SHORT, tz, tzIcu, loc);
|
||||
checkDisplayName(false, TimeZone.LONG, tz, tzIcu, loc);
|
||||
checkDisplayName(true, TimeZone.LONG, tz, tzIcu, loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDisplayName(boolean daylight, int style,
|
||||
TimeZone tz, com.ibm.icu.util.TimeZone icuTz, Locale loc) {
|
||||
ULocale uloc = ULocale.forLocale(loc);
|
||||
boolean shortStyle = (style == TimeZone.SHORT);
|
||||
String icuname = icuTz.getDisplayName(daylight,
|
||||
(shortStyle ? com.ibm.icu.util.TimeZone.SHORT : com.ibm.icu.util.TimeZone.LONG),
|
||||
uloc);
|
||||
|
||||
int numDigits = 0;
|
||||
for (int i = 0; i < icuname.length(); i++) {
|
||||
if (UCharacter.isDigit(icuname.charAt(i))) {
|
||||
numDigits++;
|
||||
}
|
||||
}
|
||||
if (numDigits >= 3) {
|
||||
// ICU does not have the localized name
|
||||
return;
|
||||
}
|
||||
|
||||
String name = tz.getDisplayName(daylight, style, loc);
|
||||
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
// The name should be taken from ICU
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: TimeZone name by ICU is " + icuname + ", but got " + name
|
||||
+ " for time zone " + tz.getID() + " in locale " + loc
|
||||
+ " (daylight=" + daylight + ", style="
|
||||
+ (shortStyle ? "SHORT" : "LONG") + ")");
|
||||
}
|
||||
} else {
|
||||
if (!name.equals(icuname)) {
|
||||
logln("INFO: TimeZone name by ICU is " + icuname + ", but got " + name
|
||||
+ " for time zone " + tz.getID() + " in locale " + loc
|
||||
+ " (daylight=" + daylight + ", style="
|
||||
+ (shortStyle ? "SHORT" : "LONG") + ")");
|
||||
}
|
||||
// Try explicit ICU locale (xx_yy_ICU)
|
||||
Locale icuLoc = TestUtil.toICUExtendedLocale(loc);
|
||||
name = tz.getDisplayName(daylight, style, icuLoc);
|
||||
if (!name.equals(icuname)) {
|
||||
errln("FAIL: TimeZone name by ICU is " + icuname + ", but got " + name
|
||||
+ " for time zone " + tz.getID() + " in locale " + icuLoc
|
||||
+ " (daylight=" + daylight + ", style="
|
||||
+ (shortStyle ? "SHORT" : "LONG") + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,24 +8,38 @@ package com.ibm.icu.impl.javaspi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class ICULocale {
|
||||
private static final String SPI_PROP_FILE = "com/ibm/icu/impl/javaspi/ICUProvider.properties";
|
||||
private static final String SUFFIX_KEY = "com.ibm.icu.impl.javaspi.ICULocale.suffix";
|
||||
private static final String ADD_VARIANTS_KEY = "com.ibm.icu.impl.javaspi.ICULocale.addIcuVariants";
|
||||
private static final String ADD_ISO3_LANG_KEY = "com.ibm.icu.impl.javaspi.ICULocale.addIso3Languages";
|
||||
private static final String SUFFIX_KEY = "com.ibm.icu.impl.javaspi.ICULocale.icuVariantSuffix";
|
||||
|
||||
private static final String DEFAULT_SUFFIX = "ICU";
|
||||
private static final boolean DEFAULT_ADD_VARIANTS = true;
|
||||
private static final boolean DEFAULT_ADD_ISO3_LANG = true;
|
||||
|
||||
private static final Locale[] SPECIAL_LOCALES = {
|
||||
new Locale("ja", "JP", "JP"),
|
||||
new Locale("no"),
|
||||
new Locale("no", "NO"),
|
||||
new Locale("no", "NO", "NY"),
|
||||
new Locale("sr", "CS"),
|
||||
new Locale("th", "TH", "TH"),
|
||||
};
|
||||
|
||||
private static Locale[] LOCALES = null;
|
||||
private static Boolean ADD_VARIANTS = null;
|
||||
private static Boolean ADD_ISO3_LANG = null;
|
||||
private static String SUFFIX = null;
|
||||
|
||||
public static Locale[] getAvailableLocales() {
|
||||
@ -47,25 +61,57 @@ public class ICULocale {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static synchronized Locale[] getLocales() {
|
||||
if (LOCALES == null) {
|
||||
List<Locale> allLocales = new ArrayList<Locale>();
|
||||
private static final Locale THAI_NATIVE_DIGIT_LOCALE = new Locale("th", "TH", "TH");
|
||||
private static final char THAI_NATIVE_ZERO = '\u0E50';
|
||||
private static DecimalFormatSymbols THAI_NATIVE_DECIMAL_SYMBOLS = null;
|
||||
|
||||
Locale[] baseLocales = ICUResourceBundle.getAvailableLocales();
|
||||
for (Locale l : baseLocales) {
|
||||
addLocale(l, allLocales);
|
||||
/*
|
||||
* Returns a DecimalFormatSymbols if the given locale requires
|
||||
* non-standard symbols, more specifically, native digits used
|
||||
* by JDK Locale th_TH_TH. If the locale does not requre a special
|
||||
* symbols, null is returned.
|
||||
*/
|
||||
public static synchronized DecimalFormatSymbols getDecimalFormatSymbolsForLocale(Locale loc) {
|
||||
if (loc.equals(THAI_NATIVE_DIGIT_LOCALE)) {
|
||||
if (THAI_NATIVE_DECIMAL_SYMBOLS == null) {
|
||||
THAI_NATIVE_DECIMAL_SYMBOLS = new DecimalFormatSymbols(new ULocale("th_TH"));
|
||||
THAI_NATIVE_DECIMAL_SYMBOLS.setDigit(THAI_NATIVE_ZERO);
|
||||
}
|
||||
for (Locale l : SPECIAL_LOCALES) {
|
||||
addLocale(l, allLocales);
|
||||
return (DecimalFormatSymbols)THAI_NATIVE_DECIMAL_SYMBOLS.clone();
|
||||
}
|
||||
LOCALES = allLocales.toArray(new Locale[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static synchronized Locale[] getLocales() {
|
||||
if (LOCALES != null) {
|
||||
return LOCALES;
|
||||
}
|
||||
|
||||
private static void addLocale(Locale loc, List<Locale> locales) {
|
||||
Set<Locale> localeSet = new HashSet<Locale>();
|
||||
ULocale[] icuLocales = ICUResourceBundle.getAvailableULocales();
|
||||
|
||||
for (ULocale uloc : icuLocales) {
|
||||
String language = uloc.getLanguage();
|
||||
String country = uloc.getCountry();
|
||||
String variant = uloc.getVariant();
|
||||
if (language.length() >= 3 && !addIso3Languages()) {
|
||||
continue;
|
||||
}
|
||||
addLocale(new Locale(language, country, variant), localeSet);
|
||||
}
|
||||
|
||||
for (Locale l : SPECIAL_LOCALES) {
|
||||
addLocale(l, localeSet);
|
||||
}
|
||||
|
||||
LOCALES = localeSet.toArray(new Locale[0]);
|
||||
return LOCALES;
|
||||
}
|
||||
|
||||
private static void addLocale(Locale loc, Set<Locale> locales) {
|
||||
locales.add(loc);
|
||||
|
||||
if (addIcuVariants()) {
|
||||
// Add ICU variant
|
||||
String language = loc.getLanguage();
|
||||
String country = loc.getCountry();
|
||||
@ -78,21 +124,51 @@ public class ICULocale {
|
||||
var.append(getIcuSuffix());
|
||||
locales.add(new Locale(language, country, var.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean addIso3Languages() {
|
||||
initConfig();
|
||||
return ADD_ISO3_LANG.booleanValue();
|
||||
}
|
||||
|
||||
private static boolean addIcuVariants() {
|
||||
initConfig();
|
||||
return ADD_VARIANTS.booleanValue();
|
||||
}
|
||||
|
||||
private static String getIcuSuffix() {
|
||||
initConfig();
|
||||
return SUFFIX;
|
||||
}
|
||||
|
||||
private static synchronized void initConfig() {
|
||||
if (SUFFIX != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
private static synchronized String getIcuSuffix() {
|
||||
if (SUFFIX == null) {
|
||||
Properties spiConfigProps = new Properties();
|
||||
try {
|
||||
InputStream is = ClassLoader.getSystemResourceAsStream(SPI_PROP_FILE);
|
||||
spiConfigProps.load(is);
|
||||
|
||||
String addVariants = (String)spiConfigProps.get(ADD_VARIANTS_KEY);
|
||||
ADD_VARIANTS = Boolean.parseBoolean(addVariants);
|
||||
|
||||
String addIso3Lang = (String)spiConfigProps.get(ADD_ISO3_LANG_KEY);
|
||||
ADD_ISO3_LANG = Boolean.parseBoolean(addIso3Lang);
|
||||
|
||||
SUFFIX = (String)spiConfigProps.get(SUFFIX_KEY);
|
||||
} catch (IOException ioe) {
|
||||
// Any IO errors, ignore
|
||||
}
|
||||
if (ADD_ISO3_LANG == null) {
|
||||
ADD_ISO3_LANG = Boolean.valueOf(DEFAULT_ADD_VARIANTS);
|
||||
}
|
||||
if (ADD_VARIANTS == null) {
|
||||
ADD_VARIANTS = Boolean.valueOf(DEFAULT_ADD_ISO3_LANG);
|
||||
}
|
||||
if (SUFFIX == null) {
|
||||
SUFFIX = DEFAULT_SUFFIX;
|
||||
}
|
||||
}
|
||||
return SUFFIX;
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,6 @@
|
||||
#* This is the properties is used for configuring ICU locale service provider
|
||||
#* implementation.
|
||||
#*
|
||||
com.ibm.icu.impl.javaspi.ICULocale.suffix=ICU
|
||||
com.ibm.icu.impl.javaspi.ICULocale.addIso3Languages = true
|
||||
com.ibm.icu.impl.javaspi.ICULocale.addIcuVariants = true
|
||||
com.ibm.icu.impl.javaspi.ICULocale.icuVariantSuffix = ICU
|
||||
|
@ -15,41 +15,54 @@ import com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU;
|
||||
|
||||
public class DateFormatProviderICU extends DateFormatProvider {
|
||||
|
||||
private static final int NONE = -1;
|
||||
|
||||
@Override
|
||||
public DateFormat getDateInstance(int style, Locale locale) {
|
||||
com.ibm.icu.text.DateFormat icuDfmt = com.ibm.icu.text.DateFormat.getDateInstance(
|
||||
style, ICULocale.canonicalize(locale));
|
||||
if (!(icuDfmt instanceof com.ibm.icu.text.SimpleDateFormat)) {
|
||||
// icuDfmt must be always SimpleDateFormat
|
||||
return null;
|
||||
}
|
||||
return SimpleDateFormatICU.wrap((com.ibm.icu.text.SimpleDateFormat)icuDfmt);
|
||||
return getInstance(style, NONE, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) {
|
||||
com.ibm.icu.text.DateFormat icuDfmt = com.ibm.icu.text.DateFormat.getDateTimeInstance(
|
||||
dateStyle, timeStyle, ICULocale.canonicalize(locale));
|
||||
if (!(icuDfmt instanceof com.ibm.icu.text.SimpleDateFormat)) {
|
||||
// icuDfmt must be always SimpleDateFormat
|
||||
return null;
|
||||
}
|
||||
return SimpleDateFormatICU.wrap((com.ibm.icu.text.SimpleDateFormat)icuDfmt);
|
||||
return getInstance(dateStyle, timeStyle, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateFormat getTimeInstance(int style, Locale locale) {
|
||||
com.ibm.icu.text.DateFormat icuDfmt = com.ibm.icu.text.DateFormat.getTimeInstance(
|
||||
style, ICULocale.canonicalize(locale));
|
||||
if (!(icuDfmt instanceof com.ibm.icu.text.SimpleDateFormat)) {
|
||||
// icuDfmt must be always SimpleDateFormat
|
||||
return null;
|
||||
}
|
||||
return SimpleDateFormatICU.wrap((com.ibm.icu.text.SimpleDateFormat)icuDfmt);
|
||||
return getInstance(NONE, style, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
}
|
||||
|
||||
private DateFormat getInstance(int dstyle, int tstyle, Locale locale) {
|
||||
com.ibm.icu.text.DateFormat icuDfmt;
|
||||
Locale actual = ICULocale.canonicalize(locale);
|
||||
if (dstyle == NONE) {
|
||||
icuDfmt = com.ibm.icu.text.DateFormat.getTimeInstance(tstyle, actual);
|
||||
} else if (tstyle == NONE) {
|
||||
icuDfmt = com.ibm.icu.text.DateFormat.getDateInstance(dstyle, actual);
|
||||
} else {
|
||||
icuDfmt = com.ibm.icu.text.DateFormat.getDateTimeInstance(dstyle, tstyle, actual);
|
||||
}
|
||||
if (!(icuDfmt instanceof com.ibm.icu.text.SimpleDateFormat)) {
|
||||
// icuDfmt must be always SimpleDateFormat
|
||||
return null;
|
||||
}
|
||||
|
||||
com.ibm.icu.text.DecimalFormatSymbols decfs = ICULocale.getDecimalFormatSymbolsForLocale(actual);
|
||||
if (decfs != null) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt = icuDfmt.getNumberFormat();
|
||||
if (icuNfmt instanceof com.ibm.icu.text.DecimalFormat) {
|
||||
((com.ibm.icu.text.DecimalFormat)icuNfmt).setDecimalFormatSymbols(decfs);
|
||||
} else if (icuNfmt instanceof com.ibm.icu.impl.DateNumberFormat) {
|
||||
((com.ibm.icu.impl.DateNumberFormat)icuNfmt).setZeroDigit(decfs.getDigit());
|
||||
}
|
||||
icuDfmt.setNumberFormat(icuNfmt);
|
||||
}
|
||||
|
||||
return SimpleDateFormatICU.wrap((com.ibm.icu.text.SimpleDateFormat)icuDfmt);
|
||||
}
|
||||
}
|
||||
|
@ -15,48 +15,29 @@ import com.ibm.icu.impl.jdkadapter.DecimalFormatICU;
|
||||
|
||||
public class NumberFormatProviderICU extends NumberFormatProvider {
|
||||
|
||||
private final int NUMBER = 0;
|
||||
private final int INTEGER = 1;
|
||||
private final int CURRENCY = 2;
|
||||
private final int PERCENT = 3;
|
||||
|
||||
@Override
|
||||
public NumberFormat getCurrencyInstance(Locale locale) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt = com.ibm.icu.text.NumberFormat.getCurrencyInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
if (!(icuNfmt instanceof com.ibm.icu.text.DecimalFormat)) {
|
||||
// icuNfmt must be always DecimalFormat
|
||||
return null;
|
||||
}
|
||||
return DecimalFormatICU.wrap((com.ibm.icu.text.DecimalFormat)icuNfmt);
|
||||
return getInstance(CURRENCY, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberFormat getIntegerInstance(Locale locale) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt = com.ibm.icu.text.NumberFormat.getIntegerInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
if (!(icuNfmt instanceof com.ibm.icu.text.DecimalFormat)) {
|
||||
// icuNfmt must be always DecimalFormat
|
||||
return null;
|
||||
}
|
||||
return DecimalFormatICU.wrap((com.ibm.icu.text.DecimalFormat)icuNfmt);
|
||||
return getInstance(INTEGER, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberFormat getNumberInstance(Locale locale) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt = com.ibm.icu.text.NumberFormat.getNumberInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
if (!(icuNfmt instanceof com.ibm.icu.text.DecimalFormat)) {
|
||||
// icuNfmt must be always DecimalFormat
|
||||
return null;
|
||||
}
|
||||
return DecimalFormatICU.wrap((com.ibm.icu.text.DecimalFormat)icuNfmt);
|
||||
return getInstance(NUMBER, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberFormat getPercentInstance(Locale locale) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt = com.ibm.icu.text.NumberFormat.getPercentInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
if (!(icuNfmt instanceof com.ibm.icu.text.DecimalFormat)) {
|
||||
// icuNfmt must be always DecimalFormat
|
||||
return null;
|
||||
}
|
||||
return DecimalFormatICU.wrap((com.ibm.icu.text.DecimalFormat)icuNfmt);
|
||||
return getInstance(PERCENT, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,4 +45,35 @@ public class NumberFormatProviderICU extends NumberFormatProvider {
|
||||
return ICULocale.getAvailableLocales();
|
||||
}
|
||||
|
||||
private NumberFormat getInstance(int type, Locale locale) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt;
|
||||
Locale actual = ICULocale.canonicalize(locale);
|
||||
switch (type) {
|
||||
case NUMBER:
|
||||
icuNfmt = com.ibm.icu.text.NumberFormat.getNumberInstance(actual);
|
||||
break;
|
||||
case INTEGER:
|
||||
icuNfmt = com.ibm.icu.text.NumberFormat.getIntegerInstance(actual);
|
||||
break;
|
||||
case CURRENCY:
|
||||
icuNfmt = com.ibm.icu.text.NumberFormat.getCurrencyInstance(actual);
|
||||
break;
|
||||
case PERCENT:
|
||||
icuNfmt = com.ibm.icu.text.NumberFormat.getPercentInstance(actual);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
if (!(icuNfmt instanceof com.ibm.icu.text.DecimalFormat)) {
|
||||
// icuNfmt must be always DecimalFormat
|
||||
return null;
|
||||
}
|
||||
|
||||
com.ibm.icu.text.DecimalFormatSymbols decfs = ICULocale.getDecimalFormatSymbolsForLocale(actual);
|
||||
if (decfs != null) {
|
||||
((com.ibm.icu.text.DecimalFormat)icuNfmt).setDecimalFormatSymbols(decfs);
|
||||
}
|
||||
|
||||
return DecimalFormatICU.wrap((com.ibm.icu.text.DecimalFormat)icuNfmt);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class LocaleNameProviderICU extends LocaleNameProvider {
|
||||
|
||||
@Override
|
||||
public String getDisplayLanguage(String languageCode, Locale locale) {
|
||||
String disp = ULocale.getDisplayCountry(languageCode, ULocale.forLocale(ICULocale.canonicalize(locale)));
|
||||
String disp = ULocale.getDisplayLanguage(languageCode, ULocale.forLocale(ICULocale.canonicalize(locale)));
|
||||
if (disp.length() == 0 || disp.equals(languageCode)) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user