useLocale
Read the current LocaleContextValue (locale, messages, direction, optional host-side t override) from the nearest LocaleProvider.
Read the active locale, translation dictionary, and text direction inside any component tree wrapped with <LocaleProvider>. Drives the i18n pipeline shared by tour copy, hint labels, announcement bodies, and any consumer code that resolves LocalizedText.
Usage
import { useLocale } from '@tour-kit/core';
function DirectionAwareCard() {
const { locale, direction } = useLocale();
return (
<article dir={direction} lang={locale}>
{/* ... */}
</article>
);
}useLocale never throws — when no <LocaleProvider> is mounted it returns the default context (locale: 'en', messages: {}, no override t, derived direction).
Return Value
| Field | Type | Description |
|---|---|---|
locale | string | Active locale tag (e.g. 'en', 'pt-BR'). |
messages | Messages | Flat key → string dictionary used by useT. |
t | TranslateFn | undefined | Optional host-app translate override; when set, useT delegates to it instead of looking up messages. |
direction | 'ltr' | 'rtl' | Derived from the locale's primary subtag (ar, he, fa, ur → rtl); override via the direction prop on <LocaleProvider>. |
For resolving a single LocalizedText value, prefer useResolvedText (returns ReactNode) or useResolveLocalizedText (returns string). See the i18n guide for the full pipeline.
Related
- LocaleProvider — wrap your tree
- useResolvedText — resolve
LocalizedTexttoReactNode - useResolveLocalizedText — resolve
LocalizedTexttostring - i18n guide — end-to-end internationalization
Ship onboarding, not config.
npm i @tour-kit/core is MIT and free. The Pro packages work unlicensed too — a one-time $99 license removes the production watermark when you ship.
MIT-licensed — no signup, no credit card. Pay once, only when you ship.