Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17176 json: add _type to zone types #4342

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading