* unitsShort/duration/hour contains other{"{0} hrs"}.
*/
class UnitPatternSink extends UResource.TableSink {
+ QuantityFormatter countToFormat;
+
@Override
public void put(UResource.Key key, UResource.Value value) {
if (key.contentEquals("dnam")) {
// The key must be one of the plural form strings. For example:
// one{"{0} hr"}
// other{"{0} hrs"}
- QuantityFormatter countToFormat;
- EnumMap<FormatWidth, QuantityFormatter> styleToCountToFormat =
- cacheData.unitToStyleToCountToFormat.get(unit);
- if (styleToCountToFormat == null) {
- styleToCountToFormat =
- new EnumMap<FormatWidth, QuantityFormatter>(FormatWidth.class);
- cacheData.unitToStyleToCountToFormat.put(unit, styleToCountToFormat);
- countToFormat = null;
- } else {
- countToFormat = styleToCountToFormat.get(width);
- }
if (countToFormat == null) {
- countToFormat = new QuantityFormatter();
- styleToCountToFormat.put(width, countToFormat);
+ EnumMap<FormatWidth, QuantityFormatter> styleToCountToFormat =
+ cacheData.unitToStyleToCountToFormat.get(unit);
+ if (styleToCountToFormat == null) {
+ styleToCountToFormat =
+ new EnumMap<FormatWidth, QuantityFormatter>(FormatWidth.class);
+ cacheData.unitToStyleToCountToFormat.put(unit, styleToCountToFormat);
+ } else {
+ countToFormat = styleToCountToFormat.get(width);
+ }
+ if (countToFormat == null) {
+ countToFormat = new QuantityFormatter();
+ styleToCountToFormat.put(width, countToFormat);
+ }
}
countToFormat.addIfAbsent(key, value);
}
public UResource.TableSink getOrCreateTableSink(UResource.Key key, int initialSize) {
// Should we ignore or reject unknown units?
unit = MeasureUnit.internalGetInstance(type, key.toString()); // never null
+ // Trigger a fresh lookup of the QuantityFormatter for this unit+width.
+ patternSink.countToFormat = null;
return patternSink;
}
}
/*
*******************************************************************************
- * Copyright (C) 2013-2015, International Business Machines Corporation and *
- * others. All Rights Reserved. *
+ * Copyright (C) 2013-2015, International Business Machines Corporation and
+ * others. All Rights Reserved.
*******************************************************************************
*/
package com.ibm.icu.dev.test.format;
new Measure(16, MeasureUnit.SECOND)));
}
-
+
+ public void testIndividualPluralFallback() {
+ // See ticket #11986 "incomplete fallback in MeasureFormat".
+ // In CLDR 28, fr_CA temperature-generic/short has only the "one" form,
+ // and falls back to fr for the "other" form.
+ MeasureFormat mf = MeasureFormat.getInstance(new ULocale("fr_CA"), FormatWidth.SHORT);
+ Measure twoDeg = new Measure(2, MeasureUnit.GENERIC_TEMPERATURE);
+ assertEquals("2 deg temp in fr_CA", "2°", mf.format(twoDeg));
+ }
+
// DO NOT DELETE THIS FUNCTION! It may appear as dead code, but we use this to generate code
// for MeasureFormat during the release process.
static Map<MeasureUnit, Pair<MeasureUnit, MeasureUnit>> getUnitsToPerParts() {