Skip to content

Commit

Permalink
CLDR-13935 Add ST examples for minimumGroupingDigits (unicode-org#3731)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedberg-icu authored May 20, 2024
1 parent 8118765 commit cb4a18a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ private String constructExampleHtml(String xpath, String value, boolean nonTrivi
result = handleDecimalFormat(parts, value, showContexts);
}
}
} else if (parts.contains("minimumGroupingDigits")) {
result = handleMinimumGrouping(parts, value);
} else if (parts.getElement(2).contains("symbols")) {
result = handleNumberSymbol(parts, value);
} else if (parts.contains("defaultNumberingSystem")
Expand Down Expand Up @@ -2145,6 +2147,26 @@ public String countAttribute(Count count) {
return "[@count=\"" + count + "\"]";
}

private String handleMinimumGrouping(XPathParts parts, String value) {
String numberSystem = cldrFile.getWinningValue("//ldml/numbers/defaultNumberingSystem");
String checkPath =
"//ldml/numbers/decimalFormats[@numberSystem=\""
+ numberSystem
+ "\"]/decimalFormatLength/decimalFormat[@type=\"standard\"]/pattern[@type=\"standard\"]";
String decimalFormat = cldrFile.getWinningValue(checkPath);
DecimalFormat numberFormat = icuServiceBuilder.getNumberFormat(decimalFormat, numberSystem);
numberFormat.setMinimumGroupingDigits(Integer.parseInt(value));

double sampleNum1 = 543.21;
double sampleNum2 = 6543.21;
double sampleNum3 = 76543.21;
String example = "";
example = addExampleResult(formatNumber(numberFormat, sampleNum1), example);
example = addExampleResult(formatNumber(numberFormat, sampleNum2), example);
example = addExampleResult(formatNumber(numberFormat, sampleNum3), example);
return example;
}

private String handleNumberSymbol(XPathParts parts, String value) {
String symbolType = parts.getElement(-1);
String numberSystem = parts.getAttributeValue(2, "numberSystem"); // null if not present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,21 @@ public void TestDateTimeComboFormats() {
"//ldml/dates/calendars/calendar[@type=\"gregorian\"]/dateTimeFormats/dateTimeFormatLength[@type=\"long\"]/dateTimeFormat[@type=\"atTime\"]/pattern[@type=\"standard\"]");
}

public void TestMinimumGroupingExamples() {
ExampleGenerator exampleGeneratorEn = getExampleGenerator("en"); // min grouping 1
ExampleGenerator exampleGeneratorEs = getExampleGenerator("es"); // min grouping 2
checkValue(
"MinimumGrouping en: 1",
"〖❬543.21❭〗〖❬6,543❭.❬21❭〗〖❬76,543❭.❬21❭〗",
exampleGeneratorEn,
"//ldml/numbers/minimumGroupingDigits");
checkValue(
"MinimumGrouping es: 2",
"〖❬543,21❭〗〖❬6543,21❭〗〖❬76.543❭,❬21❭〗",
exampleGeneratorEs,
"//ldml/numbers/minimumGroupingDigits");
}

public void TestSymbols() {
CLDRFile english = info.getEnglish();
ExampleGenerator exampleGenerator = new ExampleGenerator(english, english);
Expand Down

0 comments on commit cb4a18a

Please sign in to comment.