From e23975385836c77c0913b83761ba3feec50b7f83 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 5 Feb 2025 12:26:33 -0600 Subject: [PATCH] CLDR-17176 json: add _type to zone types - add _type:zone to all actual zones in the tree - refactor: add a new hook function postprocessAfterAdd() to add this kind of fixup --- .../unicode/cldr/json/Ldml2JsonConverter.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java b/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java index b9f0a65cb92..11dfc45044c 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java @@ -966,6 +966,7 @@ private int convertCldrItems( } } } + postprocessAfterAdd(out, item); } resolveSortingItems(out, nodesForLastItem, sortingItems); @@ -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 *