Read preferred locales and calendars, and follow system changes with React hooks
One.Localization reads the user’s language and formatting preferences.
getLocales() and getCalendars() are synchronous snapshots. The named
useLocales and useCalendars hooks read the same values and update when
the platform reports a locale or time zone change. No permission is required.
import { Text } from 'react-native'import { One, useCalendars, useLocales } from 'one'
const locales = One.Localization.getLocales()const calendars = One.Localization.getCalendars()
function LocalTime({ when }: { when: Date }) { const [locale] = useLocales() const [calendar] = useCalendars() const label = new Intl.DateTimeFormat(locale.languageTag, { ...(calendar.timeZone ? { timeZone: calendar.timeZone } : {}), hour: 'numeric', minute: '2-digit', }).format(when)
return <Text>{label}</Text>}Both reads always return at least one entry, so the first entry can be
destructured directly. Hooks are imports from one; they are not methods
on the namespace. Your app supplies translations; this API supplies the
preferences used to choose and format them.
| One.Localization | Type | Description |
|---|---|---|
getLocales() => [Locale, ...Locale[]]Read preferred locales in priority order, with at least one entry. | () => [Locale, ...Locale[]] | Read preferred locales in priority order, with at least one entry. |
getCalendars() => [Calendar, ...Calendar[]]Read calendar preferences, with at least one entry. | () => [Calendar, ...Calendar[]] | Read calendar preferences, with at least one entry. |
| Hook | Returns |
|---|---|
useLocales() | [Locale, ...Locale[]], refreshed on platform changes |
useCalendars() | [Calendar, ...Calendar[]], refreshed on platform changes |
| Locale | Type | Description |
|---|---|---|
languageTagstringBCP 47 language tag, such as en-US or zh-Hant-TW. | string | BCP 47 language tag, such as en-US or zh-Hant-TW. |
languageCodestring | nullLanguage subtag, such as en or zh. | string | null | Language subtag, such as en or zh. |
languageScriptCodestring | nullExplicit script subtag, such as Hant; null when absent. | string | null | Explicit script subtag, such as Hant; null when absent. |
regionCodestring | nullFormatting region selected by the device. | string | null | Formatting region selected by the device. |
languageRegionCodestring | nullRegion associated with this preferred language. | string | null | Region associated with this preferred language. |
currencyCodestring | nullCurrency code for the formatting region. | string | null | Currency code for the formatting region. |
currencySymbolstring | nullCurrency symbol for the formatting region. | string | null | Currency symbol for the formatting region. |
languageCurrencyCodestring | nullCurrency code associated with this language locale. | string | null | Currency code associated with this language locale. |
languageCurrencySymbolstring | nullCurrency symbol associated with this language locale. | string | null | Currency symbol associated with this language locale. |
decimalSeparatorstring | nullSeparator used between whole and fractional digits. | string | null | Separator used between whole and fractional digits. |
digitGroupingSeparatorstring | nullSeparator used between groups of digits. | string | null | Separator used between groups of digits. |
textDirection'ltr' | 'rtl'Writing direction for the language. | 'ltr' | 'rtl' | Writing direction for the language. |
measurementSystem'metric' | 'us' | 'uk' | nullMeasurement system selected by the device. | 'metric' | 'us' | 'uk' | null | Measurement system selected by the device. |
temperatureUnit'celsius' | 'fahrenheit' | nullTemperature unit selected by the device. | 'celsius' | 'fahrenheit' | null | Temperature unit selected by the device. |
| Calendar | Type | Description |
|---|---|---|
calendarstring | nullUnicode calendar type, such as gregory or buddhist. | string | null | Unicode calendar type, such as gregory or buddhist. |
timeZonestring | nullSystem time zone identifier, such as Pacific/Honolulu. | string | null | System time zone identifier, such as Pacific/Honolulu. |
uses24hourClockboolean | nullWhether the device uses a 24-hour clock. | boolean | null | Whether the device uses a 24-hour clock. |
firstWeekdaynumber | nullFirst day of the week, with Sunday 1 and Saturday 7. | number | null | First day of the week, with Sunday 1 and Saturday 7. |
Unknown optional values are null. Locale preferences can differ from
language preferences: on iOS, number separators, currency, measurement,
and temperature follow the device’s formatting settings even when its
first preferred language names a different region.
| iOS | Android | Web | |
|---|---|---|---|
| Reads | System locale and calendar | System locale and calendar | Intl and navigator.languages |
| Hook updates | Locale and time zone notifications | Locale and time zone broadcasts | Browser languagechange event |
| Currency and units | System preferences | Locale-derived values | Null |
| Clock and first weekday | System preferences | System preferences | Null when the browser does not expose them |
System settings may restart an app when its language changes. While the
app is running, hooks subscribe to the platform’s change notifications and
remove their listeners on unmount. Snapshot reads do not subscribe.
The web hooks listen for languagechange; they do not independently watch
time zone changes. During server rendering the locale falls back to
en-US; the server’s Intl implementation supplies calendar data when available.
Replace Expo Localization’s getLocales() and getCalendars() with
One.Localization.getLocales() and One.Localization.getCalendars().
Import useLocales and useCalendars from one; the hook names and the
Locale and Calendar field names stay the same.
For the older combined asynchronous snapshot, see
One.Device.getLocalizationInfo. Use Localization when
you need the preferred locale list or reactive formatting preferences.
Edit this page on GitHub.