make/tools/src/build/tools/cldrconverter/CLDRConverter.java

Print this page

        

@@ -23,10 +23,11 @@
  * questions.
  */
 
 package build.tools.cldrconverter;
 
+import build.tools.cldrconverter.BundleGenerator.BundleType;
 import java.io.File;
 import java.nio.file.DirectoryStream;
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;

@@ -56,13 +57,12 @@
 
     static final String LOCALE_NAME_PREFIX = "locale.displayname.";
     static final String CURRENCY_SYMBOL_PREFIX = "currency.symbol.";
     static final String CURRENCY_NAME_PREFIX = "currency.displayname.";
     static final String TIMEZONE_ID_PREFIX = "timezone.id.";
-    static final String TIMEZONE_NAME_PREFIX = "timezone.displayname.";
+    static final String ZONE_NAME_PREFIX = "timezone.displayname.";
     static final String METAZONE_ID_PREFIX = "metazone.id.";
-    static final String METAZONE_NAME_PREFIX = "metazone.displayname.";
 
     private static SupplementDataParseHandler handlerSuppl;
     static NumberingSystemsParseHandler handlerNumbering;
     static MetaZonesParseHandler handlerMetaZones;
     private static BundleGenerator bundleGenerator;

@@ -234,11 +234,18 @@
                         }
                     }
                     if (sb.indexOf("root") == -1) {
                         sb.append("root");
                     }
-                    retList.add(new Bundle(id, sb.toString(), null, null));
+                    Bundle b = new Bundle(id, sb.toString(), null, null);
+                    // Insert the bundle for en at the top so that it will get
+                    // processed first.
+                    if ("en".equals(id)) {
+                        retList.add(0, b);
+                    } else {
+                        retList.add(b);
+                    }
                 }
             }
         }
         return retList;
     }

@@ -310,10 +317,11 @@
 
         // For generating information on supported locales.
         Map<String, SortedSet<String>> metaInfo = new HashMap<>();
         metaInfo.put("LocaleNames", new TreeSet<String>());
         metaInfo.put("CurrencyNames", new TreeSet<String>());
