< prev index next >
make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java
Print this page
rev 57965 : 8234347: "Turkey" meta time zone does not generate composed localized names
8236548: Localized time zone name inconsistency between English and other locales
Reviewed-by:
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -23,11 +23,10 @@
* questions.
*/
package build.tools.cldrconverter;
-import static build.tools.cldrconverter.Bundle.jreTimeZoneNames;
import build.tools.cldrconverter.BundleGenerator.BundleType;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.*;
@@ -87,11 +86,42 @@
static final String TIMEZONE_ID_PREFIX = "timezone.id.";
static final String EXEMPLAR_CITY_PREFIX = "timezone.excity.";
static final String ZONE_NAME_PREFIX = "timezone.displayname.";
static final String METAZONE_ID_PREFIX = "metazone.id.";
static final String PARENT_LOCALE_PREFIX = "parentLocale.";
+ static final String META_EMPTY_ZONE_NAME = "EMPTY_ZONE";
static final String[] EMPTY_ZONE = {"", "", "", "", "", ""};
+ static final String META_ETCUTC_ZONE_NAME = "ETC_UTC";
+
+ // Old 3-letter-id mappings for compatibility. Copied from sun.util.calendar.ZoneInfoFile.
+ private static final String[][] oldMappings = new String[][] {
+ { "ACT", "Australia/Darwin" },
+ { "AET", "Australia/Sydney" },
+ { "AGT", "America/Argentina/Buenos_Aires" },
+ { "ART", "Africa/Cairo" },
+ { "AST", "America/Anchorage" },
+ { "BET", "America/Sao_Paulo" },
+ { "BST", "Asia/Dhaka" },
+ { "CAT", "Africa/Harare" },
+ { "CNT", "America/St_Johns" },
+ { "CST", "America/Chicago" },
+ { "CTT", "Asia/Shanghai" },
+ { "EAT", "Africa/Addis_Ababa" },
+ { "ECT", "Europe/Paris" },
+ { "IET", "America/Indiana/Indianapolis" },
+ { "IST", "Asia/Kolkata" },
+ { "JST", "Asia/Tokyo" },
+ { "MIT", "Pacific/Apia" },
+ { "NET", "Asia/Yerevan" },
+ { "NST", "Pacific/Auckland" },
+ { "PLT", "Asia/Karachi" },
+ { "PNT", "America/Phoenix" },
+ { "PRT", "America/Puerto_Rico" },
+ { "PST", "America/Los_Angeles" },
+ { "SST", "Pacific/Guadalcanal" },
+ { "VST", "Asia/Ho_Chi_Minh" },
+ };
private static SupplementDataParseHandler handlerSuppl;
private static LikelySubtagsParseHandler handlerLikelySubtags;
private static WinZonesParseHandler handlerWinZones;
static PluralsParseHandler handlerPlurals;
@@ -684,72 +714,25 @@
}
private static Map<String, Object> extractZoneNames(Map<String, Object> map, String id) {
Map<String, Object> names = new HashMap<>();
- // Copy over missing time zone ids from JRE for English locale
- if (id.equals("en")) {
- Map<String[], String> jreMetaMap = new HashMap<>();
- jreTimeZoneNames.stream().forEach(e -> {
- String tzid = (String)e[0];
- String[] data = (String[])e[1];
-
- if (map.get(TIMEZONE_ID_PREFIX + tzid) == null &&
- handlerMetaZones.get(tzid) == null ||
- handlerMetaZones.get(tzid) != null &&
- map.get(METAZONE_ID_PREFIX + handlerMetaZones.get(tzid)) == null) {
-
- // First, check the alias
- String canonID = canonicalTZMap.get(tzid);
- if (canonID != null && !tzid.equals(canonID)) {
- Object value = map.get(TIMEZONE_ID_PREFIX + canonID);
- if (value != null) {
- names.put(tzid, value);
- return;
- } else {
- String meta = handlerMetaZones.get(canonID);
- if (meta != null) {
- value = map.get(METAZONE_ID_PREFIX + meta);
- if (value != null) {
- names.put(tzid, meta);
- return;
- }
- }
- }
- }
-
- // Check the CLDR meta key
- Optional<Map.Entry<String, String>> cldrMeta =
- handlerMetaZones.getData().entrySet().stream()
- .filter(me ->
- Arrays.deepEquals(data,
- (String[])map.get(METAZONE_ID_PREFIX + me.getValue())))
- .findAny();
- cldrMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> {
- // Check the JRE meta key, add if there is not.
- Optional<Map.Entry<String[], String>> jreMeta =
- jreMetaMap.entrySet().stream()
- .filter(jm -> Arrays.deepEquals(data, jm.getKey()))
- .findAny();
- jreMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> {
- String metaName = "JRE_" + tzid.replaceAll("[/-]", "_");
- names.put(METAZONE_ID_PREFIX + metaName, data);
- names.put(tzid, metaName);
- });
- });
- }
- });
- }
-
getAvailableZoneIds().stream().forEach(tzid -> {
// If the tzid is deprecated, get the data for the replacement id
String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid))
.orElse(tzid);
Object data = map.get(TIMEZONE_ID_PREFIX + tzKey);
if (data instanceof String[]) {
+ // Hack for UTC. UTC is an alias to Etc/UTC in CLDR
+ if (tzid.equals("Etc/UTC") && !map.containsKey(TIMEZONE_ID_PREFIX + "UTC")) {
+ names.put(METAZONE_ID_PREFIX + META_ETCUTC_ZONE_NAME, data);
+ names.put(tzid, META_ETCUTC_ZONE_NAME);
+ names.put("UTC", META_ETCUTC_ZONE_NAME);
+ } else {
names.put(tzid, data);
+ }
} else {
String meta = handlerMetaZones.get(tzKey);
if (meta != null) {
String metaKey = METAZONE_ID_PREFIX + meta;
data = map.get(metaKey);
@@ -763,27 +746,26 @@
});
// exemplar cities.
Map<String, Object> exCities = map.entrySet().stream()
.filter(e -> e.getKey().startsWith(CLDRConverter.EXEMPLAR_CITY_PREFIX))
- .collect(Collectors
- .toMap(Map.Entry::getKey, Map.Entry::getValue));
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
names.putAll(exCities);
- if (!id.equals("en") &&
- !names.isEmpty()) {
- // CLDR does not have UTC entry, so add it here.
- names.put("UTC", EMPTY_ZONE);
-
- // no metazone zones
- Arrays.asList(handlerMetaZones.get(MetaZonesParseHandler.NO_METAZONE_KEY)
- .split("\\s")).stream()
- .forEach(tz -> {
- names.put(tz, EMPTY_ZONE);
- });
+ // If there's no UTC entry at this point, add an empty one
+ if (!names.isEmpty() && !names.containsKey("UTC")) {
+ names.putIfAbsent(METAZONE_ID_PREFIX + META_EMPTY_ZONE_NAME, EMPTY_ZONE);
+ names.put("UTC", META_EMPTY_ZONE_NAME);
}
+ // Finally some compatibility stuff
+ Arrays.stream(oldMappings)
+ .filter(oldmap -> !names.containsKey(oldmap[0]) && names.containsKey(oldmap[1]))
+ .forEach(oldmap -> {
+ names.put(oldmap[0], names.get(oldmap[1]));
+ });
+
return names;
}
/**
* Extracts the language independent calendar data. Each of the two keys,
< prev index next >