ICU-6816 Force calendar and number format to respect territory specific data
X-SVN-Rev: 28278
This commit is contained in:
parent
cad18745df
commit
4532bd86f3
@ -4852,8 +4852,8 @@ public class DecimalFormat extends NumberFormat {
|
||||
boolean[] isChoiceFormat = new boolean[1];
|
||||
String s = theCurrency.getName(symbols.getULocale(),
|
||||
Currency.SYMBOL_NAME, isChoiceFormat);
|
||||
symbols.setCurrency(theCurrency);
|
||||
symbols.setCurrencySymbol(s);
|
||||
symbols.setInternationalCurrencySymbol(theCurrency.getCurrencyCode());
|
||||
}
|
||||
|
||||
if (currencySignCount > 0) {
|
||||
|
@ -19,6 +19,7 @@ import com.ibm.icu.impl.ICULocaleService.LocaleKeyFactory;
|
||||
import com.ibm.icu.impl.ICUService.Factory;
|
||||
import com.ibm.icu.impl.ICUService.Key;
|
||||
import com.ibm.icu.text.NumberFormat.NumberFormatFactory;
|
||||
import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
class NumberFormatServiceShim extends NumberFormat.NumberFormatShim {
|
||||
@ -89,6 +90,14 @@ class NumberFormatServiceShim extends NumberFormat.NumberFormatShim {
|
||||
}
|
||||
fmt = (NumberFormat)fmt.clone();
|
||||
|
||||
// If we are creating a currency type formatter, then we may have to set the currency
|
||||
// explicitly, since the actualLoc may be different than the desiredLocale
|
||||
if ( choice == NumberFormat.CURRENCYSTYLE ||
|
||||
choice == NumberFormat.ISOCURRENCYSTYLE ||
|
||||
choice == NumberFormat.PLURALCURRENCYSTYLE) {
|
||||
fmt.setCurrency(Currency.getInstance(desiredLocale));
|
||||
}
|
||||
|
||||
ULocale uloc = actualLoc[0];
|
||||
fmt.setLocale(uloc, uloc); // services make no distinction between actual & valid
|
||||
return fmt;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2009, International Business Machines
|
||||
* Copyright (C) 2007-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*/
|
||||
|
||||
@ -9,6 +9,7 @@ import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.icu.impl.CalendarUtil;
|
||||
import com.ibm.icu.impl.ICULocaleService;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.ICUService;
|
||||
@ -64,7 +65,18 @@ class CalendarServiceShim extends Calendar.CalendarShim {
|
||||
if (desiredLocale.equals(ULocale.ROOT)) {
|
||||
desiredLocale = ULocale.ROOT;
|
||||
}
|
||||
Calendar cal = (Calendar)service.get(desiredLocale, actualLoc);
|
||||
// We need to force the calendar type here, because the actual locale's default
|
||||
// calendar may be different than the requested locale's default calendar.
|
||||
// ( Territory-based data, not language based.
|
||||
ULocale useLocale;
|
||||
if ( desiredLocale.getKeywordValue("calendar") == null) {
|
||||
String calType = CalendarUtil.getCalendarType(desiredLocale);
|
||||
useLocale = desiredLocale.setKeywordValue("calendar", calType);
|
||||
} else {
|
||||
useLocale = desiredLocale;
|
||||
}
|
||||
|
||||
Calendar cal = (Calendar)service.get(useLocale, actualLoc);
|
||||
if (cal == null) {
|
||||
throw new MissingResourceException("Unable to construct Calendar", "", "");
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2000-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2000-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -2088,6 +2088,14 @@ public class CalendarRegression extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln("Year remained " + year2 + " - PASS.");
|
||||
}
|
||||
}
|
||||
public void TestCalendarType6816() {
|
||||
Locale loc = new Locale("en", "TH");
|
||||
Calendar cal = Calendar.getInstance(loc);
|
||||
String calType = cal.getType();
|
||||
if ( !calType.equals("buddhist")) {
|
||||
errln("FAIL: Calendar type for en_TH should still be buddhist");
|
||||
}
|
||||
}
|
||||
|
||||
public void TestGetKeywordValuesForLocale(){
|
||||
|
||||
|
@ -1272,6 +1272,19 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
||||
}
|
||||
|
||||
public void Test6816() {
|
||||
Currency cur1 = Currency.getInstance(new Locale("und", "PH"));
|
||||
|
||||
NumberFormat nfmt = NumberFormat.getCurrencyInstance(new Locale("und", "PH"));
|
||||
DecimalFormatSymbols decsym = ((DecimalFormat)nfmt).getDecimalFormatSymbols();
|
||||
Currency cur2 = decsym.getCurrency();
|
||||
|
||||
if ( !cur1.getCurrencyCode().equals("PHP") || !cur2.getCurrencyCode().equals("PHP")) {
|
||||
errln("FAIL: Currencies should match PHP: cur1 = "+cur1.getCurrencyCode()+"; cur2 = "+cur2.getCurrencyCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void TestThreadedFormat() {
|
||||
|
||||
class FormatTask implements Runnable {
|
||||
|
Loading…
Reference in New Issue
Block a user