diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java index 6f067d08952..81bf09fa80e 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java @@ -755,13 +755,7 @@ private PathHeader makePathHeader(RawData data, String path, String alt) { // Caution: each call to PathHeader.Factory.fix changes the value of // PathHeader.Factory.order SectionId newSectionId = SectionId.forString(fix(data.section, 0)); - String pageIdName = fix(data.page, 0); - PageId newPageId; - if ("Volume".equals(pageIdName)) { - newPageId = getVolumePageId(path); - } else { - newPageId = PageId.forString(pageIdName); - } + PageId newPageId = PageId.forString(fix(data.page, 0)); String newHeader = fix(data.header, data.headerOrder); int newHeaderOrder = (int) order; String codeDashAlt = data.code + (alt == null ? "" : ("-" + alt)); @@ -779,28 +773,6 @@ private PathHeader makePathHeader(RawData data, String path, String alt) { path); } - private static Set METRIC = - Set.of(UnitConverter.UnitSystem.metric, UnitConverter.UnitSystem.metric_adjacent); - - private PageId getVolumePageId(String path) { - // Extract the unit from the path. For example, if path is - // //ldml/units/unitLength[@type="narrow"]/unit[@type="volume-cubic-kilometer"]/displayName - // then extract "volume-cubic-kilometer" which is the long unit id - final String longUnitId = - XPathParts.getFrozenInstance(path).findAttributeValue("unit", "type"); - if (longUnitId == null) { - throw new RuntimeException("Missing unit in path " + path); - } - final UnitConverter uc = supplementalDataInfo.getUnitConverter(); - // Convert, for example, "volume-cubic-kilometer" to "cubic-kilometer" - final String shortUnitId = uc.getShortId(longUnitId); - if (!Collections.disjoint(METRIC, uc.getSystemsEnum(shortUnitId))) { - return PageId.Volume_Metric; - } else { - return PageId.Volume_Other; - } - } - private static class SectionPage implements Comparable { private final SectionId sectionId; private final PageId pageId; @@ -2267,6 +2239,9 @@ private static String fix(String input, int orderIn) { while (true) { int functionStart = input.indexOf('&', pos); if (functionStart < 0) { + if ("Volume".equals(input)) { + return getVolumePageId(args.value[0] /* path */).toString(); + } return input; } int functionEnd = input.indexOf('(', functionStart); @@ -2287,6 +2262,28 @@ private static String fix(String input, int orderIn) { } } + private static Set METRIC = + Set.of(UnitConverter.UnitSystem.metric, UnitConverter.UnitSystem.metric_adjacent); + + private static PageId getVolumePageId(String path) { + // Extract the unit from the path. For example, if path is + // //ldml/units/unitLength[@type="narrow"]/unit[@type="volume-cubic-kilometer"]/displayName + // then extract "volume-cubic-kilometer" which is the long unit id + final String longUnitId = + XPathParts.getFrozenInstance(path).findAttributeValue("unit", "type"); + if (longUnitId == null) { + throw new InternalCldrException("Missing unit in path " + path); + } + final UnitConverter uc = supplementalDataInfo.getUnitConverter(); + // Convert, for example, "volume-cubic-kilometer" to "cubic-kilometer" + final String shortUnitId = uc.getShortId(longUnitId); + if (!Collections.disjoint(METRIC, uc.getSystemsEnum(shortUnitId))) { + return PageId.Volume_Metric; + } else { + return PageId.Volume_Other; + } + } + /** * Collect all the paths for a CLDRFile, and make sure that they have cached PathHeaders *