-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Intl.NumberFormat currency symbols are inaccurate when dealing with different types of dollars/$. #2778
Comments
(Pardon the lengthy reply but I'm using this as an opportunity to do some research as well as answer your question.) These details are typically (almost entirely) implemented as data and algorithms in an internationalization API. On Windows (Chakra, ChakraCore, and Edge) we use Windows Globalization for this. I'm working on enabling ChakraCore to use ICU instead (which is the library used by Chrome's v8 engine and Node.js, and may also be what is used for Firefox). This work will also enable Intl to work on Linux and OSX where the Windows Globalization libraries are obviously not available. So the above would explain why all of the others are the same. As for whether it should be considered a bug for the purposes of the ChakraCore issue tracker -- unfortunately, it's essentially an External issue (depends on libraries outside of ChakraCore). I think I'll leave this open for now and will probably close it at a time no later than when ICU support is enabled. That's the best we can do here. As for why we might be different from them (as a matter of philosophy of implementation, rather than the technical difference in library): strings which are output from Intl functions are, by spec, not intended to be parsed by a program or read in any other way except as displayed to an end user. These strings are meant to communicate information in a way which will be familiar and useful for users in various locales. As a matter of implementation, Windows Globalization may have felt this is a better way to provide the information. Clearly it's a "compatibility" issue for anyone who tries to parse these strings, but the Intl spec is deliberately non-specific about how to format things because what constitutes "familiar and useful" is, to some extent, a matter of opinion. Although, there will be some cases where it is actually incorrect (or uncomfortable, unreadable, unusable, etc.). "Accurate" however, is at a minimum, a matter of taste -- but I would suggest that actually the information conveyed in this case is, in fact, accurate, if you leave aside implementation differences and different degrees of information. As you can imagine, the databases comprising data for all locales are huge (lots of combinations of languages, countries, scripts, and so on). It's possible there is a bug, but it's also possible that a decision was deliberately made for this particular locale and format specification to display the way it does in Edge. For example, the As for whether a particular developer or user should consider such a difference to be a bug can be answered by whether the string makes sense and communicates the necessary information without unnecessary confusion. Here's my opinion on these outputs: I think in all cases, the output string is clear. As for which one is better, it depends on your perspective. Since (IMO) we are aiming for something which will be familiar and useful for people in the provided locale, I'd say the It looks like neither library actually takes this into account. Regardless of locale, it seems Edge always displays |
I wrote a test to check more combinations to be more sure about it, but it appears that locale does not affect display of currencies under either Windows Globalization or mini-ICU. (The ICU used here is mini-ICU which is a smaller database used by default in Node.js. Full ICU is an option available but I don't have a build handy.) These invariants could be an artifact of system language as well. For example, on a Chinese language system, they may more aggressively use Chinese characters like 元 (yuan) for currency instead of Latin-based words and symbols like ¥. Test: function testCurrencyDisplay(locale, currency, display) {
let formatted = new Intl.NumberFormat(locale, {
style: 'currency',
currencyDisplay: display,
currency: currency
}).format(65421.45);
return formatted;
}
function testAndPrint(locale, currency, display) {
console.log(`${locale} ${currency} ${display}: \t` + testCurrencyDisplay(locale, currency, display));
}
let locales = ['en-US', 'en-CA', 'es-MX', 'zh-CN', 'zh-HK', 'ja-JP', 'de-DE'];
let currencies = ['USD', 'CAD', 'MXN', 'CNY', 'HKD', 'JPY', 'EUR'];
locales.forEach((locale) => {
currencies.forEach((currency) => {
testAndPrint(locale, currency, 'symbol');
testAndPrint(locale, currency, 'code');
// testAndPrint(locale, currency, 'name');
});
console.log();
}); Node-v8 (using mini-ICU) output for just
Node-ChakraCore (using Windows Globalization) output:
Note that under Windows Globalization the currencies with symbols have a non-breaking space ( I commented out the
These spaces are ordinary spaces ( Adding the German locale yielded an interesting difference. Notice the locale-specific swap in usage of WinGlob:
In Chrome (presumably using a more complete version of ICU):
In Node-v8 mini-ICU the results were the same across all locales. |
It appears Chrome (using full ICU) is sensitive to input locale.
|
To the extent that Windows Globalization may provide more accurate information and an implementation of the "name" currencyDisplay option, and for some reason ChakraCore does not implement or expose this information, we may have a bug here. I'll investigate and may end up fixing this (if there is indeed a bug) as I work on the ICU implementation of Intl. |
Sounds good, I'll stay tuned. Thanks for the quick initial response! |
ICU work item mentioned is now tracked as #2919 |
@dilijev Is this issue fixed ? |
@kirstenwallace Is this issue fixed ? or did you find any alternative solution for this issue. |
No update here yet. Aiming for parity between ICU and WinGlob implementations for #2919, then will investigate other potential bugs. |
Tracking as part of #3644 |
This is interesting. I live in Canada and I've never seen "CA$" in my life. It's either "$" or "CAD". |
@thedamon thanks for the info. ICU uses CLDR as the basis for its data set for producing strings, so that's almost certainly coming from there, not sure whether CA$ is actually considered standard in any sense. @jackhorton do we have any channel by which we can investigate/report bugs in (or ask questions about) CLDR for ICU? |
Based on the issue as reported, it actually sounds like Chakra’s
interpretation is more in line with what I’d expect to see, though I
haven’t tested it directly.
What *does* concern me is realizing that browser implementations of Intl
will vary and that many will not align with what a user or the client would
expect or demand. I’ve never seen the dollar symbol decorated when talking
about my native currency except maybe as C$ when comparing it to other
currencies.. but when comparing almost always the full code CAD is used
…On Mon, Nov 27, 2017 at 16:31 Doug Ilijev ***@***.***> wrote:
@thedamon <https://github.com/thedamon> thanks for the info. ICU uses
CLDR as its data set for producing strings, so that's certainly coming from
there, not sure whether CA$ is actually considered standard in any sense.
@jackhorton <https://github.com/jackhorton> do we have any channel by
which we can investigate/report bugs in CLDR for ICU?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2778 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABT8I_VGPHhjx9EEYEzd1aS00RgAmw-Wks5s6yougaJpZM4MzWiY>
.
|
http://unicode.org/cldr/trac seems like the most reasonable place. With that being said, in ICU, CA$ only shows up when you're using CAD from a non-Canadian locale in the |
@thedamon: @jackhorton makes a good point there, if you're displaying CAD in a CA locale you would never see the string appear that way. @thedamon side note: it is actually the case that in the reality of the web, all engines except for Chakra use ICU as the library backing Intl, and we are the odd ones out by using WinGlob (hence all the compatibility bug reports tracked in #3644). It is my understanding that some subset or modified form of CLDR is used for WinGlob as well, and it may be the case that Windows' version of ICU is also using a modified form of CLDR. After #2919 is completed, the logic will be compatible, but we may still differ in the database. Minor issues/differences like this (whether or not to use CA$ in non-CA locales for |
@jackhorton that really makes sense as a way to set it. I had a lang tag set to "en-CA" and currency set to "CAD" when it cropped up, so the issue is maybe that I just do not understand how the current locale is calculated... |
You might have had |
I think this is a bug...
The following code in Chrome, Firefox, etc, will return a currency symbol of 'US$':
And it will simply use '$' if the currency is set to 'CAD':
But in Edge (and all versions of IE), both of these examples will return a currency symbol of '$'. It will not return US$ or CA$, no matter the locale or currency used. (Same goes for AUD, HKD, etc.)
Example: https://jsfiddle.net/5wfzk7mf/
The text was updated successfully, but these errors were encountered: