Skip to content

locale

get

Signature

js
locale.get()

Description

Returns the current locale string. In a browser environment, reads from navigator.languages with a fallback to navigator.language. In a non-browser environment (Node.js), falls back to Intl.DateTimeFormat().resolvedOptions().locale.

Returns

TypeDescription
stringThe current locale string (e.g. 'fr-FR', 'en-US')

Examples

js
locale.get() // 'fr-FR'

getCodes

Signature

js
locale.getCodes()

Description

Parses the current locale and returns its components as an object.

Returns

TypeDescription
objectAn object with the locale components
result.languagestring — The language code (e.g. 'fr', 'en')
result.scriptstring | undefined — The script code if present (e.g. 'Latn')
result.regionstring | undefined — The region code if present (e.g. 'FR', 'US')

Examples

js
locale.getCodes() // { language: 'fr', script: undefined, region: 'FR' }
locale.getCodes() // { language: 'zh', script: 'Hans', region: 'CN' }