Locale Provider
Overview
LocaleProvider manages the lang HTML attribute which affects browser behavior for hyphenation, spell-checking, and Intl API defaults. It is used by FormatNumber and FormatByte components to determine the number formatting locale.
Usage
import { setLocale, getLocale } from "@paramanu/utilities-js"
setLocale("fr-FR")console.log(getLocale()) // "fr-FR"import { LocaleProvider, useLocale } from "@paramanu/utilities-react"
<LocaleProvider defaultLocale="en-US"> <App /></LocaleProvider>
// Inside a component:const { locale, setLocale } = useLocale()Guidelines
- Use BCP 47 language tags (e.g.,
"en-US","de-DE","ja") - Sets the
langattribute ondocument.documentElementby default - FormatNumber and FormatByte inherit the locale from context
- The
useLocalehook provides read/write access to the current locale
API
| Prop | Type | Default | Description |
|---|---|---|---|
defaultLocale | string | "en" | Initial BCP 47 language tag |