+        metaInfo.put("TimeZoneNames", new TreeSet<String>());
         metaInfo.put("CalendarData", new TreeSet<String>());
         metaInfo.put("FormatData", new TreeSet<String>());
 
         for (Bundle bundle : bundles) {
             // Get the target map, which contains all the data that should be

@@ -346,38 +354,43 @@
             // Go ahead and generate them.
             if (bundleTypes.contains(Bundle.Type.LOCALENAMES)) {
                 Map<String, Object> localeNamesMap = extractLocaleNames(targetMap, bundle.getID());
                 if (!localeNamesMap.isEmpty() || bundle.isRoot()) {
                     metaInfo.get("LocaleNames").add(toLanguageTag(bundle.getID()));
-                    bundleGenerator.generateBundle("util", "LocaleNames", bundle.getID(), true, localeNamesMap, true);
+                    bundleGenerator.generateBundle("util", "LocaleNames", bundle.getID(), true, localeNamesMap, BundleType.OPEN);
                 }
             }
             if (bundleTypes.contains(Bundle.Type.CURRENCYNAMES)) {
                 Map<String, Object> currencyNamesMap = extractCurrencyNames(targetMap, bundle.getID(), bundle.getCurrencies());
                 if (!currencyNamesMap.isEmpty() || bundle.isRoot()) {
                     metaInfo.get("CurrencyNames").add(toLanguageTag(bundle.getID()));
-                    bundleGenerator.generateBundle("util", "CurrencyNames", bundle.getID(), true, currencyNamesMap, true);
+                    bundleGenerator.generateBundle("util", "CurrencyNames", bundle.getID(), true, currencyNamesMap, BundleType.OPEN);
                 }
             }
             if (bundleTypes.contains(Bundle.Type.TIMEZONENAMES)) {
                 Map<String, Object> zoneNamesMap = extractZoneNames(targetMap, bundle.getID());
+                if (!zoneNamesMap.isEmpty() || bundle.isRoot()) {
+                    metaInfo.get("TimeZoneNames").add(toLanguageTag(bundle.getID()));
+                    bundleGenerator.generateBundle("util", "TimeZoneNames", bundle.getID(), true, zoneNamesMap, BundleType.TIMEZONE);
+                }
             }
             if (bundleTypes.contains(Bundle.Type.CALENDARDATA)) {
                 Map<String, Object> calendarDataMap = extractCalendarData(targetMap, bundle.getID());
                 if (!calendarDataMap.isEmpty() || bundle.isRoot()) {
                     metaInfo.get("CalendarData").add(toLanguageTag(bundle.getID()));
-                    bundleGenerator.generateBundle("util", "CalendarData", bundle.getID(), true, calendarDataMap, false);
+                    bundleGenerator.generateBundle("util", "CalendarData", bundle.getID(), true, calendarDataMap, BundleType.PLAIN);
                 }
             }
             if (bundleTypes.contains(Bundle.Type.FORMATDATA)) {
                 Map<String, Object> formatDataMap = extractFormatData(targetMap, bundle.getID());
                 // LocaleData.getAvailableLocales depends on having FormatData bundles around
                 if (!formatDataMap.isEmpty() || bundle.isRoot()) {
                     metaInfo.get("FormatData").add(toLanguageTag(bundle.getID()));
-                    bundleGenerator.generateBundle("text", "FormatData", bundle.getID(), true, formatDataMap, false);
+                    bundleGenerator.generateBundle("text", "FormatData", bundle.getID(), true, formatDataMap, BundleType.OPEN);
                 }
             }
+
             // For testing
             SortedSet<String> allLocales = new TreeSet<>();
             allLocales.addAll(metaInfo.get("CurrencyNames"));
             allLocales.addAll(metaInfo.get("LocaleNames"));
             allLocales.addAll(metaInfo.get("CalendarData"));

@@ -429,10 +442,11 @@
         static KeyComparator INSTANCE = new KeyComparator();
 
         private KeyComparator() {
         }
 
+        @Override
         public int compare(String o1, String o2) {
             int len1 = o1.length();
             int len2 = o2.length();
             if (!isDigit(o1.charAt(0)) && !isDigit(o2.charAt(0))) {
                 // Shorter string comes first unless either starts with a digit.

@@ -474,11 +488,30 @@
         }
         return currencyNames;
     }
 
     private static Map<String, Object> extractZoneNames(Map<String, Object> map, String id) {
-        return null;
+        Map<String, Object> names = new HashMap<>();
+        for (String tzid : handlerMetaZones.keySet()) {
+            String tzKey = TIMEZONE_ID_PREFIX + tzid;
+            Object data = map.get(tzKey);
+            if (data instanceof String[]) {
+                names.put(tzid, data);
+            } else {
+                String meta = handlerMetaZones.get(tzid);
+                if (meta != null) {
+                    String metaKey = METAZONE_ID_PREFIX + meta;
+                    data = map.get(metaKey);
+                    if (data instanceof String[]) {
+                        // Keep the metazone prefix here.
+                        names.put(metaKey, data);
+                        names.put(tzid, meta);
+                    }
+                }
+            }
+        }
+        return names;
     }
 
     private static Map<String, Object> extractCalendarData(Map<String, Object> map, String id) {
         Map<String, Object> calendarData = new LinkedHashMap<>();
         copyIfPresent(map, "firstDayOfWeek", calendarData);

@@ -492,15 +525,23 @@
             String prefix = calendarType.keyElementName();
             copyIfPresent(map, prefix + "MonthNames", formatData); // default FORMAT since JDK8
             copyIfPresent(map, prefix + "standalone.MonthNames", formatData);
             copyIfPresent(map, prefix + "MonthAbbreviations", formatData);
             copyIfPresent(map, prefix + "standalone.MonthAbbreviations", formatData);
+            copyIfPresent(map, prefix + "MonthNarrow", formatData);
+            copyIfPresent(map, prefix + "standalone.MonthNarrows", formatData);
             copyIfPresent(map, prefix + "DayNames", formatData);
+            copyIfPresent(map, prefix + "standalone.DayNames", formatData);
             copyIfPresent(map, prefix + "DayAbbreviations", formatData);
+            copyIfPresent(map, prefix + "standalone.DayAbbreviations", formatData);
+            copyIfPresent(map, prefix + "DayNarrows", formatData);
+            copyIfPresent(map, prefix + "standalone.DayNarrows", formatData);
             copyIfPresent(map, prefix + "AmPmMarkers", formatData);
+            copyIfPresent(map, prefix + "narrow.AmPmMarkers", formatData);
+            copyIfPresent(map, prefix + "long.Eras", formatData);
             copyIfPresent(map, prefix + "Eras", formatData);
-            copyIfPresent(map, prefix + "short.Eras", formatData);
+            copyIfPresent(map, prefix + "narrow.Eras", formatData);
             copyIfPresent(map, prefix + "TimePatterns", formatData);
             copyIfPresent(map, prefix + "DatePatterns", formatData);
             copyIfPresent(map, prefix + "DateTimePatterns", formatData);
             copyIfPresent(map, prefix + "DateTimePatternChars", formatData);
         }

@@ -558,11 +599,10 @@
             switch (aChar) {
             case ' ':
                 if (x == 0 || escapeSpace) {
                     outBuffer.append('\\');
                 }
-
                 outBuffer.append(' ');
                 break;
             case '\\':
                 outBuffer.append('\\');
                 outBuffer.append('\\');

@@ -582,11 +622,11 @@
             case '\f':
                 outBuffer.append('\\');
                 outBuffer.append('f');
                 break;
             default:
-                if (!USE_UTF8 && ((aChar < 0x0020) || (aChar > 0x007e))) {
+                if (aChar < 0x0020 || (!USE_UTF8 && aChar > 0x007e)) {
                     formatter.format("\\u%04x", (int)aChar);
                 } else {
                     if (specialSaveChars.indexOf(aChar) != -1) {
                         outBuffer.append('\\');
                     }