Skip to content

Commit

Permalink
CLDR-11155 Separate Volume_Metric and Volume_Other
Browse files Browse the repository at this point in the history
-New subroutines makePathHeader and getVolumePageId

-Change example in Dashboard.java from Volume to Area

-Comments
  • Loading branch information
btangmu authored and Squash Bot committed Feb 27, 2024
1 parent 1259519 commit 8215021
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static final class ReviewNotificationGroup {
@Schema(description = "SurveyTool section", example = "Units")
public String section;

@Schema(description = "SurveyTool page", example = "Volume")
@Schema(description = "SurveyTool page", example = "Area")
public String page;

@Schema(description = "SurveyTool header", example = "dessert-spoon-imperial")
Expand Down
73 changes: 53 additions & 20 deletions tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,8 @@ public enum PageId {
Graphics(SectionId.Units),
Length(SectionId.Units),
Area(SectionId.Units),
Volume(SectionId.Units),
// TODO: enable splitting Volume into Volume/Volume2
// Reference: https://unicode-org.atlassian.net/browse/CLDR-11155
// Volume2(SectionId.Units),
Volume_Metric(SectionId.Units, "Volume Metric"),
Volume_Other(SectionId.Units, "Volume Other"),
SpeedAcceleration(SectionId.Units, "Speed and Acceleration"),
MassWeight(SectionId.Units, "Mass and Weight"),
EnergyPower(SectionId.Units, "Energy and Power"),
Expand Down Expand Up @@ -721,20 +719,7 @@ public PathHeader fromPath(final String path, List<String> failures) {
samples.put(data, cleanPath);
}
try {
PathHeader result =
new PathHeader(
SectionId.forString(fix(data.section, 0)),
PageId.forString(fix(data.page, 0)),
fix(data.header, data.headerOrder),
(int) order, // only valid after call to fix. TODO, make
// this cleaner
fix(
data.code + (alt == null ? "" : ("-" + alt)),
data.codeOrder),
order, // only valid after call to fix
suborder,
data.status,
path);
PathHeader result = makePathHeader(data, path, alt);
synchronized (cache) {
PathHeader old = cache.get(path);
if (old == null) {
Expand Down Expand Up @@ -766,6 +751,56 @@ public PathHeader fromPath(final String path, List<String> failures) {
}
}

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);
}
String newHeader = fix(data.header, data.headerOrder);
int newHeaderOrder = (int) order;
String codeDashAlt = data.code + (alt == null ? "" : ("-" + alt));
String newCode = fix(codeDashAlt, data.codeOrder);
long newCodeOrder = order;
return new PathHeader(
newSectionId,
newPageId,
newHeader,
newHeaderOrder,
newCode,
newCodeOrder,
suborder,
data.status,
path);
}

private static Set<UnitConverter.UnitSystem> 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<SectionPage> {
private final SectionId sectionId;
private final PageId pageId;
Expand Down Expand Up @@ -2476,8 +2511,6 @@ private static PageId getCharacterPageId(String cp) {
if (pageId == null) {
throw new InternalCldrException("Failure getting character page id");
}
// TODO: enable splitting Volume into Volume/Volume2, starting Volume2 at "acre-foot"
// Reference: https://unicode-org.atlassian.net/browse/CLDR-11155
return pageId;
}

Expand Down

0 comments on commit 8215021

Please sign in to comment.