Intl

Intl 객체는 각 언어에 맞는 문자비교, 숫자, 시간, 날짜비교를 제공하는, ECMAScript 국제화 API를 위한 이름공간입니다. Collator, NumberFormat, DateTimeFormatIntl 객체의 속성을 위한 생성자입니다. 이 페이지는 일반적인 국제화의 기능을 수행하는 객체의 생성자들과 언어를 구분하는 함수들 뿐만 아니라 이러한 속성들에 대해서도 다루고 있습니다.

속성

Intl.Collator
콜레이터 생성자입니다. 콜레이터 객체는 각 언어에 맞는 문자열 비교를 가능하게 해줍니다.
Intl.DateTimeFormat
각 언어에 맞는 시간과 날짜 서식을 적용할 수 있는 객체의 생성자입니다.
Intl.ListFormat
각 언어에 맞는 목록 서식을 적용할 수 있는 객체의 생성자입니다.
Intl.NumberFormat
각 언어에 맞는 숫자 서식을 적용할 수 있는 객체의 생성자입니다.
Intl.PluralRules
각 언어에 맞는 복수형 규칙 및 단수 복수 구분 서식을 적용할 수 있는 객체의 생성자입니다.
Intl.RelativeTimeFormat
각 언어에 맞는 상대 시간 서식을 적용할 수 있는 객체의 생성자입니다.

메서드

Intl.getCanonicalLocales()
표준 로케일 이름 목록을 반환합니다.

로케일 식별과 조정

The internationalization constructors as well as several language sensitive methods of other constructors (listed under See also) use a common pattern for identifying locales and determing the one they will actually use: they all accept locales and options arguments, and negotiate the requested locale(s) against the locales they support using an algorithm specified in the options.localeMatcher property.

locales 매개변수

The locales argument must be either a string holding a BCP 47 language tag, or an array of such language tags. If the locales argument is not provided or is undefined, the runtime's default locale is used.

A BCP 47 language tag identifies a language or locale (the difference between the two is fuzzy). In their most common form it can contain, in this order: a language code, a script code, and a country code, all separated by hyphens. Examples:

  • "hi": Hindi.
  • "de-AT": German as used in Austria.
  • "zh-Hans-CN": Chinese written in simplified characters as used in China.

The subtags identifying languages, scripts, countries (regions), and (rarely used) variants in BCP 47 language tags can be found in the IANA Language Subtag Registry.

BCP 47 also allows for extensions, and one of them matters to the JavaScript internationalization functions: the "u" (Unicode) extension. It can be used to request a customization of the locale-specific behavior of a Collator, NumberFormat, or DateTimeFormat object. Examples:

  • "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.

로케일 조정

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 매개변수

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.

명세

Specification Status Comment
ECMAScript Internationalization API 1.0 (ECMA-402)
The definition of 'Intl' in that specification.
Standard Initial definition.
ECMAScript Internationalization API 2.0 (ECMA-402)
The definition of 'Intl' in that specification.
Standard
ECMAScript Internationalization API 4.0 (ECMA-402)
The definition of 'Intl' in that specification.
Draft Added Intl.getCanonicalLocales in the 4th edition.

브라우저 호환성

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
IntlChrome Full support 24Edge Full support YesFirefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 26Firefox Android Full support 56Opera Android Full support YesSafari iOS Full support 10Samsung Internet Android Full support Yesnodejs Full support Yes
CollatorChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android No support NoChrome Android Full support 26Firefox Android Full support 56Opera Android Full support YesSafari iOS Full support 10Samsung Internet Android Full support Yesnodejs ?
DateTimeFormatChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 26Firefox Android Full support 56Opera Android ? Safari iOS Full support 10Samsung Internet Android Full support Yesnodejs Full support Yes
ListFormat
Experimental
Chrome Full support 72Edge No support NoFirefox No support NoIE No support NoOpera Full support 60Safari No support NoWebView Android Full support 72Chrome Android Full support 72Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android Full support Yesnodejs No support No
LocaleChrome Full support 74Edge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
NumberFormatChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support YesChrome Android Full support 26Firefox Android Full support 56Opera Android Full support 14Safari iOS Full support 10Samsung Internet Android Full support Yesnodejs ?
PluralRulesChrome Full support 63Edge Full support 18Firefox Full support 58IE No support NoOpera Full support 50Safari No support NoWebView Android Full support 63Chrome Android Full support 63Firefox Android Full support 58Opera Android Full support 46Safari iOS No support NoSamsung Internet Android No support Nonodejs Full support 10.0.0
RelativeTimeFormatChrome Full support 71Edge No support NoFirefox Full support 65IE No support NoOpera Full support 58Safari No support NoWebView Android Full support 71Chrome Android Full support 71Firefox Android Full support 65Opera Android ? Safari iOS No support NoSamsung Internet Android Full support Yesnodejs Full support 12.0.0
getCanonicalLocalesChrome Full support 54Edge Full support 16Firefox Full support 48IE No support NoOpera No support NoSafari Full support 11WebView Android No support NoChrome Android No support NoFirefox Android Full support 56Opera Android No support NoSafari iOS Full support 11Samsung Internet Android No support Nonodejs No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

같이 보기