Slide navigation: Forward with space bar, →, or PgDn. Backwards with ← or PgUp.
123,456.78 (United States) 123.456,78 (Switzerland) ๑๒๓,๔๕๖.๗๘ (Thailand with Thai numerals)
March 22, 1961 22. März 1961 1961年3月22日
de or zh.Latn, Cyrl, Hant.US or CH.u-nu-thai.['de-CH', 'fr-CH', 'en']{ sensitivity: 'case' }localeMatcher option:
'lookup' uses the algorithm in http://tools.ietf.org/html/rfc4647#section-3.4.'best fit' allows the runtime to choose a locale.resolvedOptions on internationalization objects to obtain all computed options:
const collator = new Intl.Collator('en-US-u-kf-lower', { sensitivity: 'base' })
collator.resolvedOptions() → {
locale: 'en',
usage: 'sort',
sensitivity: 'base',
ignorePunctuation: false,
numeric: false,
caseFirst: 'lower',
collation: 'default'
}
Intl.getCanonicalLocales only normalizes provided locale names.Intl.Xxx.supportedLocalesOf only filter provided locale names.new Intl.NumberFormat('de').format(123456.78) → '123,456.78'formatToParts method yields an array of the parts:
[ { type: 'integer', value: '123' },
{ type: 'group', value: ',' },
{ type: 'integer', value: '456' },
{ type: 'decimal', value: '.' },
{ type: 'fraction', value: '78' } ]
nu (numbering): latn, arab, thai, ... style: decimal (default), currency, percentcurrency: ISO 4217 currency code such as USD or EUR. Required for currency style.useGrouping: true (default) to use grouping separators.minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, minimumSignificantDigits, maximumSignificantDigitsconst words = ['Alpha', 'Zulu', 'able', 'zebra', 'Ångström']
words.sort(new Intl.Collator('en').compare) → [ 'able', 'Alpha', 'Ångström', 'zebra', 'Zulu']
words.sort(new Intl.Collator('sv').compare) → [ 'able', 'Alpha', 'zebra', 'Zulu', 'Ångström']
co (collation): phonebook, phonetic, reformed, pinyin, ...kn (numeric collation): true ('1' < '2' < '10'), false (default)kf (case first): upper, lower, false (default)usage: sort (default), searchsensitivity: base (a = A = Å), accent (a = A ≠ Å), case (a ≠ A = Å), variant (a, A, Å all different)ignorePunctuation: true, false (default)numeric, caseFirst: See kn, kf above.['Österreich', 'Offenbach'].sort(new Intl.Collator('de-u-co-phonebk').compare)
// In German phonebooks (but not dictionaries), Ö is considered as Oe
['part1', 'part10', 'part2', 'part9'].sort(new Intl.Collator('en-u-kn-true').compare)
→ ["part1", "part2", "part9", "part10"]
toLocaleUpperCase, toLocaleLowerCase
'Großhändler'.toLocaleUpperCase('de') → 'GROSSHÄNDLER'
localeCompare
'part10'.localeCompare('part2', 'en', { numeric: true }) → 1
normalize combines/decomposes accents, ligatures:
['NFC', 'NFD', 'NFKC', 'NFKD'].map(mode => [...'Å™'.normalize(mode)])
→ ['Å', '™'], ['A', '°', '™'], ['Å', 'T', 'M'], ['A', '°', 'T', 'M'][0, 1, 2, 3, 4, 5].map(i => (new Intl.PluralRules('en').select(i)))
→ ['other', 'one', 'other', 'other', 'other', 'other']
[0, 1, 2, 3, 4, 5].map(i => (new Intl.PluralRules('ru').select(i)))
→ ['many', 'one', 'few', 'few', 'few', 'many']
PluralRules class just produces the English form names. They still need to be mapped to the localized word forms.type: cardinal (default), ordinalconst rules = new Intl.PluralRules('en', { type: 'ordinal' })
[0, 1, 2, 3, 4, 5].map(i => (rules.select(i)))
→ ['other', 'one', 'two', 'few', 'other', 'other']const list = ['Goethe', 'Schiller', 'Lessing']
new Intl.ListFormat('en', { type: 'conjunction' }).format(list)
→ 'Goethe, Schiller, and Lessing'
new Intl.ListFormat('de', { type: 'disjunction' }).format(list)
→ 'Goethe, Schiller oder Lessing'
type: conjunction (default), disjunction, unitstyle: long, short, narrow (with unit type only)unit type is for unit lists like “7 pounds 11 ounces”, but it produces commas in long and short styles—Chicago and AP wouldn't approveconst newYearsEve = new Date(1999, 11, 31)
new Intl.DateTimeFormat('en').format(newYearsEve) → 12/31/1999
new Intl.DateTimeFormat('de').format(newYearsEve) → 31.12.1999
new Intl.DateTimeFormat('en', {
year: 'numeric',
month: 'short',
day: 'numeric',
}).format(new Date()) → Dec 31, 1999
nu (numbering): latn, arab, thai, ... ca (calendar): gregory, hebrew, buddhist, ...hc (hour cycle): h11, h12, h23, h24timeZone: UTC, Europe/Berlin, ... (default local time)hour12: true, falsehourCycle: h11, h12, h23, h24formatMatcher: basic, best fit (default)month: 2-digit (09), numeric (9), narrow (S), short (Sep), long (September)year, day, hour, minute, second: 2-digit, numericweekday, era: long, short, narrowtimeZoneName: short, longdateStyle, timeStyle (Stage 3): full, long, medium, shortnew Intl.RelativeTimeFormat('en', { numeric: 'auto'}).format(-1, 'day') → 'yesterday'
new Intl.RelativeTimeFormat('fr', { numeric: 'auto'}).format(-10, 'days') → 'il y a 10 jours'
format/formatToParts method has two arguments: a quantity and a unit:
year, quarter, month, week, day, hour, minute, second (or their plurals, such as years)numeric: always (1 day ago, default), auto (yesterday)style: long, short, narrowtoLocaleString, toLocaleDateString, toLocaleTimeString take locale and options arguments.
const newYearsEve = new Date(1999, 11, 31, 23, 59)
newYearsEve.toLocaleDateString('de') → '31.12.1999'
newYearsEve.toLocaleTimeString('de') → '23:59:00'
newYearsEve.toLocaleString('de') → '31.12.1999, 23:59:00'toLocaleString in any class.