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 5619daf82a5..1fdb3b0b60b 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 @@ -1855,7 +1855,27 @@ private JsonElement startNonleafNode(JsonElement out, final CldrNode node) throw o.getAsJsonObject().addProperty(attrAsKey, v); } // else, omit } else { - o.getAsJsonObject().addProperty(attrAsKey, value); + // hack for localeRules + if (attrAsKey.equals("_localeRules")) { + // find the _localeRules object, add if it didn't exist + JsonElement localeRules = out.getAsJsonObject().get(attrAsKey); + if (localeRules == null) { + localeRules = new JsonObject(); + out.getAsJsonObject().add(attrAsKey, localeRules); + } + // find the sibling object, add if it did't exist ( this will be parentLocale or collations etc.) + JsonElement sibling = localeRules.getAsJsonObject().get(name); + if (sibling == null) { + sibling = new JsonObject(); + localeRules.getAsJsonObject().add(name, sibling); + } + // get the 'parent' attribute, which wil be the value + final String parent = XPathParts.getFrozenInstance(node.getUntransformedPath()).getAttributeValue(-1, "parent"); + // finally, we add something like "nonLikelyScript: und" + sibling.getAsJsonObject().addProperty(value, parent); + } else { + o.getAsJsonObject().addProperty(attrAsKey, value); + } } } return o; @@ -2312,7 +2332,9 @@ private void writeLeafNode( String attrValue = escapeValue(rawAttrValue); // attribute is prefixed with "_" when being used as key. String attrAsKey = "_" + key; - logger.finest(() -> "Leaf Node: " + node.getUntransformedPath() + " ." + key); + if (node != null) { + logger.finest(() -> "Leaf Node: " + node.getUntransformedPath() + " ." + key); + } if (LdmlConvertRules.ATTRVALUE_AS_ARRAY_SET.contains(key)) { String[] strings = attrValue.trim().split("\\s+"); JsonArray a = new JsonArray(); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/json/LdmlConvertRules.java b/tools/cldr-code/src/main/java/org/unicode/cldr/json/LdmlConvertRules.java index b2e839a4310..ea3ed6f13dd 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/json/LdmlConvertRules.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/json/LdmlConvertRules.java @@ -288,9 +288,13 @@ public static class SplittableAttributeSpec { new SplittableAttributeSpec("paperSize", "territories", "type"), new SplittableAttributeSpec("parentLocale", "locales", "parent"), new SplittableAttributeSpec( - "collations", "locales", "parent"), // parentLocale component=collations + "collations", "locales", "parent"), // parentLocale component=collations new SplittableAttributeSpec( - "segmentations", "locales", "parent"), // parentLocale component=segmentations + "grammaticalFeatures", "locales", "parent"), // parentLocale component=grammaticalFeatures + new SplittableAttributeSpec( + "plurals", "locales", "parent"), // parentLocale component=plurals + new SplittableAttributeSpec( + "segmentations", "locales", "parent"), // parentLocale component=segmentations new SplittableAttributeSpec("hours", "regions", null), new SplittableAttributeSpec("dayPeriodRules", "locales", null), // new SplittableAttributeSpec("group", "contains", "group"), @@ -298,6 +302,8 @@ public static class SplittableAttributeSpec { new SplittableAttributeSpec("unitPreference", "regions", null), new SplittableAttributeSpec("grammaticalFeatures", "locales", null), new SplittableAttributeSpec("grammaticalDerivations", "locales", null), + // this will cause EMPTY parentLocales elements to work properly + new SplittableAttributeSpec("parentLocales", "component", ""/* Not null */), }; /** The set that contains all timezone type of elements. */