FYI: Fallback on to other locales for zone strings

View: New views
1 Messages — Rating Filter:   Alert me  

FYI: Fallback on to other locales for zone strings

by gnu_andrew :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We should pick up zone strings from further up the hierarchy
e.g. for a locale of en we should also pick up those from the
root.  This solves the GMT issue mentioned earlier.

ChangeLog:

2008-07-07  Andrew John Hughes  <gnu_andrew@...>

        * java/text/DateFormatSymbols.java:
        (getZoneStrings(ResourceBundle,Locale)):
        Fallback on to parent locales.

--
Andrew :)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8

Index: java/text/DateFormatSymbols.java
===================================================================
RCS file: /sources/classpath/classpath/java/text/DateFormatSymbols.java,v
retrieving revision 1.25
diff -u -u -r1.25 DateFormatSymbols.java
--- java/text/DateFormatSymbols.java 7 Jul 2008 15:07:17 -0000 1.25
+++ java/text/DateFormatSymbols.java 7 Jul 2008 21:40:11 -0000
@@ -135,39 +135,44 @@
     List<String[]> allZones = new ArrayList<String[]>();
     try
       {
-        int index = 0;
- String country = locale.getCountry();
  Map<String,String[]> systemZones = new HashMap<String,String[]>();
-        String data = res.getString("zoneStrings");
- String[] zones = data.split("\u00a9");
- for (int a = 0; a < zones.length; ++a)
+ while (true)
   {
-    String[] strings = zones[a].split("\u00ae");
-    // Workaround for missing short GMT display name
-    // See http://www.unicode.org/cldr/bugs/locale-bugs/incoming?id=1885
-    if (strings[0].equals("GMT"))
-      strings[2] = "GMT";
-    String type = properties.getProperty(strings[0] + "." + country);
-    if (type == null)
-      type = properties.getProperty(strings[0] + ".DEFAULT");
-    if (type != null)
-      strings[0] = type;
-    if (strings.length < 5)
+    int index = 0;
+    String country = locale.getCountry();
+    String data = res.getString("zoneStrings");
+    String[] zones = data.split("\u00a9");
+    for (int a = 0; a < zones.length; ++a)
       {
- String[] newStrings = new String[5];
- System.arraycopy(strings, 0, newStrings, 0, strings.length);
- for (int b = strings.length; b < newStrings.length; ++b)
-  newStrings[b] = "";
- strings = newStrings;
-      }
-    String[] existing = systemZones.get(strings[0]);
-    if (existing != null && existing.length > 1)
-      {
- for (int b = 1; b < existing.length; ++b)
-  if (!existing[b].equals(""))
-    strings[b] = existing[b];  
+ String[] strings = zones[a].split("\u00ae");
+ String type = properties.getProperty(strings[0] + "." + country);
+ if (type == null)
+  type = properties.getProperty(strings[0] + ".DEFAULT");
+ if (type != null)
+  strings[0] = type;
+ if (strings.length < 5)
+  {
+    String[] newStrings = new String[5];
+    System.arraycopy(strings, 0, newStrings, 0, strings.length);
+    for (int b = strings.length; b < newStrings.length; ++b)
+      newStrings[b] = "";
+    strings = newStrings;
+  }
+ String[] existing = systemZones.get(strings[0]);
+ if (existing != null && existing.length > 1)
+  {
+    for (int b = 1; b < existing.length; ++b)
+      if (!existing[b].equals(""))
+ strings[b] = existing[b];  
+  }
+ systemZones.put(strings[0], strings);
       }
-    systemZones.put(strings[0], strings);
+    if (res.getLocale() == Locale.ROOT)
+      break;
+    else
+      res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
+     LocaleHelper.getFallbackLocale(res.getLocale()),
+     ClassLoader.getSystemClassLoader());
   }
  allZones.addAll(systemZones.values());
       }
@@ -245,9 +250,9 @@
     shortMonths = getStringArray(res, "shortMonths");
     shortWeekdays = getStringArray(res, "shortWeekdays");
     weekdays = getStringArray(res, "weekdays");
-    runtimeZoneStrings = getZoneStrings(res, locale);
     dateFormats = formatsForKey(res, "DateFormat");
     timeFormats = formatsForKey(res, "TimeFormat");
+    runtimeZoneStrings = getZoneStrings(res, locale);
   }
 
   /**
LightInTheBox - Buy quality products at wholesale price