Monday, May 26, 2014

Re: NumberFormat.setForcedLatinDigits

Up?

On Tuesday, May 6, 2014 1:29:38 PM UTC+4, Denis Dzenskevich wrote:
Hello,

There is a method NumberFormat.setForcedLatinDigits, according to javadoc it should
   * Specify whether all new NumberFormat instances will use latin digits
   * and related characters rather than the localized ones.

I faced with an issue that under Russian locale, it doesn't replace decimal separator: NumberFormats created afterwards, continue to use locale-specific comma instead of latin dot.

In code, it tries to replace it:
  protected static NumberConstants createLatinNumberConstants(
     
final NumberConstants orig) {
   
final String groupingSeparator = remapSeparator(
        orig
.groupingSeparator());
   
final String decimalSeparator = remapSeparator(
        orig
.decimalSeparator());
   
final String monetaryGroupingSeparator = remapSeparator(
        orig
.monetaryGroupingSeparator());
   
final String monetarySeparator = remapSeparator(
        orig
.monetarySeparator());
   
...


But it uses the same function
  protected static String remapSeparator(String separator) {
   
char ch = separator.length() > 0 ? separator.charAt(0) : 0xFFFF;
   
if (LOCALIZED_DOT_EQUIVALENTS.indexOf(ch) >= 0) {
     
return ".";
   
}
   
if (LOCALIZED_COMMA_EQUIVALENTS.indexOf(ch) >= 0) {
     
return ",";
   
}
   
return "\u00A0";
 
}

to replace both grouping and decimal separator (and also monetary grouping and monetary decimal).
This approach doesn't work well if e. g. one locale has comma as decimal separator and another one has comma as grouping separator.

Also, there are test cases in GWT that asserts (probably mistakenly) that comma should be preserved (com.google.gwt.i18n.client.NumberFormat_fr_Test and NumberFormat_ar_Test).
  public void testForceLatin() {
    assertFalse
(NumberFormat.forcedLatinDigits());
   
NumberFormat.setForcedLatinDigits(true);
    assertTrue
(NumberFormat.forcedLatinDigits());
   
NumberFormat decLatin = NumberFormat.getDecimalFormat();
    assertEquals
("1\u00A0003,14", decLatin.format(1003.14));
    assertEquals
("-1\u00A0003,14", decLatin.format(-1003.14));
   
NumberFormat.setForcedLatinDigits(false);
    assertFalse
(NumberFormat.forcedLatinDigits());
    assertEquals
("3,14", decLatin.format(3.14));
   
NumberFormat unforced = NumberFormat.getDecimalFormat();
    assertEquals
("3,14", unforced.format(3.14));
 
}

So what's the expected behavior here? Should setForcedLatinDigits always force latin decimal separator?
And if yes, why this complex logic to remapSeparator is used instead of simply returning '.' as decimal separator?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment