Closed
Bug 1388777
Opened 7 years ago
Closed 1 month ago
Array.prototype.toLocaleString should use a locale-aware separator
Categories
(Core :: JavaScript: Internationalization API, defect, P3)
Core
JavaScript: Internationalization API
Tracking
()
RESOLVED
INACTIVE
People
(Reporter: silv3rwind, Unassigned)
Details
Attachments
(1 file)
40.18 KB,
image/png
|
Details |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0 Build ID: 20170803105720 Steps to reproduce: On a Windows machine and a german locale with default regional settings set, run this in the browser console: ['',''].toLocaleString() Actual results: Output is ',' Expected results: Output should be ';' The spec [1] says "the list-separator String appropriate for the host environment’s current locale", and this value is a setting in the Windows regional options (see attached screenshot). The implementation of using this value should be similiar to how Number.prototype.toLocaleString already works for the locale-aware decimal point formatting. Also to mention: Chrome exhibits the same bug. IE11 and presumably Edge return '; ' on the tested system, which is closes to the expected ';'. [1] https://tc39.github.io/ecma402/#sup-array.prototype.tolocalestring
Reporter | ||
Comment 1•7 years ago
|
||
Chromium bug for reference: https://bugs.chromium.org/p/chromium/issues/detail?id=753841
Comment 2•7 years ago
|
||
(In reply to silv3rwind from comment #0) > The spec [1] says "the list-separator String appropriate for the host > environment’s current locale", and this value is a setting in the Windows > regional options (see attached screenshot). The sensible choice would be to use a separator string based on the locale-argument resp. the default locale if no explicit locale argument was provided. That way |[1.1, 2.2, 3.3].toLocaleString("en")| would return |"1.1,2.2,3.3"|, and |[1.1, 2.2, 3.3].toLocaleString("de")| would return |"1,1;2,2;3,3"|. Maybe https://github.com/tc39/ecma402/issues/33 will help to get this right in the spec.
Comment 3•7 years ago
|
||
Correct, Intl.ListFromatter spec proposal aims to add the correct behavior for localized list formatting.
Reporter | ||
Comment 4•7 years ago
|
||
Isn't the intention of the .toLocaleString to format in the user's current locale when no argument is given? It's how Number.prototype.toLocalString works, and I think the Array variant should work the same. To shed some light on my use case: I'm trying to find the separator to generate a CSV file for Excel which expects ';' separators when running under a german locale. Right now I've found a workaround using Number.prototype.toLocalString to detect the user's decimal separator, but it's not really ideal as it isn't aware of separators other than ',' and ';' [1]. [1] https://github.com/silverwind/save-csv/blob/46e1883cbe92ca9635f2edd23c2756aec9c717ce/save-csv.js#L25-L31
Comment 5•7 years ago
|
||
> Isn't the intention of the .toLocaleString to format in the user's current locale when no argument is given? It's how Number.prototype.toLocalString works, and I think the Array variant should work the same. No. Number.prototype.toLocaleString is specified in ECMA262 as dummy no-op, and then as part of Intl.NumberFormat ECMA402 spec as a fully functional localized formatter. The same has to happen with Intl.ListFormat and Array.prototype.toLocaleString. > To shed some light on my use case: I'm trying to find the separator to generate a CSV file for Excel which expects ';' separators when running under a german locale. If I were trying to solve that, I'd probably extract the bits from https://github.com/unicode-cldr/cldr-misc-modern/blob/master/main/de/listPatterns.json for all locales into a single json and use that. Probably, listPattern-type-unit['middle]. It'll be interesting to see how this will pan out in Intl.ListFormat because the default proposed formatter would get you a human readable list. If this will stay true for Array.prototype.toLocaleString then by default you'll get: ["Anna", "Mary", "Joe"].toLocaleString(); // "Anna, Mary and Joe" and you'll need to specify "style: unit" option to get "Anna, Mary, Joe"
Updated•7 years ago
|
status-firefox55:
--- → affected
status-firefox56:
--- → affected
status-firefox57:
--- → affected
Priority: -- → P3
Updated•2 years ago
|
Severity: normal → S3
Updated•1 month ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 1 month ago
Resolution: --- → INACTIVE
You need to log in
before you can comment on or make changes to this bug.
Description
•