Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-11535 Fixes incorrect spacing in currency examples #3976

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
package org.unicode.cldr.test;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.ibm.icu.impl.Row.R3;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.number.DecimalQuantity;
import com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.BreakIterator;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.DateFormatSymbols;
import com.ibm.icu.text.DateTimePatternGenerator;
import com.ibm.icu.text.DecimalFormat;
import com.ibm.icu.text.DecimalFormatSymbols;
import com.ibm.icu.text.ListFormatter;
import com.ibm.icu.text.MessageFormat;
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.text.PluralRules;
import com.ibm.icu.text.PluralRules.DecimalQuantitySamples;
import com.ibm.icu.text.PluralRules.DecimalQuantitySamplesRange;
import com.ibm.icu.text.PluralRules.Operand;
import com.ibm.icu.text.PluralRules.SampleType;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.text.SimpleFormatter;
import com.ibm.icu.text.UTF16;
import com.ibm.icu.text.UnicodeSet;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.Output;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.ULocale;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.ChoiceFormat;
Expand All @@ -47,6 +18,7 @@
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.unicode.cldr.tool.LikelySubtags;
import org.unicode.cldr.util.AnnotationUtil;
import org.unicode.cldr.util.CLDRConfig;
Expand Down Expand Up @@ -91,6 +63,36 @@
import org.unicode.cldr.util.personname.PersonNameFormatter.NamePattern;
import org.unicode.cldr.util.personname.SimpleNameObject;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.ibm.icu.impl.Row.R3;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.impl.number.DecimalQuantity;
import com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.BreakIterator;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.DateFormatSymbols;
import com.ibm.icu.text.DateTimePatternGenerator;
import com.ibm.icu.text.DecimalFormat;
import com.ibm.icu.text.DecimalFormatSymbols;
import com.ibm.icu.text.ListFormatter;
import com.ibm.icu.text.MessageFormat;
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.text.PluralRules;
import com.ibm.icu.text.PluralRules.DecimalQuantitySamples;
import com.ibm.icu.text.PluralRules.DecimalQuantitySamplesRange;
import com.ibm.icu.text.PluralRules.Operand;
import com.ibm.icu.text.PluralRules.SampleType;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.text.SimpleFormatter;
import com.ibm.icu.text.UTF16;
import com.ibm.icu.text.UnicodeSet;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.Output;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.ULocale;

/**
* Class to generate examples and help messages for the Survey tool (or console version).
*
Expand Down Expand Up @@ -2681,35 +2683,50 @@ private String handleCurrencyFormat(XPathParts parts, String value, boolean show

String numberSystem = parts.getAttributeValue(2, "numberSystem"); // null if not present

DecimalFormat df =
icuServiceBuilder.getCurrencyFormat(currency, currencySymbol, numberSystem);
df.applyPattern(value);

String countValue = parts.getAttributeValue(-1, "count");
if (countValue != null) {
DecimalFormat df =
icuServiceBuilder.getCurrencyFormat(currency, currencySymbol, numberSystem);
df.applyPattern(value);
return formatCountDecimal(df, countValue);
}

double sampleAmount = 1295.00;
example = addExampleResult(formatNumber(df, sampleAmount), example, showContexts);
example = addExampleResult(formatNumber(df, -sampleAmount), example, showContexts);

if (showContexts && !altAlpha) {
// If this example is not for alt="alphaNextToNumber", then if the currency symbol
// above has letters (strong dir) add another example with non-letter symbol
// (weak or neutral), or vice versa
if (symbolIsLetters(currencySymbol, false)) {
currency = "EUR";
checkPath = "//ldml/numbers/currencies/currency[@type=\"" + currency + "\"]/symbol";
currencySymbol = cldrFile.getWinningValue(checkPath);
} else {
currencySymbol = currency;
}
df = icuServiceBuilder.getCurrencyFormat(currency, currencySymbol, numberSystem);
df.applyPattern(value);
example = addExampleResult(formatNumber(df, sampleAmount), example, showContexts);
example = addExampleResult(formatNumber(df, -sampleAmount), example, showContexts);
String symbol_eur;
String symbol_usd;
boolean symbol_first = value.charAt(0) == '¤';
if (altAlpha) {
symbol_eur = "EUR";
symbol_usd = symbol_first ? "$USD" : "USD$";
}
else {
symbol_eur = "€";
symbol_usd = symbol_first ? "USD$" : "$USD";
}

String pattern_eur = value.replace("¤", symbol_eur);
String pattern_usd = value.replace("¤", symbol_usd);

DecimalFormat df_eur = icuServiceBuilder.getNumberFormat(pattern_eur, numberSystem);
DecimalFormat df_usd = icuServiceBuilder.getNumberFormat(pattern_usd, numberSystem);

double sampleAmount = 1295.00;
example = addExampleResult(formatNumber(df_eur, sampleAmount), example, showContexts);
example = addExampleResult(formatNumber(df_eur, -sampleAmount), example, showContexts);
example = addExampleResult(formatNumber(df_usd, sampleAmount), example, showContexts);
example = addExampleResult(formatNumber(df_usd, -sampleAmount), example, showContexts);

DecimalFormat df = icuServiceBuilder.getCurrencyFormat(currency, "¤", numberSystem);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing "¤" is ugly but seems to work since it is not one of the characters that triggers space insertion

df.applyPattern(value);
example =
addExampleResult(
formatNumber(df, sampleAmount).replace("¤", currencySymbol),
example,
showContexts);
example =
addExampleResult(
formatNumber(df, -sampleAmount).replace("¤", currencySymbol),
example,
showContexts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do things stand with this draft PR? it adds more examples, using df_eur and df_usd...

@srl295 I see you made a more recent commit (91e1079) to this method: it returned String but is now void and ends with examples.add(example)

Emiyare also made a more recent commit (00e1fc2) inserting a few lines into this method. It looks like the old changes could be wrapped into the current code fairly easy but not just by rebasing...


return example;
}
Expand Down