Intl

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

* Some parts of this feature may have varying levels of support.

O objeto Intl é o namespace para a API de Internacionalização do ECMAScript , que fornece comparação de string sensível à línguagem, formatação de números, e formatação de data e hora. Os construtores para os objetos Collator, NumberFormat, e DateTimeFormat são propriedades do objecto Intl. Esta página documenta essas propriedades, bem como funcionalidades comuns aos construtores de internacionalização e outras funções sensíveis de linguagem.

Propriedades

Intl.Collator

Construtor para collators, objetos que permitem comparação de string sensível a linguagem.

Intl.DateTimeFormat

Construtor para objetos que permitem formatação de data e hora sensível a linguagem.

Intl.NumberFormat

Construtor para objetos que permitem formatação de número sensível a linguagem.

Métodos

Intl.getCanonicalLocales()

Retorna os nomes canônicos de local (ex.: en-US, pt-BR).

Identificação e negociação de local

Os construtores de internacionalização, assim como diversos métodos de outros construtores que são sensíveis a idioma (listados em Veja também) usam um padrão comum para identificar locais e determinar qual será utilizado: todos aceitam argumentos locales e options e negociam o(s) local(is) requisitado entre os locais suportados usando um algoritmo especificado na propriedade options.localeMatcher.

Argumento locales

O argumento locales deve ser uma string contendo uma tag de linguagem BCP 47 ou um array dessas tags. Se o argumento locales não for passado ou estiver indefinido, será utilizado o local padrão do runtime.

Uma tag de linguagem BCP 47 identifica um idioma ou local (a diferença entre ambos neste caso é difusa). Em sua forma mais comum, ela pode conter, nesta ordem: um código de idioma, um código de escrita e um código de país, todos eparados por hífen. Exemplos:

  • "hi": Hindi.
  • "de-AT": Alemão como usado na Áustria.
  • "zh-Hans-CN": Chinês com escrita simplificada como usado na China.

As subtags identificando idiomas, escritas, países (regiões) e (raramente utilizadas) variantes nas tags de linguagem BCP 47 podem ser consultadas no Registro de Subtags de Linguagem da IANA.

BCP 47 também permite extensões, e uma delas é relevante para as funções JavaScript de internacionalização: a extensão "u" (Unicode). Ela pode ser utilizada para requisitar uma customização do comportamento específico local de um objeto Collator, NumberFormat, ou DateTimeFormat. Exemplos:

  • "de-DE-u-co-phonebk": Use the phonebook variant of the German sort order, which expands umlauted vowels to character pairs: ä → ae, ö → oe, ü → ue.
  • "th-TH-u-nu-thai": Use Thai digits (๐, ๑, ๒, ๓, ๔, ๕, ๖, ๗, ๘, ๙) in number formatting.
  • "ja-JP-u-ca-japanese": Use the Japanese calendar in date and time formatting, so that 2013 is expressed as the year 25 of the Heisei period, or 平成 25.

Locale negotiation

The locales argument, after stripping off all Unicode extensions, is interpreted as a prioritized request from the application. The runtime compares it against the locales it has available and picks the best one available. Two matching algorithms exist: the "lookup" matcher follows the Lookup algorithm specified in BCP 47; the "best fit" matcher lets the runtime provide a locale that's at least, but possibly more, suited for the request than the result of the Lookup algorithm. If the application doesn't provide a locales argument, or the runtime doesn't have a locale that matches the request, then the runtime's default locale is used. The matcher can be selected using a property of the options argument (see below).

If the selected language tag had a Unicode extension substring, that extension is now used to customize the constructed object or the behavior of the function. Each constructor or function supports only a subset of the keys defined for the Unicode extension, and the supported values often depend on the language tag. For example, the "co" key (collation) is only supported by Collator, and its "phonebk" value is only supported for German.

options argument

The options argument must be an object with properties that vary between constructors and functions. If the options argument is not provided or is undefined, default values are used for all properties.

One property is supported by all language sensitive constructors and functions: The localeMatcher property, whose value must be a string "lookup" or "best fit" and which selects one of the locale matching algorithms described above.

Especificações

