ICU-9042 in time unit format, ignore those plural counts that are not defined in the locale's plural rules
X-SVN-Rev: 31930
This commit is contained in:
parent
7042fcca36
commit
9aa2213d01
@ -1,6 +1,6 @@
|
||||
/*
|
||||
**************************************************************************
|
||||
* Copyright (C) 2008-2011, Google, International Business Machines
|
||||
* Copyright (C) 2008-2012, Google, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**************************************************************************
|
||||
*/
|
||||
@ -333,14 +333,15 @@ public class TimeUnitFormat extends MeasureFormat {
|
||||
pluralRules = PluralRules.forLocale(locale);
|
||||
timeUnitToCountToPatterns = new HashMap<TimeUnit, Map<String, Object[]>>();
|
||||
|
||||
setup("units", timeUnitToCountToPatterns, FULL_NAME);
|
||||
setup("unitsShort", timeUnitToCountToPatterns, ABBREVIATED_NAME);
|
||||
Set<String> pluralKeywords = pluralRules.getKeywords();
|
||||
setup("units", timeUnitToCountToPatterns, FULL_NAME, pluralKeywords);
|
||||
setup("unitsShort", timeUnitToCountToPatterns, ABBREVIATED_NAME, pluralKeywords);
|
||||
isReady = true;
|
||||
}
|
||||
|
||||
|
||||
private void setup(String resourceKey, Map<TimeUnit, Map<String, Object[]>> timeUnitToCountToPatterns,
|
||||
int style) {
|
||||
int style, Set<String> pluralKeywords) {
|
||||
// fill timeUnitToCountToPatterns from resource file
|
||||
try {
|
||||
ICUResourceBundle resource = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
|
||||
@ -375,6 +376,8 @@ public class TimeUnitFormat extends MeasureFormat {
|
||||
}
|
||||
for ( int pluralIndex = 0; pluralIndex < count; ++pluralIndex) {
|
||||
String pluralCount = oneUnitRes.get(pluralIndex).getKey();
|
||||
if (!pluralKeywords.contains(pluralCount))
|
||||
continue;
|
||||
String pattern = oneUnitRes.get(pluralIndex).getString();
|
||||
final MessageFormat messageFormat = new MessageFormat(pattern, locale);
|
||||
if (format != null) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2008-2010, International Business Machines Corporation and *
|
||||
* Copyright (C) 2008-2012, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -182,6 +182,25 @@ public class TimeUnitTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @bug9042
|
||||
* Performs tests for Greek.
|
||||
* This tests that if the plural count listed in time unit format does not
|
||||
* match those in the plural rules for the locale, those plural count in
|
||||
* time unit format will be ingored and subsequently, fall back will kick in
|
||||
* which is tested above.
|
||||
* Without data sanitization, setNumberFormat() would crash.
|
||||
* As of CLDR shiped in ICU4.8, Greek is one such language.
|
||||
*/
|
||||
public void TestGreekWithSanitization() {
|
||||
ULocale loc = new ULocale("el");
|
||||
NumberFormat numfmt = NumberFormat.getInstance(loc);
|
||||
TimeUnitFormat tuf = new TimeUnitFormat(loc);
|
||||
tuf.parseObject("", new ParsePosition(0));
|
||||
tuf.setNumberFormat(numfmt);
|
||||
}
|
||||
|
||||
|
||||
private void formatParsing(TimeUnitFormat format) {
|
||||
final TimeUnit[] values = TimeUnit.values();
|
||||
for (int j = 0; j < values.length; ++j) {
|
||||
|
Loading…
Reference in New Issue
Block a user