intlName
intlName(value, options?) converts identifiers into localized human names. Use this for country labels, currency names, script names, and language names.
Native reference: Intl.DisplayNames
Signature
ts
1function intlName(2 value: string,3 options?: Intl.DisplayNamesOptions & {4 locale?: string5 scope?: IntlRuntime6 }7): stringEmpty or unknown values return ''.
Option map
| Option | Type | Default | Effect |
|---|---|---|---|
locale | string | runtime locale | One-off locale override |
scope | IntlRuntime | getIntl() | Use scoped locale defaults |
type | region | language | script | currency | calendar | dateTimeField | undefined | What the value represents |
style | narrow | short | long | short | Label width |
fallback | none | code | code | What to return when the value cannot be resolved |
languageDisplay | dialect | standard | standard | Dialect vs language-first naming |
scriptDisplay | standard | short | standard | Script name style |
Examples
Region names
ts
1intlName('US', { locale: 'en-US', type: 'region' }) // "United States"2intlName('US', { locale: 'fr-FR', type: 'region', style: 'short' }) // "États-Unis"Language, script, and currency
ts
1intlName('en', { type: 'language' }) // "English"2intlName('pt-BR', { type: 'language' }) // "Portuguese (Brazil)"3intlName('USD', { type: 'currency', style: 'long' }) // "US Dollar"4intlName('Latn', { type: 'script', style: 'short' }) // "Latn"Scope + locale override
ts
1import { createIntl, intlName } from '@beforesemicolon/intl'2 3const scoped = createIntl({ locale: 'ja-JP', messages: {} })4 5intlName('USD', { scope: scoped })6intlName('USD', { scope: scoped, locale: 'es-ES' })Fallback strategy
ts
1intlName('', { type: 'region' }) // ''2intlName('ZZ', { type: 'language', fallback: 'code' }) // "ZZ" in code fallback mode