Specification
ECMAScript® 2025 Internationalization API Specification
# intl-object

Compatibilidade com navegadores

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Intl
Collator
Collator() constructor
options.caseFirst parameter
options.collation parameter
options.ignorePunctuation parameter
options.localeMatcher parameter
options.numeric parameter
options.sensitivity parameter
options.usage parameter
Collator.compare
Collator.resolvedOptions
Collator.supportedLocalesOf
DateTimeFormat
DateTimeFormat() constructor
Supports normative optional ChainDateTimeFormat behavior
locales parameter
options parameter
options.calendar parameter
options.dateStyle parameter
options.dayPeriod parameter
options.fractionalSecondDigits parameter
options.hourCycle parameter
options.numberingSystem parameter
options.timeStyle parameter
options.timeZoneName parameter
shortGeneric/longGeneric/shortOffset/longOffset as options.timeZoneName option
options.timeZone parameter
IANA time zone names in options.timeZone option
DateTimeFormat.format
DateTimeFormat.formatRange
DateTimeFormat.formatRangeToParts
DateTimeFormat.formatToParts
DateTimeFormat.resolvedOptions
computed timeZone
DateTimeFormat.supportedLocalesOf
DisplayNames
DisplayNames() constructor
DisplayNames.of
DisplayNames.resolvedOptions
DisplayNames.supportedLocalesOf
DurationFormat
DurationFormat() constructor
DurationFormat.format
DurationFormat.formatToParts
DurationFormat.resolvedOptions
DurationFormat.supportedLocalesOf
ListFormat
ListFormat() constructor
ListFormat.format
ListFormat.formatToParts
ListFormat.resolvedOptions
ListFormat.supportedLocalesOf
Locale
Locale() constructor
Locale.baseName
Locale.calendar
Locale.caseFirst
Locale.collation
Locale.getCalendars
Locale.getCollations
Locale.getHourCycles
Locale.getNumberingSystems
Locale.getTextInfo
Locale.getTimeZones
Locale.getWeekInfo
Locale.hourCycle
Locale.language
Locale.maximize
Locale.minimize
Locale.numberingSystem
Locale.numeric
Locale.region
Locale.script
Locale.toString
NumberFormat
NumberFormat() constructor
Supports normative optional ChainNumberFormat behavior
locales parameter
options parameter
options.compactDisplay parameter
options.currencyDisplay parameter
options.currencySign parameter
options.currency parameter
options.localeMatcher parameter
options.maximumFractionDigits parameter
options.maximumSignificantDigits parameter
options.minimumFractionDigits parameter
options.minimumIntegerDigits parameter
options.minimumSignificantDigits parameter
options.notation parameter
options.numberingSystem parameter
options.roundingIncrement parameter
options.roundingMode parameter
options.roundingPriority parameter
options.signDisplay parameter
negative value
options.style parameter
options.trailingZeroDisplay parameter
options.unitDisplay parameter
options.unit parameter
options.useGrouping parameter
options.useGrouping parameter accepts: 'always', 'auto', 'min2' (in addition to: true and false)
NumberFormat.format
number param string value is decimal (not Number)
NumberFormat.formatRange
NumberFormat.formatRangeToParts
NumberFormat.formatToParts
NumberFormat.resolvedOptions
NumberFormat.supportedLocalesOf
PluralRules
PluralRules() constructor
options parameter
options.roundingIncrement parameter
options.roundingMode parameter
options.roundingPriority parameter
options.trailingZeroDisplay parameter
Experimental
PluralRules.resolvedOptions
PluralRules.select
PluralRules.selectRange
PluralRules.supportedLocalesOf
RelativeTimeFormat
RelativeTimeFormat() constructor
locales parameter
RelativeTimeFormat.format
RelativeTimeFormat.formatToParts
RelativeTimeFormat.resolvedOptions
RelativeTimeFormat.supportedLocalesOf
Segmenter
Segmenter() constructor
Segmenter.resolvedOptions
Segmenter.segment
Segmenter.supportedLocalesOf
Segments
[Symbol.iterator]
Segments.containing
getCanonicalLocales
supportedValuesOf

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
Uses a non-standard name.
Has more compatibility info.

Veja também