Skip to content

Commit

Permalink
CLDR-17176 json: add _type to zone types (#4342)
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 authored Feb 6, 2025
1 parent f461b19 commit 2e3e0a0
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ private int convertCldrItems(
}
}
}
postprocessAfterAdd(out, item);
}

resolveSortingItems(out, nodesForLastItem, sortingItems);
Expand Down Expand Up @@ -1045,6 +1046,43 @@ private int convertCldrItems(
return totalItemsInFile;
}

/**
* Provide an opportunity to fix up the JsonObject before write, after items were added.
*
* @param out the JsonObject which already reflects 'item'
* @param item the original CLDR item
*/
private void postprocessAfterAdd(JsonObject out, CldrItem item) {
if (item.getUntransformedPath().contains("timeZoneNames/zone")) {
// add _type values into the time zone tree
try {
JsonObject sub = out;
for (final CldrNode n : item.getNodesInPath()) {
if (n.getNodeKeyName().equals("cldr")) {
continue; // skip the top 'cldr' node
}
if (!n.getName().equals("zone") && n.getParent().equals("zone")) {
// child of zone, but not a zone - add the type.
sub.addProperty("_type", "zone");
break;
} else {
JsonElement je = sub.get(n.getNodeKeyName());
if (je == null) {
// then add it! Because we run before the sorting,
// we can run where the parent isn't added yet.
je = new JsonObject();
sub.add(n.getNodeKeyName(), je);
}
sub = je.getAsJsonObject(); // traverse into the JSON DOM..
}
}
} catch (ParseException e) {
System.err.println("Error adding _type in tree for " + item.getUntransformedPath());
e.printStackTrace();
}
}
}

/**
* Fixup an XPathParts with a specific transform element
*
Expand Down

0 comments on commit 2e3e0a0

Please sign in to comment.