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..3c2ab1dfe3a 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,30 @@ 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 +2335,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..e1eb03ec4e1 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 @@ -289,6 +289,8 @@ public static class SplittableAttributeSpec { new SplittableAttributeSpec("parentLocale", "locales", "parent"), new SplittableAttributeSpec( "collations", "locales", "parent"), // parentLocale component=collations + new SplittableAttributeSpec( + "plurals", "locales", "parent"), // parentLocale component=plurals new SplittableAttributeSpec( "segmentations", "locales", "parent"), // parentLocale component=segmentations new SplittableAttributeSpec("hours", "regions", null), @@ -298,6 +300,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. */