Vize

use-display-names

Localized names of languages, regions, scripts, currencies, calendars, and date-time fields (Intl.DisplayNames): "JP" → "Japan", "ja" → "日本語" in Japanese, "EUR" → "Euro".

Package @vizejs/composable/use-display-names
Own the source vize lib pull composable:use-display-names
Runtime exports useDisplayNames
Gzip budget 2304 B

Usage

import { useDisplayNames } from "@vizejs/composable/use-display-names";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
useDisplayNames i18n experimental deterministic-fallback caller-managed none web, server, worker, native, desktop, terminal Intl, window useLocale

API

useDisplayNames

Localized names of languages, regions, scripts, currencies, calendars, and date-time fields (Intl.DisplayNames): "JP" → "Japan", "ja" → "日本語" in Japanese, "EUR" → "Euro". Malformed codes yield undefined rather than the platform RangeError, so user-entered codes never crash rendering; invalid options still throw on first read. Derived state only: no listeners or timers, and deterministic during server rendering when the locale is explicit.

function useDisplayNames( code: MaybeRefOrGetter<string | null | undefined>, options: MaybeRefOrGetter<UseDisplayNamesOptions>, ): DisplayNamesControls
const { name } = useDisplayNames(regionCode, { type: "region", locale: "en" });

Types

UseDisplayNamesOptions

Options for useDisplayNames.

Member Type Description
type DisplayNamesKind Kind of code to name.
locale? string | Intl.Locale Locale the names are written in. Pass it explicitly for hydration-stable server rendering.
style? "narrow" | "short" | "long" Name length.
fallback? "code" | "none" What to return for a well-formed code without a name: the code itself or undefined.
languageDisplay? "dialect" | "standard" Language names: "dialect" names "en-GB" "British English", "standard" names it "English (United Kingdom)".

DisplayNamesControls

Reactive display names returned by useDisplayNames.

Member Type Description
locale ComputedRef<string> Canonical locale in use.
displayNames ComputedRef<Intl.DisplayNames> Display names instance for the current locale and options.
name ComputedRef<string | undefined> Name of the reactive code; undefined for malformed or unnamed codes.
of (code: string) => string | undefined Name any code. Malformed codes return undefined instead of throwing.