]> granicus.if.org Git - icu/commitdiff
ICU-9952 Workaround to fix inheritance for availFmt/intervalFmt items in ICU4J; ...
authorPeter Edberg <pedberg@unicode.org>
Thu, 21 Feb 2013 11:33:13 +0000 (11:33 +0000)
committerPeter Edberg <pedberg@unicode.org>
Thu, 21 Feb 2013 11:33:13 +0000 (11:33 +0000)
X-SVN-Rev: 33292

icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java
icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java

index c4bb33c1c3aa91df4dcabd3cc8829311becc6626..ee256ebd152b2e7eec88fa821a6a2834bafb3fbf 100644 (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);
index 9e1ca990249855a64505a6cbbd06acab7b44226f..34fb17f73167266fa0b4ac2537d593393b73be44 100644 (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();