Skip to content

Commit

Permalink
CLDR-16720 json transliterator- improve format
Browse files Browse the repository at this point in the history
- hoist json content up 2 levels
- fix 'BGN' in path
  • Loading branch information
srl295 committed Sep 19, 2024
1 parent 2459840 commit 054ab28
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,6 @@ private int convertCldrItems(
}
// the value is now the raw filename
item.setValue(rawTransformFile);
item.setPath(
item.getPath()
.replaceAll("\\]/tRule.*$", "]/_rulesFile")
.replace("/transforms/", "/"));
item.setFullPath(
item.getFullPath()
.replaceAll("\\]/tRule.*$", "]/_rulesFile")
.replace("/transforms/", "/"));
}

// some items need to be split to multiple item before processing. None
Expand Down Expand Up @@ -970,7 +962,31 @@ private int convertCldrItems(
outputUnitPreferenceData(js, theItems, out, nodesForLastItem);
}

// closeNodes(out, nodesForLastItem.size() - 2, 0);
// Special processing for transforms.
if (type == RunType.transforms) {
final JsonObject jo = out.getAsJsonObject("transforms");
if (jo == null || jo.isEmpty()) {
throw new RuntimeException(
"Could not get transforms object in " + filename);
}
@SuppressWarnings("unchecked")
final Entry<String, JsonElement>[] s = jo.entrySet().toArray(new Entry[0]);
if (s == null || s.length != 1) {
throw new RuntimeException(
"Could not get 1 subelement of transforms in " + filename);
}
// key doesn't matter.
// move subitem up
out = s[0].getValue().getAsJsonObject();
final Entry<String, JsonElement>[] s2 =
out.entrySet().toArray(new Entry[0]);
if (s2 == null || s2.length != 1) {
throw new RuntimeException(
"Could not get 1 sub-subelement of transforms in " + filename);
}
// move sub-subitem up.
out = s2[0].getValue().getAsJsonObject();
}

// write JSON
try (PrintWriter outf = FileUtilities.openUTF8Writer(outputDir, outFilename)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@
> $1/$2$4

# Transform - drop terminal tRule element
< (.*)/tRule.*
> $1
< //supplementalData/transforms/transform(.*)/tRule.*$
> //supplementalData/transforms/transform$1/_rulesFile

0 comments on commit 054ab28

Please sign in to comment.