Skip to content

Commit

Permalink
CLDR-17367 v45 JSON: improve localeRules processing (#3611)
Browse files Browse the repository at this point in the history
(cherry picked from commit fc51e78)
  • Loading branch information
srl295 authored and pedberg-icu committed Apr 22, 2024
1 parent d6fdabd commit bfb4982
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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. */
Expand Down

0 comments on commit bfb4982

Please sign in to comment.