Skip to content

Commit

Permalink
CLDR-17459 Fixups for printing list, prefixable (#3688)
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati authored May 6, 2024
1 parent 5881198 commit f9f77ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1922,8 +1922,9 @@ public Set<UnitSystem> getSystemsEnum(String unit) {
main:
for (Map<String, Integer> unitsToPowers :
Arrays.asList(id.denUnitsToPowers, id.numUnitsToPowers)) {
for (String subunit : unitsToPowers.keySet()) {
subunit = UnitConverter.stripPrefix(subunit, null);
for (String rawSubunit : unitsToPowers.keySet()) {
String subunit = UnitConverter.stripPrefix(rawSubunit, null);

Set<UnitSystem> systems = new TreeSet<>(sourceToSystems.get(subunit));
if (systems.contains(UnitSystem.metric)) {
systems.add(UnitSystem.metric_adjacent);
Expand All @@ -1934,8 +1935,12 @@ public Set<UnitSystem> getSystemsEnum(String unit) {

if (result == null) {
result = systems; // first setting
if (!subunit.equals(rawSubunit)) {
result.remove(UnitSystem.prefixable);
}
} else {
result.retainAll(systems);
result.remove(UnitSystem.prefixable); // remove if more than one
}
if (result.isEmpty()) {
break main;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.ibm.icu.impl.Row.R3;
import com.ibm.icu.number.FormattedNumber;
import com.ibm.icu.number.LocalizedNumberFormatter;
import com.ibm.icu.number.Notation;
import com.ibm.icu.number.NumberFormatter;
import com.ibm.icu.number.NumberFormatter.UnitWidth;
import com.ibm.icu.number.Precision;
Expand Down Expand Up @@ -3544,7 +3545,7 @@ enum TranslationStatus {
has_grammar_X,
add_grammar,
skip_grammar,
skip_trans("\t— specific langs poss.)");
skip_trans("\tspecific langs poss.");

private TranslationStatus() {
outName = name();
Expand Down Expand Up @@ -3599,8 +3600,22 @@ public void TestUnitsToTranslate() {
: TranslationStatus.skip_grammar;
shortUnitToTranslationStatus40.put(shortUnit, status);
}
LocalizedNumberFormatter nf =
NumberFormatter.with()
.notation(Notation.scientific())
.precision(Precision.fixedSignificantDigits(7))
.locale(Locale.ENGLISH);
Output<String> base = new Output<>();
for (Entry<String, TranslationStatus> entry : shortUnitToTranslationStatus40.entrySet()) {
String shortUnit = entry.getKey();
var conversionInfo = converter.parseUnitId(shortUnit, base, false);
String factor =
conversionInfo == null || conversionInfo.special != null
? "n/a"
: nf.format(conversionInfo.factor.doubleValue())
.toString()
.replace("E", " × 10^");

TranslationStatus status40 = entry.getValue();
if (isVerbose())
System.out.println(
Expand All @@ -3610,6 +3625,8 @@ public void TestUnitsToTranslate() {
+ "\t"
+ converter.getSystemsEnum(shortUnit)
+ "\t"
+ factor
+ "\t"
+ (converter.isSimple(shortUnit) ? "simple" : "complex")
+ "\t"
+ status40);
Expand Down

0 comments on commit f9f77ba

Please sign in to comment.