Skip to content

Commit

Permalink
CLDR-11155 Pages too big: further divisions for Volume, Units
Browse files Browse the repository at this point in the history
-Divide Volume Other into Volume US and VolumeOther

-Divide Other Units into Other Units, Other Units Per, Other Units USm abd Other Units Misc

-New subroutines getOtherUnitsPageId, isSystemUnit, getShortUnitId
  • Loading branch information
btangmu committed Apr 3, 2024
1 parent e35d89c commit cd4ca7b
Showing 1 changed file with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public enum PageId {
Length(SectionId.Units),
Area(SectionId.Units),
Volume_Metric(SectionId.Units, "Volume Metric"),
Volume_US(SectionId.Units, "Volume US"),
Volume_Other(SectionId.Units, "Volume Other"),
SpeedAcceleration(SectionId.Units, "Speed and Acceleration"),
MassWeight(SectionId.Units, "Mass and Weight"),
Expand All @@ -241,6 +242,9 @@ public enum PageId {
Digital(SectionId.Units),
Coordinates(SectionId.Units),
OtherUnits(SectionId.Units, "Other Units"),
OtherUnitsPer(SectionId.Units, "Other Units Per"),
OtherUnitsUS(SectionId.Units, "Other Units US"),
OtherUnitsMisc(SectionId.Units, "Other Units Misc"),
CompoundUnits(SectionId.Units, "Compound Units"),

Displaying_Lists(SectionId.Misc, "Displaying Lists"),
Expand Down Expand Up @@ -2241,6 +2245,8 @@ private static String fix(String input, int orderIn) {
if (functionStart < 0) {
if ("Volume".equals(input)) {
return getVolumePageId(args.value[0] /* path */).toString();
} else if ("Other Units".equals(input)) {
return getOtherUnitsPageId(args.value[0] /* path */).toString();
}
return input;
}
Expand All @@ -2262,10 +2268,40 @@ private static String fix(String input, int orderIn) {
}
}

private static Set<UnitConverter.UnitSystem> METRIC =
private static Set<UnitConverter.UnitSystem> METRIC_UNITS =
Set.of(UnitConverter.UnitSystem.metric, UnitConverter.UnitSystem.metric_adjacent);

private static Set<UnitConverter.UnitSystem> US_UNITS =
Set.of(UnitConverter.UnitSystem.ussystem);

private static PageId getVolumePageId(String path) {
final String shortUnitId = getShortUnitId(path);
if (isSystemUnit(shortUnitId, METRIC_UNITS)) {
return PageId.Volume_Metric;
} else {
return isSystemUnit(shortUnitId, US_UNITS) ? PageId.Volume_US : PageId.Volume_Other;
}
}

private static PageId getOtherUnitsPageId(String path) {
String shortUnitId = getShortUnitId(path);
if (isSystemUnit(shortUnitId, METRIC_UNITS)) {
return shortUnitId.contains("per") ? PageId.OtherUnitsPer : PageId.OtherUnits;
} else {
return isSystemUnit(shortUnitId, US_UNITS)
? PageId.OtherUnitsUS
: PageId.OtherUnitsMisc;
}
}

private static boolean isSystemUnit(
String shortUnitId, Set<UnitConverter.UnitSystem> system) {
final UnitConverter uc = supplementalDataInfo.getUnitConverter();
final Set<UnitConverter.UnitSystem> systems = uc.getSystemsEnum(shortUnitId);
return !Collections.disjoint(system, systems);
}

private static String getShortUnitId(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
Expand All @@ -2276,12 +2312,7 @@ private static PageId getVolumePageId(String 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;
}
return uc.getShortId(longUnitId);
}

/**
Expand Down

0 comments on commit cd4ca7b

Please sign in to comment.