Skip to main content
userTourKit
@tour-kit/coreHooks

useLocale

Read the current LocaleContextValue (locale, messages, direction, optional host-side t override) from the nearest LocaleProvider.

domidex01Published

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

FieldTypeDescription
localestringActive locale tag (e.g. 'en', 'pt-BR').
messagesMessagesFlat key → string dictionary used by useT.
tTranslateFn | undefinedOptional 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, urrtl); 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.

Free & open source

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.