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

Add "collation" option to Intl.Collator #380

Closed
FrankYFTang opened this issue Sep 28, 2019 · 4 comments · Fixed by #459
Closed

Add "collation" option to Intl.Collator #380

FrankYFTang opened this issue Sep 28, 2019 · 4 comments · Fixed by #459
Assignees
Labels
c: locale Component: locale identifiers s: discuss Status: TG2 must discuss to move forward Small Smaller change solvable in a Pull Request

Comments

@FrankYFTang
Copy link
Contributor

#175
add "calendar" and "numberingSystem" option to Intl.DateTimeFormat and Intl.NumberFormat
Also notice "numberingSystem" is already an option in Intl.RelativeTimeFormat.

We should also consider add "collation" to Intl.Collator.

Notes by @littledan in #175 stated
"This patch leaves out "collation" because of a lack
of clear use cases."

Not sure what does that mean.

I think it is useful. For example, in Chinese, we may construct the following collator

var pinyin = new Intl.Collator("zh", {collator: "pinyin"});
var zhuyin = new Intl.Collator("zh", {collator: "zhuyin"});
var stroke = new Intl.Collator("zh", {collator: "stroke"});

@FrankYFTang
Copy link
Contributor Author

@littledan @sffc

@sffc sffc added c: locale Component: locale identifiers s: discuss Status: TG2 must discuss to move forward labels Sep 29, 2019
@sffc
Copy link
Contributor

sffc commented Sep 29, 2019

I'm +1 for this.

There is some discussion about this on #105. @NorbertLindenberg said,

collation: Use cases? Note that several of the values only make sense for a small set of languages.

@sffc sffc added the Small Smaller change solvable in a Pull Request label Jun 5, 2020
@FrankYFTang
Copy link
Contributor Author

Here are some code example currently work in Firefox and Chrome by using the -u-co- extension in locale.

Chinese

// Four names in Traditional Chinese and Simplified Chinese. The first is the same in both form.
let array = ["王五", "譚永鋒", "张无忌" ,"谭永锋", "劉新宇", "刘新宇", "張無忌"];
let pinyin = new Intl.Collator(["zh-u-co-pinyin"])
let zhuyin = new Intl.Collator(["zh-u-co-zhuyin"])
let stroke = new Intl.Collator(["zh-u-co-stroke"])
array.sort(pinyin.compare)
// ["刘新宇", "劉新宇", "谭永锋", "譚永鋒", "王五", "张无忌", "張無忌"]
array.sort(zhuyin.compare)
// ["谭永锋", "譚永鋒", "刘新宇", "劉新宇", "张无忌", "張無忌", "王五"]
stroke = new Intl.Collator(["zh-u-co-stroke"])
// ["王五", "刘新宇", "张无忌", "張無忌", "谭永锋", "劉新宇", "譚永鋒"]

If we enable the "collation" option, then the code should be

let pinyin = new Intl.Collator(["zh"], {collation: "pinyin"})
let zhuyin = new Intl.Collator(["zh"], {collation: "zhuyin"})
let stroke = new Intl.Collator(["zh"], {collation: "stroke"})

Examples in Vietnamese

let array=["Toan", "Thai", "Tin", "Tung", "Trong","Tai"]
let vi =  new Intl.Collator("vi")
let viTrad = new Intl.Collator("vi-u-co-trad") 
// and with "collation" option, it should be Intl.Collator("vi", {collation: "trad")
array.sort(vi.compare)
// ["Tai", "Thai", "Tin", "Toan", "Trong", "Tung"]
array.sort(viTrad.compare)
// ["Tai", "Tin", "Toan", "Tung", "Thai", "Trong"]

FrankYFTang added a commit that referenced this issue Jun 16, 2020
Collator already have "co" in  [[RelevantExtensionKeys]] internal slot and therefore the  usage by using "-u-co-$collationkey" is already supported in ECMA402.

Close #380
@FrankYFTang
Copy link
Contributor Author

The following html show the underline collation support is already build into Firefox, Chrome and Safari

<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<h1>Chinese Examples</h1>
<script>
var array = ["王五", "譚永鋒", "张无忌" ,"谭永锋", "劉新宇", "刘新宇", "張無忌"];
var zh = new Intl.Collator(["zh"])
var zhTW = new Intl.Collator(["zh-TW"])
var pinyin = new Intl.Collator(["zh-u-co-pinyin"])
var zhuyin = new Intl.Collator(["zh-u-co-zhuyin"])
var stroke = new Intl.Collator(["zh-u-co-stroke"])
document.write("<h2>zh:</h2>" + array.sort(zh.compare) + "<br>");
document.write("<h2>zh-TW:</h2>" + array.sort(zhTW.compare) + "<br>");
document.write("<h2>Pinyin:</h2>" + array.sort(pinyin.compare) + "<br>");
document.write("<h2>Zhuyin:</h2>" + array.sort(zhuyin.compare) + "<br>");
document.write("<h2>Stroke:</h2>" + array.sort(stroke.compare) + "<br>");
</script>
<h1>Vietnamese Examples</h1>
<script>
array=["Toan", "Thai", "Tin", "Tung", "Trong","Tai"];
var vi =  new Intl.Collator("vi");
var viTrad = new Intl.Collator("vi-u-co-trad");
document.write("<h2>vi:</h2>" + array.sort(vi.compare) + "<br>");
document.write("<h2>Traditional:</h2>" + array.sort(viTrad.compare) + "<br>");
</script>
</body>
</html>

leobalter pushed a commit that referenced this issue Jan 5, 2021
* Allow Collator to get collation from option

Collator already have "co" in  [[RelevantExtensionKeys]] internal slot and therefore the  usage by using "-u-co-$collationkey" is already supported in ECMA402.

Close #380

* Move the reading of the collation option earlier

To make it the same as the order already in Table 3: Resolved Options of Collator Instances

* add reference of type to  UTS 35

* change ` to *

* change http to https
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: locale Component: locale identifiers s: discuss Status: TG2 must discuss to move forward Small Smaller change solvable in a Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants