parent
7c0de5fd1a
commit
2b7ed6119a
@ -154,6 +154,16 @@ public class CurrencyData {
|
|||||||
return fallback ? isoCode : null;
|
return fallback ? isoCode : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFormalSymbol(String isoCode) {
|
||||||
|
return fallback ? isoCode : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVariantSymbol(String isoCode) {
|
||||||
|
return fallback ? isoCode : null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> symbolMap() {
|
public Map<String, String> symbolMap() {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
|
@ -7,6 +7,7 @@ import com.ibm.icu.impl.StandardPlural;
|
|||||||
import com.ibm.icu.impl.number.AffixUtils.SymbolProvider;
|
import com.ibm.icu.impl.number.AffixUtils.SymbolProvider;
|
||||||
import com.ibm.icu.number.NumberFormatter.SignDisplay;
|
import com.ibm.icu.number.NumberFormatter.SignDisplay;
|
||||||
import com.ibm.icu.number.NumberFormatter.UnitWidth;
|
import com.ibm.icu.number.NumberFormatter.UnitWidth;
|
||||||
|
import com.ibm.icu.text.CurrencyDisplayNames;
|
||||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||||
import com.ibm.icu.text.NumberFormat.Field;
|
import com.ibm.icu.text.NumberFormat.Field;
|
||||||
import com.ibm.icu.text.PluralRules;
|
import com.ibm.icu.text.PluralRules;
|
||||||
@ -401,8 +402,23 @@ public class MutablePatternModifier implements Modifier, SymbolProvider, MicroPr
|
|||||||
} else if (unitWidth == UnitWidth.HIDDEN) {
|
} else if (unitWidth == UnitWidth.HIDDEN) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
int selector = unitWidth == UnitWidth.NARROW ? Currency.NARROW_SYMBOL_NAME
|
int selector;
|
||||||
: Currency.SYMBOL_NAME;
|
switch (unitWidth) {
|
||||||
|
case SHORT:
|
||||||
|
selector = Currency.SYMBOL_NAME;
|
||||||
|
break;
|
||||||
|
case NARROW:
|
||||||
|
selector = Currency.NARROW_SYMBOL_NAME;
|
||||||
|
break;
|
||||||
|
case FORMAL:
|
||||||
|
selector = Currency.FORMAL_SYMBOL_NAME;
|
||||||
|
break;
|
||||||
|
case VARIANT:
|
||||||
|
selector = Currency.VARIANT_SYMBOL_NAME;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
return currency.getName(symbols.getULocale(), selector, null);
|
return currency.getName(symbols.getULocale(), selector, null);
|
||||||
}
|
}
|
||||||
case AffixUtils.TYPE_CURRENCY_DOUBLE:
|
case AffixUtils.TYPE_CURRENCY_DOUBLE:
|
||||||
|
@ -131,8 +131,10 @@ public final class NumberFormatter {
|
|||||||
FULL_NAME,
|
FULL_NAME,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use the three-digit ISO XXX code in place of the symbol for displaying currencies. The
|
* Use the three-digit ISO XXX code in place of the symbol for displaying currencies.
|
||||||
* behavior of this option is currently undefined for use with measure units.
|
*
|
||||||
|
* <p>
|
||||||
|
* Behavior of this option with non-currency units is not defined at this time.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* In CLDR, this option corresponds to the "¤¤" placeholder for currencies.
|
* In CLDR, this option corresponds to the "¤¤" placeholder for currencies.
|
||||||
@ -142,6 +144,32 @@ public final class NumberFormatter {
|
|||||||
*/
|
*/
|
||||||
ISO_CODE,
|
ISO_CODE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan
|
||||||
|
* dollar in zh-TW.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Behavior of this option with non-currency units is not defined at this time.
|
||||||
|
*
|
||||||
|
* @draft ICU 67
|
||||||
|
* @provisional This API might change or be removed in a future release.
|
||||||
|
* @see NumberFormatter
|
||||||
|
*/
|
||||||
|
FORMAL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the alternate variant of the currency symbol; for example, "TL" for the Turkish
|
||||||
|
* lira (TRY).
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Behavior of this option with non-currency units is not defined at this time.
|
||||||
|
*
|
||||||
|
* @draft ICU 67
|
||||||
|
* @provisional This API might change or be removed in a future release.
|
||||||
|
* @see NumberFormatter
|
||||||
|
*/
|
||||||
|
VARIANT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the number according to the specified unit, but do not display the unit. For
|
* Format the number according to the specified unit, but do not display the unit. For
|
||||||
* currencies, apply monetary symbols and formats as with SHORT, but omit the currency symbol.
|
* currencies, apply monetary symbols and formats as with SHORT, but omit the currency symbol.
|
||||||
|
@ -100,6 +100,8 @@ class NumberSkeletonImpl {
|
|||||||
STEM_UNIT_WIDTH_SHORT,
|
STEM_UNIT_WIDTH_SHORT,
|
||||||
STEM_UNIT_WIDTH_FULL_NAME,
|
STEM_UNIT_WIDTH_FULL_NAME,
|
||||||
STEM_UNIT_WIDTH_ISO_CODE,
|
STEM_UNIT_WIDTH_ISO_CODE,
|
||||||
|
STEM_UNIT_WIDTH_FORMAL,
|
||||||
|
STEM_UNIT_WIDTH_VARIANT,
|
||||||
STEM_UNIT_WIDTH_HIDDEN,
|
STEM_UNIT_WIDTH_HIDDEN,
|
||||||
STEM_SIGN_AUTO,
|
STEM_SIGN_AUTO,
|
||||||
STEM_SIGN_ALWAYS,
|
STEM_SIGN_ALWAYS,
|
||||||
@ -173,6 +175,8 @@ class NumberSkeletonImpl {
|
|||||||
b.add("unit-width-short", StemEnum.STEM_UNIT_WIDTH_SHORT.ordinal());
|
b.add("unit-width-short", StemEnum.STEM_UNIT_WIDTH_SHORT.ordinal());
|
||||||
b.add("unit-width-full-name", StemEnum.STEM_UNIT_WIDTH_FULL_NAME.ordinal());
|
b.add("unit-width-full-name", StemEnum.STEM_UNIT_WIDTH_FULL_NAME.ordinal());
|
||||||
b.add("unit-width-iso-code", StemEnum.STEM_UNIT_WIDTH_ISO_CODE.ordinal());
|
b.add("unit-width-iso-code", StemEnum.STEM_UNIT_WIDTH_ISO_CODE.ordinal());
|
||||||
|
b.add("unit-width-formal", StemEnum.STEM_UNIT_WIDTH_FORMAL.ordinal());
|
||||||
|
b.add("unit-width-variant", StemEnum.STEM_UNIT_WIDTH_VARIANT.ordinal());
|
||||||
b.add("unit-width-hidden", StemEnum.STEM_UNIT_WIDTH_HIDDEN.ordinal());
|
b.add("unit-width-hidden", StemEnum.STEM_UNIT_WIDTH_HIDDEN.ordinal());
|
||||||
b.add("sign-auto", StemEnum.STEM_SIGN_AUTO.ordinal());
|
b.add("sign-auto", StemEnum.STEM_SIGN_AUTO.ordinal());
|
||||||
b.add("sign-always", StemEnum.STEM_SIGN_ALWAYS.ordinal());
|
b.add("sign-always", StemEnum.STEM_SIGN_ALWAYS.ordinal());
|
||||||
@ -315,6 +319,10 @@ class NumberSkeletonImpl {
|
|||||||
return UnitWidth.FULL_NAME;
|
return UnitWidth.FULL_NAME;
|
||||||
case STEM_UNIT_WIDTH_ISO_CODE:
|
case STEM_UNIT_WIDTH_ISO_CODE:
|
||||||
return UnitWidth.ISO_CODE;
|
return UnitWidth.ISO_CODE;
|
||||||
|
case STEM_UNIT_WIDTH_FORMAL:
|
||||||
|
return UnitWidth.FORMAL;
|
||||||
|
case STEM_UNIT_WIDTH_VARIANT:
|
||||||
|
return UnitWidth.VARIANT;
|
||||||
case STEM_UNIT_WIDTH_HIDDEN:
|
case STEM_UNIT_WIDTH_HIDDEN:
|
||||||
return UnitWidth.HIDDEN;
|
return UnitWidth.HIDDEN;
|
||||||
default:
|
default:
|
||||||
@ -428,6 +436,12 @@ class NumberSkeletonImpl {
|
|||||||
case ISO_CODE:
|
case ISO_CODE:
|
||||||
sb.append("unit-width-iso-code");
|
sb.append("unit-width-iso-code");
|
||||||
break;
|
break;
|
||||||
|
case FORMAL:
|
||||||
|
sb.append("unit-width-formal");
|
||||||
|
break;
|
||||||
|
case VARIANT:
|
||||||
|
sb.append("unit-width-variant");
|
||||||
|
break;
|
||||||
case HIDDEN:
|
case HIDDEN:
|
||||||
sb.append("unit-width-hidden");
|
sb.append("unit-width-hidden");
|
||||||
break;
|
break;
|
||||||
@ -729,6 +743,8 @@ class NumberSkeletonImpl {
|
|||||||
case STEM_UNIT_WIDTH_SHORT:
|
case STEM_UNIT_WIDTH_SHORT:
|
||||||
case STEM_UNIT_WIDTH_FULL_NAME:
|
case STEM_UNIT_WIDTH_FULL_NAME:
|
||||||
case STEM_UNIT_WIDTH_ISO_CODE:
|
case STEM_UNIT_WIDTH_ISO_CODE:
|
||||||
|
case STEM_UNIT_WIDTH_FORMAL:
|
||||||
|
case STEM_UNIT_WIDTH_VARIANT:
|
||||||
case STEM_UNIT_WIDTH_HIDDEN:
|
case STEM_UNIT_WIDTH_HIDDEN:
|
||||||
checkNull(macros.unitWidth, segment);
|
checkNull(macros.unitWidth, segment);
|
||||||
macros.unitWidth = StemToObject.unitWidth(stem);
|
macros.unitWidth = StemToObject.unitWidth(stem);
|
||||||
|
@ -110,9 +110,10 @@ public abstract class CurrencyDisplayNames {
|
|||||||
public abstract ULocale getULocale();
|
public abstract ULocale getULocale();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the symbol for the currency with the provided ISO code. If
|
* Returns the symbol for the currency with the provided ISO code.
|
||||||
* there is no data for the ISO code, substitutes isoCode, or returns null
|
* <p>
|
||||||
* if noSubstitute was set in the factory method.
|
* If there is no data for this symbol, substitutes isoCode,
|
||||||
|
* or returns null if noSubstitute was set in the factory method.
|
||||||
*
|
*
|
||||||
* @param isoCode the three-letter ISO code.
|
* @param isoCode the three-letter ISO code.
|
||||||
* @return the symbol.
|
* @return the symbol.
|
||||||
@ -122,7 +123,12 @@ public abstract class CurrencyDisplayNames {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the narrow symbol for the currency with the provided ISO code.
|
* Returns the narrow symbol for the currency with the provided ISO code.
|
||||||
* If there is no data for narrow symbol, substitutes the default symbol,
|
* <p>
|
||||||
|
* The narrow currency symbol is similar to the regular currency symbol,
|
||||||
|
* but it always takes the shortest form;
|
||||||
|
* for example, "$" instead of "US$" for USD in en-CA.
|
||||||
|
* <p>
|
||||||
|
* If there is no data for this symbol, substitutes the default symbol,
|
||||||
* or returns null if noSubstitute was set in the factory method.
|
* or returns null if noSubstitute was set in the factory method.
|
||||||
*
|
*
|
||||||
* @param isoCode the three-letter ISO code.
|
* @param isoCode the three-letter ISO code.
|
||||||
@ -131,6 +137,39 @@ public abstract class CurrencyDisplayNames {
|
|||||||
*/
|
*/
|
||||||
public abstract String getNarrowSymbol(String isoCode);
|
public abstract String getNarrowSymbol(String isoCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the formal symbol for the currency with the provided ISO code.
|
||||||
|
* <p>
|
||||||
|
* The formal currency symbol is similar to the regular currency symbol,
|
||||||
|
* but it always takes the form used in formal settings such as banking;
|
||||||
|
* for example, "NT$" instead of "$" for TWD in zh-TW.
|
||||||
|
* <p>
|
||||||
|
* If there is no data for this symbol, substitutes the default symbol,
|
||||||
|
* or returns null if noSubstitute was set in the factory method.
|
||||||
|
*
|
||||||
|
* @param isoCode the three-letter ISO code.
|
||||||
|
* @return the formal symbol.
|
||||||
|
* @draft ICU 67
|
||||||
|
* @provisional This API might change or be removed in a future release.
|
||||||
|
*/
|
||||||
|
public abstract String getFormalSymbol(String isoCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the variant symbol for the currency with the provided ISO code.
|
||||||
|
* <p>
|
||||||
|
* The variant symbol for a currency is an alternative symbol that is not
|
||||||
|
* necessarily as widely used as the regular symbol.
|
||||||
|
* <p>
|
||||||
|
* If there is no data for variant symbol, substitutes the default symbol,
|
||||||
|
* or returns null if noSubstitute was set in the factory method.
|
||||||
|
*
|
||||||
|
* @param isoCode the three-letter ISO code.
|
||||||
|
* @return the variant symbol.
|
||||||
|
* @draft ICU 67
|
||||||
|
* @provisional This API might change or be removed in a future release.
|
||||||
|
*/
|
||||||
|
public abstract String getVariantSymbol(String isoCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the 'long name' for the currency with the provided ISO code.
|
* Returns the 'long name' for the currency with the provided ISO code.
|
||||||
* If there is no data for the ISO code, substitutes isoCode, or returns null
|
* If there is no data for the ISO code, substitutes isoCode, or returns null
|
||||||
|
@ -90,14 +90,38 @@ public class Currency extends MeasureUnit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Selector for getName() indicating the narrow currency symbol.
|
* Selector for getName() indicating the narrow currency symbol.
|
||||||
* The narrow currency symbol is similar to the regular currency
|
* <p>
|
||||||
* symbol, but it always takes the shortest form: for example,
|
* The narrow currency symbol is similar to the regular currency symbol,
|
||||||
* "$" instead of "US$" for USD in en-CA.
|
* but it always takes the shortest form;
|
||||||
|
* for example, "$" instead of "US$" for USD in en-CA.
|
||||||
*
|
*
|
||||||
* @stable ICU 61
|
* @stable ICU 61
|
||||||
*/
|
*/
|
||||||
public static final int NARROW_SYMBOL_NAME = 3;
|
public static final int NARROW_SYMBOL_NAME = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selector for getName() indicating the formal currency symbol.
|
||||||
|
* <p>
|
||||||
|
* The formal currency symbol is similar to the regular currency symbol,
|
||||||
|
* but it always takes the form used in formal settings such as banking;
|
||||||
|
* for example, "NT$" instead of "$" for TWD in zh-TW.
|
||||||
|
*
|
||||||
|
* @draft ICU 67
|
||||||
|
* @provisional This API might change or be removed in a future release.
|
||||||
|
*/
|
||||||
|
public static final int FORMAL_SYMBOL_NAME = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selector for getName() indicating the variant currency symbol.
|
||||||
|
* <p>
|
||||||
|
* The variant symbol for a currency is an alternative symbol that is not
|
||||||
|
* necessarily as widely used as the regular symbol.
|
||||||
|
*
|
||||||
|
* @draft ICU 67
|
||||||
|
* @provisional This API might change or be removed in a future release.
|
||||||
|
*/
|
||||||
|
public static final int VARIANT_SYMBOL_NAME = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currency Usage used for Decimal Format
|
* Currency Usage used for Decimal Format
|
||||||
* @stable ICU 54
|
* @stable ICU 54
|
||||||
@ -572,6 +596,10 @@ public class Currency extends MeasureUnit {
|
|||||||
return names.getSymbol(subType);
|
return names.getSymbol(subType);
|
||||||
case NARROW_SYMBOL_NAME:
|
case NARROW_SYMBOL_NAME:
|
||||||
return names.getNarrowSymbol(subType);
|
return names.getNarrowSymbol(subType);
|
||||||
|
case FORMAL_SYMBOL_NAME:
|
||||||
|
return names.getFormalSymbol(subType);
|
||||||
|
case VARIANT_SYMBOL_NAME:
|
||||||
|
return names.getVariantSymbol(subType);
|
||||||
case LONG_NAME:
|
case LONG_NAME:
|
||||||
return names.getName(subType);
|
return names.getName(subType);
|
||||||
default:
|
default:
|
||||||
|
@ -75,10 +75,10 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
private volatile FormattingData formattingDataCache = null;
|
private volatile FormattingData formattingDataCache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single-item cache for getNarrowSymbol().
|
* Single-item cache for variant symbols.
|
||||||
* Holds data for only one currency. If another currency is requested, the old cache item is overwritten.
|
* Holds data for only one currency. If another currency is requested, the old cache item is overwritten.
|
||||||
*/
|
*/
|
||||||
private volatile NarrowSymbol narrowSymbolCache = null;
|
private volatile VariantSymbol variantSymbolCache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single-item cache for getPluralName().
|
* Single-item cache for getPluralName().
|
||||||
@ -116,11 +116,15 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
FormattingData(String isoCode) { this.isoCode = isoCode; }
|
FormattingData(String isoCode) { this.isoCode = isoCode; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static class NarrowSymbol {
|
static class VariantSymbol {
|
||||||
final String isoCode;
|
final String isoCode;
|
||||||
String narrowSymbol = null;
|
final String variant;
|
||||||
|
String symbol = null;
|
||||||
|
|
||||||
NarrowSymbol(String isoCode) { this.isoCode = isoCode; }
|
VariantSymbol(String isoCode, String variant) {
|
||||||
|
this.isoCode = isoCode;
|
||||||
|
this.variant = variant;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ParsingData {
|
static class ParsingData {
|
||||||
@ -167,13 +171,35 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNarrowSymbol(String isoCode) {
|
public String getNarrowSymbol(String isoCode) {
|
||||||
NarrowSymbol narrowSymbol = fetchNarrowSymbol(isoCode);
|
VariantSymbol variantSymbol = fetchVariantSymbol(isoCode, "narrow");
|
||||||
|
|
||||||
// Fall back to ISO Code
|
// Fall back to regular symbol
|
||||||
if (narrowSymbol.narrowSymbol == null && fallback) {
|
if (variantSymbol.symbol == null && fallback) {
|
||||||
return getSymbol(isoCode);
|
return getSymbol(isoCode);
|
||||||
}
|
}
|
||||||
return narrowSymbol.narrowSymbol;
|
return variantSymbol.symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFormalSymbol(String isoCode) {
|
||||||
|
VariantSymbol variantSymbol = fetchVariantSymbol(isoCode, "formal");
|
||||||
|
|
||||||
|
// Fall back to regular symbol
|
||||||
|
if (variantSymbol.symbol == null && fallback) {
|
||||||
|
return getSymbol(isoCode);
|
||||||
|
}
|
||||||
|
return variantSymbol.symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVariantSymbol(String isoCode) {
|
||||||
|
VariantSymbol variantSymbol = fetchVariantSymbol(isoCode, "variant");
|
||||||
|
|
||||||
|
// Fall back to regular symbol
|
||||||
|
if (variantSymbol.symbol == null && fallback) {
|
||||||
|
return getSymbol(isoCode);
|
||||||
|
}
|
||||||
|
return variantSymbol.symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -256,14 +282,14 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NarrowSymbol fetchNarrowSymbol(String isoCode) {
|
VariantSymbol fetchVariantSymbol(String isoCode, String variant) {
|
||||||
NarrowSymbol result = narrowSymbolCache;
|
VariantSymbol result = variantSymbolCache;
|
||||||
if (result == null || !result.isoCode.equals(isoCode)) {
|
if (result == null || !result.isoCode.equals(isoCode) || !result.variant.equals(variant)) {
|
||||||
result = new NarrowSymbol(isoCode);
|
result = new VariantSymbol(isoCode, variant);
|
||||||
CurrencySink sink = new CurrencySink(!fallback, CurrencySink.EntrypointTable.CURRENCY_NARROW);
|
CurrencySink sink = new CurrencySink(!fallback, CurrencySink.EntrypointTable.CURRENCY_VARIANT);
|
||||||
sink.narrowSymbol = result;
|
sink.variantSymbol = result;
|
||||||
rb.getAllItemsWithFallbackNoFail("Currencies%narrow/" + isoCode, sink);
|
rb.getAllItemsWithFallbackNoFail("Currencies%" + variant + "/" + isoCode, sink);
|
||||||
narrowSymbolCache = result;
|
variantSymbolCache = result;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -331,7 +357,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
ParsingData parsingData = null;
|
ParsingData parsingData = null;
|
||||||
Map<String, String> unitPatterns = null;
|
Map<String, String> unitPatterns = null;
|
||||||
CurrencySpacingInfo spacingInfo = null;
|
CurrencySpacingInfo spacingInfo = null;
|
||||||
NarrowSymbol narrowSymbol = null;
|
VariantSymbol variantSymbol = null;
|
||||||
|
|
||||||
enum EntrypointTable {
|
enum EntrypointTable {
|
||||||
// For Parsing:
|
// For Parsing:
|
||||||
@ -340,7 +366,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
// For Formatting:
|
// For Formatting:
|
||||||
CURRENCIES,
|
CURRENCIES,
|
||||||
CURRENCY_PLURALS,
|
CURRENCY_PLURALS,
|
||||||
CURRENCY_NARROW,
|
CURRENCY_VARIANT,
|
||||||
CURRENCY_SPACING,
|
CURRENCY_SPACING,
|
||||||
CURRENCY_UNIT_PATTERNS
|
CURRENCY_UNIT_PATTERNS
|
||||||
}
|
}
|
||||||
@ -371,8 +397,8 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
case CURRENCY_PLURALS:
|
case CURRENCY_PLURALS:
|
||||||
consumeCurrencyPluralsEntry(key, value);
|
consumeCurrencyPluralsEntry(key, value);
|
||||||
break;
|
break;
|
||||||
case CURRENCY_NARROW:
|
case CURRENCY_VARIANT:
|
||||||
consumeCurrenciesNarrowEntry(key, value);
|
consumeCurrenciesVariantEntry(key, value);
|
||||||
break;
|
break;
|
||||||
case CURRENCY_SPACING:
|
case CURRENCY_SPACING:
|
||||||
consumeCurrencySpacingTable(key, value);
|
consumeCurrencySpacingTable(key, value);
|
||||||
@ -475,11 +501,11 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
|||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
void consumeCurrenciesNarrowEntry(UResource.Key key, UResource.Value value) {
|
void consumeCurrenciesVariantEntry(UResource.Key key, UResource.Value value) {
|
||||||
assert narrowSymbol != null;
|
assert variantSymbol != null;
|
||||||
// No extra structure to traverse.
|
// No extra structure to traverse.
|
||||||
if (narrowSymbol.narrowSymbol == null) {
|
if (variantSymbol.symbol == null) {
|
||||||
narrowSymbol.narrowSymbol = value.getString();
|
variantSymbol.symbol = value.getString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ public class NumberFormatterApiTest {
|
|||||||
private static final Currency ESP = Currency.getInstance("ESP");
|
private static final Currency ESP = Currency.getInstance("ESP");
|
||||||
private static final Currency PTE = Currency.getInstance("PTE");
|
private static final Currency PTE = Currency.getInstance("PTE");
|
||||||
private static final Currency RON = Currency.getInstance("RON");
|
private static final Currency RON = Currency.getInstance("RON");
|
||||||
|
private static final Currency TWD = Currency.getInstance("TWD");
|
||||||
|
private static final Currency TRY = Currency.getInstance("TRY");
|
||||||
private static final Currency CNY = Currency.getInstance("CNY");
|
private static final Currency CNY = Currency.getInstance("CNY");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -802,6 +804,42 @@ public class NumberFormatterApiTest {
|
|||||||
5.43,
|
5.43,
|
||||||
"US$5.43");
|
"US$5.43");
|
||||||
|
|
||||||
|
assertFormatSingle(
|
||||||
|
"Currency Difference between Formal and Short (Formal Version)",
|
||||||
|
"currency/TWD unit-width-formal",
|
||||||
|
"currency/TWD unit-width-formal",
|
||||||
|
NumberFormatter.with().unit(TWD).unitWidth(UnitWidth.FORMAL),
|
||||||
|
ULocale.forLanguageTag("zh-TW"),
|
||||||
|
5.43,
|
||||||
|
"NT$5.43");
|
||||||
|
|
||||||
|
assertFormatSingle(
|
||||||
|
"Currency Difference between Formal and Short (Short Version)",
|
||||||
|
"currency/TWD unit-width-short",
|
||||||
|
"currency/TWD unit-width-short",
|
||||||
|
NumberFormatter.with().unit(TWD).unitWidth(UnitWidth.SHORT),
|
||||||
|
ULocale.forLanguageTag("zh-TW"),
|
||||||
|
5.43,
|
||||||
|
"$5.43");
|
||||||
|
|
||||||
|
assertFormatSingle(
|
||||||
|
"Currency Difference between Variant and Short (Formal Version)",
|
||||||
|
"currency/TRY unit-width-variant",
|
||||||
|
"currency/TRY unit-width-variant",
|
||||||
|
NumberFormatter.with().unit(TRY).unitWidth(UnitWidth.VARIANT),
|
||||||
|
ULocale.forLanguageTag("tr-TR"),
|
||||||
|
5.43,
|
||||||
|
"TL\u00A05,43");
|
||||||
|
|
||||||
|
assertFormatSingle(
|
||||||
|
"Currency Difference between Variant and Short (Short Version)",
|
||||||
|
"currency/TRY unit-width-short",
|
||||||
|
"currency/TRY unit-width-short",
|
||||||
|
NumberFormatter.with().unit(TRY).unitWidth(UnitWidth.SHORT),
|
||||||
|
ULocale.forLanguageTag("tr-TR"),
|
||||||
|
5.43,
|
||||||
|
"₺5,43");
|
||||||
|
|
||||||
assertFormatSingle(
|
assertFormatSingle(
|
||||||
"Currency-dependent format (Control)",
|
"Currency-dependent format (Control)",
|
||||||
"currency/USD unit-width-short",
|
"currency/USD unit-width-short",
|
||||||
|
@ -94,7 +94,7 @@ public class CurrencyTest extends TestFmwk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
usd.getName(ULocale.US, 5, new boolean[1]);
|
usd.getName(ULocale.US, 6, new boolean[1]);
|
||||||
errln("expected getName with invalid type parameter to throw exception");
|
errln("expected getName with invalid type parameter to throw exception");
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -177,7 +177,7 @@ public class CurrencyTest extends TestFmwk {
|
|||||||
Locale[] locs = Currency.getAvailableLocales();
|
Locale[] locs = Currency.getAvailableLocales();
|
||||||
found = false;
|
found = false;
|
||||||
for (int i = 0; i < locs.length; ++i) {
|
for (int i = 0; i < locs.length; ++i) {
|
||||||
if (locs[i].equals(fu_FU)) {
|
if (locs[i].equals(fu_FU.toLocale())) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -246,26 +246,44 @@ public class CurrencyTest extends TestFmwk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test20484_NarrowSymbolFallback() {
|
public void testCurrencyVariants() {
|
||||||
Object[][] cases = new Object[][] {
|
Object[][] cases = new Object[][] {
|
||||||
{"en-US", "CAD", "CA$", "$"},
|
{"en-US", "CAD", "CA$", "$", "CA$", "CA$"},
|
||||||
{"en-US", "CDF", "CDF", "CDF"},
|
{"en-US", "CDF", "CDF", "CDF", "CDF", "CDF"},
|
||||||
{"sw-CD", "CDF", "FC", "FC"},
|
{"sw-CD", "CDF", "FC", "FC", "FC", "FC"},
|
||||||
{"en-US", "GEL", "GEL", "₾"},
|
{"en-US", "GEL", "GEL", "₾", "GEL", "GEL"},
|
||||||
{"ka-GE", "GEL", "₾", "₾"},
|
{"ka-GE", "GEL", "₾", "₾", "₾", "₾"},
|
||||||
{"ka", "GEL", "₾", "₾"},
|
{"ka", "GEL", "₾", "₾", "₾", "₾"},
|
||||||
|
{"zh-TW", "TWD", "$", "$", "NT$", "$"},
|
||||||
|
{"ccp", "TRY", "TRY", "₺", "TRY", "TL"}
|
||||||
};
|
};
|
||||||
for (Object[] cas : cases) {
|
for (Object[] cas : cases) {
|
||||||
ULocale locale = new ULocale((String) cas[0]);
|
ULocale locale = new ULocale((String) cas[0]);
|
||||||
String isoCode = (String) cas[1];
|
String isoCode = (String) cas[1];
|
||||||
String expectedShort = (String) cas[2];
|
String expectedShort = (String) cas[2];
|
||||||
String expectedNarrow = (String) cas[3];
|
String expectedNarrow = (String) cas[3];
|
||||||
|
String expectedFormal = (String) cas[4];
|
||||||
|
String expectedVariant = (String) cas[5];
|
||||||
|
|
||||||
CurrencyDisplayNames cdn = CurrencyDisplayNames.getInstance(locale);
|
CurrencyDisplayNames cdn = CurrencyDisplayNames.getInstance(locale);
|
||||||
assertEquals("Short symbol: " + locale + ": " + isoCode,
|
assertEquals("Short symbol: " + locale + ": " + isoCode,
|
||||||
expectedShort, cdn.getSymbol(isoCode));
|
expectedShort, cdn.getSymbol(isoCode));
|
||||||
assertEquals("Narrow symbol: " + locale + ": " + isoCode,
|
assertEquals("Narrow symbol: " + locale + ": " + isoCode,
|
||||||
expectedNarrow, cdn.getNarrowSymbol(isoCode));
|
expectedNarrow, cdn.getNarrowSymbol(isoCode));
|
||||||
|
assertEquals("Formal symbol: " + locale + ": " + isoCode,
|
||||||
|
expectedFormal, cdn.getFormalSymbol(isoCode));
|
||||||
|
assertEquals("Variant symbol: " + locale + ": " + isoCode,
|
||||||
|
expectedVariant, cdn.getVariantSymbol(isoCode));
|
||||||
|
|
||||||
|
Currency currency = Currency.getInstance(isoCode);
|
||||||
|
assertEquals("Old API, Short symbol: " + locale + ": " + isoCode,
|
||||||
|
expectedShort, currency.getName(locale, Currency.SYMBOL_NAME, null));
|
||||||
|
assertEquals("Old API, Narrow symbol: " + locale + ": " + isoCode,
|
||||||
|
expectedNarrow, currency.getName(locale, Currency.NARROW_SYMBOL_NAME, null));
|
||||||
|
assertEquals("Old API, Formal symbol: " + locale + ": " + isoCode,
|
||||||
|
expectedFormal, currency.getName(locale, Currency.FORMAL_SYMBOL_NAME, null));
|
||||||
|
assertEquals("Old API, Variant symbol: " + locale + ": " + isoCode,
|
||||||
|
expectedVariant, currency.getName(locale, Currency.VARIANT_SYMBOL_NAME, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user