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

List formatting API #33

Closed
zbraniecki opened this issue Sep 16, 2015 · 19 comments · Fixed by #456
Closed

List formatting API #33

zbraniecki opened this issue Sep 16, 2015 · 19 comments · Fixed by #456
Assignees
Labels
c: text Component: case mapping, collation, properties Proposal Larger change requiring a proposal s: in progress Status: the issue has an active proposal

Comments

@zbraniecki
Copy link
Member

A common scenario is to have a list of items (Array in JS) which has to be formatted in a given language. CLDR provides all the patterns for that.

Example use cases:

  • List of participants in a chat
  • List of days for which an alarm is set
  • List of affected events in Calendar app

Proposed API:

var f = new Intl.ListFormat(navigator.languages, {
  'type': 'regular', // regular or duration
  'variant': 'regular', // regular, short, narrow
});

f.format(['John', 'Amy', 'Nick']); // "John, Amy and Nick" in en-US

this would also supersede current Array.prototype.toLocaleString with ability to build better localized lists.

I can imagine this not having it's own object and only extending Array.prototype.toLocaleString with options.

@zbraniecki
Copy link
Member Author

Relevant CLDR entry example: http://www.unicode.org/cldr/charts/27/summary/pl.html#6947

@srl295
Copy link
Member

srl295 commented Sep 22, 2015

Doesn't Array.prototype.toLocaleString have a different definition? Should that have a type associated with it ( maybe simple or separator, could propose it up to CLDR - as in John,Amy,Nick )

Proposal seems reasonable. I would prefer it was on Intl as well as the extension otherwise there's no object to inspect.

CLDR: Part 2 section 11

[ Also I think it's probably a good idea to link to the CLDR spec instead of just charts or data- The reason I say this is that the data can be mis interpreted without the context of the spec. Feel free to ping me if I can help locating something, and/or join cldr-users ]

@zbraniecki
Copy link
Member Author

Doesn't Array.prototype.toLocaleString have a different definition?

The only thing I could find in Ecma 402 13.4.1 and Ecma 262 22.1.3.26 is that it uses toLocaleString on its members and concatenates them using locale specific separator key.

Should that have a type associated with it ( maybe simple or separator, could propose it up to CLDR - as in John,Amy,Nick )

I like it.

Proposal seems reasonable. I would prefer it was on Intl as well as the extension otherwise there's no object to inspect.

Good point.

Also I think it's probably a good idea to link to the CLDR spec instead of just charts or data

I'm getting better at navigating CLDR docs. Better doesn't mean good yet, but I'll do better, thanks! :)

@srl295
Copy link
Member

srl295 commented Sep 30, 2015

FYI: [http://unicode.org/cldr/trac/ticket/8314](CLDR 8314) discussing <list>;</list> which is explicitly to be used in the context of a list of numbers.

@zbraniecki
Copy link
Member Author

Updated proposal API:

var f = new Intl.ListFormat(locales, {
  'style': 'regular', // regular, duration, duration-short, duration-narrow, number
});

f.format(['John', 'Amy', 'Nick']); // "John, Amy and Nick" in en-US

Array.prototype.toLocaleString(locales, {
  'style': 'regular', // regular, duration, duration-short, duration-narrow, number
});

This API could also be used internally by UnitFormat, similarly to how ICU uses it in MeasureFormat - http://www.icu-project.org/apiref/icu4j/com/ibm/icu/text/MeasureFormat.html#formatMeasures%28com.ibm.icu.util.Measure...%29

@zbraniecki
Copy link
Member Author

Here's a polyfill: https://github.com/zbraniecki/IntlListFormat

@caridy
Copy link
Contributor

caridy commented Oct 26, 2015

This is looking great. Let's start working on the spec on https://github.com/zbraniecki/intl-list-format-spec, btw, there is a typo in the link from the polyfill to the spec.

@zbraniecki
Copy link
Member Author

Thanks, fixed the link. I didn't finish the spec yet, I'll try to do this this week.

@zbraniecki
Copy link
Member Author

Added more to the spec and added type: unit per #32 (comment)

@zbraniecki
Copy link
Member Author

As for elements formatting, we will use toLocaleString of the element (instead of toString).

@zbraniecki
Copy link
Member Author

Heads up, this has been advanced to Stage 0 as of today.

@caridy caridy added this to the 4rd Edition milestone Feb 29, 2016
@zbraniecki
Copy link
Member Author

@srl295 and I brought to cldr-users the topic of regular/duration lists vs. number/unit lists - http://unicode.org/pipermail/cldr-users/2016-March/000469.html

Once this is resolved I'll provide the spec (I have the polyfill working) - https://github.com/l20n/mozintl/blob/master/src/formatters/list.js

@zbraniecki
Copy link
Member Author

This proposal has been advanced to Stage 1 as of today.

@zbraniecki
Copy link
Member Author

CLDR issue for types of lists: http://unicode.org/cldr/trac/ticket/9361

@zbraniecki
Copy link
Member Author

We plan to request stage 2 at the next TC39 meeting.

@zbraniecki
Copy link
Member Author

The proposal has reached stage 2 as of today.

@zbraniecki
Copy link
Member Author

The proposal has reached stage 3 as of today!

@sffc sffc added s: in progress Status: the issue has an active proposal c: text Component: case mapping, collation, properties and removed enhancement labels Mar 19, 2019
@sffc sffc removed this from the 4th Edition milestone Jun 5, 2020
@sffc sffc added the Proposal Larger change requiring a proposal label Jun 5, 2020
@zbraniecki
Copy link
Member Author

I plan to offer https://github.com/tc39/proposal-intl-list-format for Stage 4 advancement at ECMA402 call this week.

@sffc sffc added this to Priority Issues in ECMA-402 Meeting Topics Jun 8, 2020
@sffc sffc moved this from Priority Issues to Previously Discussed in ECMA-402 Meeting Topics Jun 11, 2020
@zbraniecki
Copy link
Member Author

Intl.ListFormat has been approved for Stage 4 at today's TC39 meeting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: text Component: case mapping, collation, properties Proposal Larger change requiring a proposal s: in progress Status: the issue has an active proposal
Projects
ECMA-402 Meeting Topics
Previously Discussed
Development

Successfully merging a pull request may close this issue.

4 participants