Skip to content

Commit 2e2f755

Browse files
committed
Adds Intl.DisplayNames to es2020 - re: microsoft#44022
1 parent f481743 commit 2e2f755

File tree

1 file changed

+73
-6
lines changed

1 file changed

+73
-6
lines changed

src/lib/es2020.intl.d.ts

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ declare namespace Intl {
2929
| "minutes"
3030
| "second"
3131
| "seconds";
32+
3233
/**
3334
* The locale matching algorithm to use.
3435
*
@@ -75,7 +76,7 @@ declare namespace Intl {
7576
/**
7677
* An object with properties reflecting the locale
7778
* and formatting options computed during initialization
78-
* of the `Intel.RelativeTimeFormat` object
79+
* of the `Intl.RelativeTimeFormat` object
7980
*
8081
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description).
8182
*/
@@ -150,9 +151,6 @@ declare namespace Intl {
150151
* The [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
151152
* object is a constructor for objects that enable language-sensitive relative time formatting.
152153
*
153-
* Part of [Intl object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl)
154-
* namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm).
155-
*
156154
* [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#Browser_compatibility).
157155
*/
158156
const RelativeTimeFormat: {
@@ -275,8 +273,7 @@ declare namespace Intl {
275273
* For the general form and interpretation of the locales argument,
276274
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
277275
*
278-
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale#Parameters)
279-
* with some or all of options of the locale.
276+
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale#Parameters) with some or all of options of the locale.
280277
*
281278
* @returns [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) object.
282279
*
@@ -285,4 +282,74 @@ declare namespace Intl {
285282
const Locale: {
286283
new (tag?: BCP47LanguageTag, options?: LocaleOptions): Locale;
287284
};
285+
286+
interface DisplayNamesOptions {
287+
localeMatcher: RelativeTimeFormatLocaleMatcher;
288+
style: RelativeTimeFormatStyle;
289+
type: "language" | "region" | "script" | "currency";
290+
fallback: "code" | "none";
291+
}
292+
293+
interface DisplayNames {
294+
/**
295+
* Receives a code and returns a string based on the locale and options provided when instantiating
296+
* [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
297+
*
298+
* @param code The `code` to provide depends on the `type` passed to display name during creation:
299+
* - If the type is `"region"`, code should be either an [ISO-3166 two letters region code](https://www.iso.org/iso-3166-country-codes.html),
300+
* or a [three digits UN M49 Geographic Regions](https://unstats.un.org/unsd/methodology/m49/).
301+
* - If the type is `"script"`, code should be an [ISO-15924 four letters script code](https://unicode.org/iso15924/iso15924-codes.html).
302+
* - If the type is `"language"`, code should be a `languageCode` ["-" `scriptCode`] ["-" `regionCode` ] *("-" `variant` )
303+
* subsequence of the unicode_language_id grammar in [UTS 35's Unicode Language and Locale Identifiers grammar](https://unicode.org/reports/tr35/#Unicode_language_identifier).
304+
* `languageCode` is either a two letters ISO 639-1 language code or a three letters ISO 639-2 language code.
305+
* - If the type is `"currency"`, code should be a [3-letter ISO 4217 currency code](https://www.iso.org/iso-4217-currency-codes.html).
306+
*
307+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of).
308+
*/
309+
of(code: string): string;
310+
/**
311+
* Returns a new object with properties reflecting the locale and style formatting options computed during the construction of the current
312+
* [`Intl/DisplayNames`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
313+
*
314+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions).
315+
*/
316+
resolvedOptions(): DisplayNamesOptions;
317+
}
318+
319+
/**
320+
* The [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
321+
* object enables the consistent translation of language, region and script display names.
322+
*
323+
* [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames#browser_compatibility).
324+
*/
325+
const DisplayNames: {
326+
prototype: DisplayNames;
327+
328+
/**
329+
* @param locales A string with a BCP 47 language tag, or an array of such strings.
330+
* For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation)
331+
* page.
332+
*
333+
* @param options An object for setting up a display name.
334+
*
335+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames).
336+
*/
337+
new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: Partial<DisplayNamesOptions>): DisplayNames;
338+
339+
/**
340+
* Returns an array containing those of the provided locales that are supported in display names without having to fall back to the runtime's default locale.
341+
*
342+
* @param locales A string with a BCP 47 language tag, or an array of such strings.
343+
* For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation)
344+
* page.
345+
*
346+
* @param options An object with a locale matcher.
347+
*
348+
* @returns An array of strings representing a subset of the given locale tags that are supported in display names without having to fall back to the runtime's default locale.
349+
*
350+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf).
351+
*/
352+
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[];
353+
};
354+
288355
}

0 commit comments

Comments
 (0)