ICU-5952 Deprecated YU maps to RS in CLDR. ICU4C doesn't do deprecated code remapping. The next update of CLDR includes the history of deprecated region codes.
X-SVN-Rev: 22860
This commit is contained in:
parent
313bc1e982
commit
2acc63bddc
@ -167,27 +167,27 @@ public class CurrencyTest extends TestFmwk {
|
||||
}
|
||||
|
||||
public void TestCurrencyKeyword() {
|
||||
ULocale locale = new ULocale("th_TH@collation=traditional;currency=QQQ");
|
||||
Currency currency = Currency.getInstance(locale);
|
||||
String result = currency.getCurrencyCode();
|
||||
if (!"QQQ".equals(result)) {
|
||||
errln("got unexpected currency: " + result);
|
||||
}
|
||||
ULocale locale = new ULocale("th_TH@collation=traditional;currency=QQQ");
|
||||
Currency currency = Currency.getInstance(locale);
|
||||
String result = currency.getCurrencyCode();
|
||||
if (!"QQQ".equals(result)) {
|
||||
errln("got unexpected currency: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
public void TestDeprecatedCurrencyFormat() {
|
||||
// bug 5952
|
||||
Locale locale = new Locale("sr", "YU");
|
||||
Locale locale = new Locale("sr", "QQ");
|
||||
DecimalFormatSymbols icuSymbols = new
|
||||
com.ibm.icu.text.DecimalFormatSymbols(locale);
|
||||
String symbol = icuSymbols.getCurrencySymbol();
|
||||
Currency currency = icuSymbols.getCurrency();
|
||||
String expectCur = "EUR";
|
||||
String expectSym = "\u20AC";
|
||||
if(!symbol.equals(expectSym) || !currency.toString().equals(expectCur)) {
|
||||
errln("for " + locale + " expected " + expectSym+"/"+expectCur + " but got " + symbol+"/"+currency.toString());
|
||||
String expectCur = null;
|
||||
String expectSym = "\u00A4";
|
||||
if(!symbol.toString().equals(expectSym) || currency != null) {
|
||||
errln("for " + locale + " expected " + expectSym+"/"+expectCur + " but got " + symbol+"/"+currency);
|
||||
} else {
|
||||
logln("for " + locale + " expected " + expectSym+"/"+expectCur + " and got " + symbol+"/"+currency.toString());
|
||||
logln("for " + locale + " expected " + expectSym+"/"+expectCur + " and got " + symbol+"/"+currency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,21 +124,22 @@ public class Currency extends MeasureUnit implements Serializable {
|
||||
* Instantiate a currency from a resource bundle found in Locale loc.
|
||||
*/
|
||||
/* package */ static Currency createCurrency(ULocale loc) {
|
||||
// TODO: check, this munging might not be required for ULocale
|
||||
String country = loc.getCountry();
|
||||
String variant = loc.getVariant();
|
||||
boolean isPreEuro = variant.equals("PREEURO");
|
||||
boolean isEuro = variant.equals("EURO");
|
||||
// TODO: ICU4C has service registration, and the currency is requested from the service here.
|
||||
ICUResourceBundle bundle = (ICUResourceBundle) ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"supplementalData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
if(bundle==null){
|
||||
//throw new MissingResourceException()
|
||||
return null;
|
||||
}
|
||||
UResourceBundle cm = bundle.get("CurrencyMap");
|
||||
|
||||
// Do a linear search
|
||||
String curriso = null;
|
||||
try {
|
||||
UResourceBundle cm = bundle.get("CurrencyMap");
|
||||
String curriso = null;
|
||||
UResourceBundle countryArray = cm.get(country);
|
||||
// Some regions can have more than one current currency in use.
|
||||
// The latest default currency is always the first one.
|
||||
UResourceBundle currencyReq = countryArray.get(0);
|
||||
curriso = currencyReq.getString("id");
|
||||
if (isPreEuro && curriso.equals(EUR_STR)) {
|
||||
@ -152,55 +153,13 @@ public class Currency extends MeasureUnit implements Serializable {
|
||||
return new Currency(curriso);
|
||||
}
|
||||
} catch (MissingResourceException ex) {
|
||||
try{
|
||||
if (isPreEuro || isEuro) {
|
||||
country = country + '_' + variant;
|
||||
}
|
||||
// a deprecated ISO code may have been passed
|
||||
// try to get the current country code
|
||||
String rep = ULocale.getCurrentCountryID(country);
|
||||
if(DEBUG) System.out.println("DEBUG: oldID: "+country +" newID:" +rep);
|
||||
// here pointer comparison is valid since getCurrentCountryID
|
||||
// will return the input string if there is no replacement
|
||||
if(rep != country){
|
||||
UResourceBundle countryArray = cm.get(rep);
|
||||
UResourceBundle currencyReq = countryArray.get(0);
|
||||
curriso = currencyReq.getString("id");
|
||||
if (isPreEuro && curriso.equals(EUR_STR)) {
|
||||
currencyReq = countryArray.get(1);
|
||||
curriso = currencyReq.getString("id");
|
||||
}
|
||||
else if (isEuro) {
|
||||
curriso = EUR_STR;
|
||||
}
|
||||
if (curriso != null) {
|
||||
return new Currency(curriso);
|
||||
}
|
||||
}
|
||||
}catch(MissingResourceException e){
|
||||
//do nothing
|
||||
}
|
||||
// We don't know about this region.
|
||||
// As of CLDR 1.5.1, the data includes deprecated region history too.
|
||||
// So if we get here, either the region doesn't exist, or the data is really bad.
|
||||
// Deprecated regions should return the last valid currency for that region in the data.
|
||||
// We don't try to resolve it to a new region.
|
||||
}
|
||||
return null;
|
||||
/*
|
||||
for (int i=0; i<cm.length; ++i) {
|
||||
if (country.equals((String) cm[i][0])) {
|
||||
curriso = (String) cm[i][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Currency curr = null;
|
||||
if (curriso != null) {
|
||||
|
||||
curr = new Currency(curriso);
|
||||
|
||||
// TODO: Determine valid and actual locale correctly.
|
||||
ULocale uloc = bundle.getULocale();
|
||||
curr.setLocale(uloc, uloc);
|
||||
}
|
||||
return curr;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -538,7 +538,7 @@ public final class ULocale implements Serializable {
|
||||
};
|
||||
String[] tempReplacementCountries = {
|
||||
/* "BU", "DY", "FX", "HV", "NH", "RH", "TP", "YU", "ZR" */
|
||||
"MM", "BJ", "FR", "BF", "VU", "ZW", "TL", "CS", "CD", /* replacement country codes */
|
||||
"MM", "BJ", "FR", "BF", "VU", "ZW", "TL", "RS", "CD", /* replacement country codes */
|
||||
};
|
||||
|
||||
/* This list MUST contain a three-letter code for every two-letter code in
|
||||
|
Loading…
Reference in New Issue
Block a user