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-17367 v45 JSON: improve localeRules processing #3611

Merged
Show file tree
Hide file tree
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 @@ -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
Loading