Web/JavaScript/Reference/Global objects/Intl/Locale/collation
The Intl.Locale.prototype.collation property is an accessor property that returns the collation type for the Locale, which is used to order strings according to the locale's rules.
Description
Collation is the process of ordering strings of characters. It is used whenever strings must be sorted and placed into a certain order, from search query results to ordering records in a database. While the idea of placing strings in order might seem trivial, the idea of order can vary from region to region and language to language. The collation property helps to make it easier for JavaScript programmers to access the collation type used by a particular locale.
Below is a table with the available collation types, taken from the Unicode collation specification.
Valid collation types
| Collation Type | Description |
|---|---|
| big5han | Pinyin ordering for Latin, big5 charset ordering for CJK characters (used in Chinese) |
| compat | A previous version of the ordering, for compatibility |
| dict | Dictionary style ordering (such as in Sinhala) |
|
The
direct |
Binary code point order (used in Hindi) |
| ducet | The default Unicode collation element table order |
| emoji | Recommended ordering for emoji characters |
| eor | European ordering rules |
| gb2312 | Pinyin ordering for Latin, gb2312han charset ordering for CJK characters (used in Chinese) |
| phonebk | Phonebook style ordering (such as in German) |
| phonetic | Phonetic ordering (sorting based on pronunciation) |
| pinyin | Pinyin ordering for Latin and for CJK characters (used in Chinese) |
| reformed | Reformed ordering (such as in Swedish) |
| search | Special collation type for string search |
| searchjl | Special collation type for Korean initial consonant search |
| standard | Default ordering for each language |
| stroke | Pinyin ordering for Latin, stroke order for CJK characters (used in Chinese) |
| trad | Traditional style ordering (such as in Spanish) |
| unihan | Pinyin ordering for Latin, Unihan radical-stroke ordering for CJK characters (used in Chinese) |
| zhuyin | Pinyin ordering for Latin, zhuyin order for Bopomofo and CJK characters (used in Chinese) |
Examples
Like other locale subtags, the collation type can be added to the Intl.Locale object via the locale string, or a configuration object argument to the constructor.
Adding a collation type via the locale string
In the Unicode locale string spec, collation types are locale key "extension subtags". These subtags add additional data about the locale, and are added to locale identifiers by using the -u extension. Thus, the collation type can be added to the inital locale identifier string that is passed into the Locale constructor. To add the collation type, first add the -u extension to the string. Next, add the -co extension to indicate that you are adding a collation type. Finally, add the collation to the string.
let stringColl = new Intl.Locale("en-Latn-US-u-co-emoji");
console.log(stringColl.collation); // Prints "emoji"
Adding a collation type via the configuration object argument
The Intl.Locale constructor has an optional configuration object argument, which can contain any of several extension types, including collation types. Set the collation property of the configuration object to your desired collation type, and then pass it into the constructor.
let configColl = new Intl.Locale("en-Latn-US", {collation: "emoji"});
console.log(configColl.collation); // Prints "emoji"
Specifications
| Specification |
|---|
| ECMAScript Internationalization API (ECMA-402) |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
collation
|
Chrome
Full support 74 |
Edge
Full support 79 |
Firefox
Full support 75 |
IE
No support No |
Opera
Full support 62 |
Safari
Full support 14 |
WebView Android
Full support 74 |
Chrome Android
Full support 74 |
Firefox Android
No support No |
Opera Android
Full support 53 |
Safari iOS
Full support 14 |
Samsung Internet Android
Full support 11.0 |
nodejs Full support 12.0.0 Full support 12.0.0 Notes' Before version 13.0.0, only the locale data for |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
See also
Intl.Locale.prototype.collation by Mozilla Contributors is licensed under CC-BY-SA 2.5.