ICU-9952 Workaround to fix inheritance for availFmt/intervalFmt items in ICU4J; #9964 for long-term fix

X-SVN-Rev: 33292
This commit is contained in:
Peter Edberg 2013-02-21 11:33:13 +00:00
parent 4fa11a300d
commit 91b8823ba5
2 changed files with 47 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
@ -391,6 +392,17 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,currentLocale);
ICUResourceBundle calBundle = rb.getWithFallback("calendar");
ICUResourceBundle calTypeBundle = calBundle.getWithFallback(calendarTypeToUse);
// Start hack to force inheriting sideways from generic before up to parent locale.
// This happens in ICU4C just via the aliases in root, not sure why not here.
// This is added per #9952, #9964 for better long-term fix.
if (calTypeBundle != null && !calendarTypeToUse.equals("gregorian") && !calendarTypeToUse.equals("chinese")) {
Locale desiredLocale = rb.getLocale();
Locale calDataLocale = calTypeBundle.getLocale();
if (!calDataLocale.equals(desiredLocale)) {
calTypeBundle = calBundle.getWithFallback("generic");
}
}
// End hack
ICUResourceBundle itvDtPtnResource =calTypeBundle.getWithFallback("intervalFormats");
// look for fallback first, since it establishes the default order
String fallback = itvDtPtnResource.getStringWithFallback(FALLBACK_STRING);

View File

@ -15,6 +15,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Set;
@ -188,6 +189,18 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
// Get data for that calendar
ICUResourceBundle calBundle = rb.getWithFallback("calendar");
ICUResourceBundle calTypeBundle = calBundle.getWithFallback(calendarTypeToUse);
// Start hack to force inheriting sideways from generic before up to parent locale.
// This happens in ICU4C just via the aliases in root, not sure why not here.
// This is added per #9952, #9964 for better long-term fix. Part 2 is below.
if (calTypeBundle != null && !calendarTypeToUse.equals("gregorian") && !calendarTypeToUse.equals("chinese")) {
Locale desiredLocale = rb.getLocale();
Locale calDataLocale = calTypeBundle.getLocale();
if (!calDataLocale.equals(desiredLocale)) {
calTypeBundle = calBundle.getWithFallback("generic");
}
}
// End hack
// CLDR item formats
@ -244,8 +257,20 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
if (pbundle == null) {
break;
}
calBundle = pbundle.getWithFallback("calendar");
calTypeBundle = calBundle.getWithFallback(calendarTypeToUse);
// Start hack for sideways inheritance, part 2
// This is added per #9952, #9964 for better long-term fix.
if (calTypeBundle != null && !calendarTypeToUse.equals("gregorian") && !calendarTypeToUse.equals("chinese")) {
Locale desiredLocale = pbundle.getLocale();
Locale calDataLocale = calTypeBundle.getLocale();
if (!calDataLocale.equals(desiredLocale)) {
calTypeBundle = calBundle.getWithFallback("generic");
}
}
// End hack part 2
try {
availFormatsBundle = pbundle.getWithFallback("calendar/" + calendarTypeToUse + "/availableFormats");
availFormatsBundle = calTypeBundle.getWithFallback("availableFormats");
} catch (MissingResourceException e) {
availFormatsBundle = null;
}
@ -2012,15 +2037,15 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
for (int i = 0; i < TYPE_LIMIT; ++i) {
if (original[i].length() != 0) {
// append a string of the same length using the canonical character
for (int j = 0; j < types.length; ++j) {
int[] row = types[j];
if (row[1] == i) {
char originalChar = original[i].charAt(0);
char repeatChar = (originalChar=='h' || originalChar=='K')? 'h': (char)row[0];
result.append(Utility.repeat(String.valueOf(repeatChar), original[i].length()));
break;
}
}
for (int j = 0; j < types.length; ++j) {
int[] row = types[j];
if (row[1] == i) {
char originalChar = original[i].charAt(0);
char repeatChar = (originalChar=='h' || originalChar=='K')? 'h': (char)row[0];
result.append(Utility.repeat(String.valueOf(repeatChar), original[i].length()));
break;
}
}
}
}
return result.toString();