Skip to content

Commit 2e3e0a0

Browse files
authored
CLDR-17176 json: add _type to zone types (#4342)
1 parent f461b19 commit 2e3e0a0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ private int convertCldrItems(
966966
}
967967
}
968968
}
969+
postprocessAfterAdd(out, item);
969970
}
970971

971972
resolveSortingItems(out, nodesForLastItem, sortingItems);
@@ -1045,6 +1046,43 @@ private int convertCldrItems(
10451046
return totalItemsInFile;
10461047
}
10471048

1049+
/**
1050+
* Provide an opportunity to fix up the JsonObject before write, after items were added.
1051+
*
1052+
* @param out the JsonObject which already reflects 'item'
1053+
* @param item the original CLDR item
1054+
*/
1055+
private void postprocessAfterAdd(JsonObject out, CldrItem item) {
1056+
if (item.getUntransformedPath().contains("timeZoneNames/zone")) {
1057+
// add _type values into the time zone tree
1058+
try {
1059+
JsonObject sub = out;
1060+
for (final CldrNode n : item.getNodesInPath()) {
1061+
if (n.getNodeKeyName().equals("cldr")) {
1062+
continue; // skip the top 'cldr' node
1063+
}
1064+
if (!n.getName().equals("zone") && n.getParent().equals("zone")) {
1065+
// child of zone, but not a zone - add the type.
1066+
sub.addProperty("_type", "zone");
1067+
break;
1068+
} else {
1069+
JsonElement je = sub.get(n.getNodeKeyName());
1070+
if (je == null) {
1071+
// then add it! Because we run before the sorting,
1072+
// we can run where the parent isn't added yet.
1073+
je = new JsonObject();
1074+
sub.add(n.getNodeKeyName(), je);
1075+
}
1076+
sub = je.getAsJsonObject(); // traverse into the JSON DOM..
1077+
}
1078+
}
1079+
} catch (ParseException e) {
1080+
System.err.println("Error adding _type in tree for " + item.getUntransformedPath());
1081+
e.printStackTrace();
1082+
}
1083+
}
1084+
}
1085+
10481086
/**
10491087
* Fixup an XPathParts with a specific transform element
10501088
*

0 commit comments

Comments
 (0)