Aller au contenu

Composants · Référence

Locale Switcher

An i18n-library-agnostic dropdown for switching between arbitrary locales with localized language labels.

Dernière mise à jour le 16 octobre 2026

Overview

locale-switcher provides a compact, i18n-library-agnostic language switcher. The caller provides the current locale, available locales, and a change callback.

Set the active locale once with KrakstackProvider; pass locale directly only when a component needs an override. Message overrides are keyed by arbitrary locale strings, so additional languages can be supplied with messages={{ es: { ... } }}. Exact locale keys such as es-MX take precedence over base keys such as es; English is the final fallback.

Install

shell
bunx shadcn@latest add @krak-stack/locale-switcher

Features

  • Accepts any locale strings and delegates locale changes to the caller
  • In-file English and French labels
  • Optional message overrides
  • Icon-only trigger with accessible screen-reader text

Usage

tsx
import { LocaleSwitcher } from "@/components/ui/locale-switcher";

<LocaleSwitcher
  locale={locale}
  locales={["en", "fr", "es"]}
  onLocaleChange={setLocale}
  messages={{ es: { title: "Idioma", es: "Español" } }}
/>
Dependencies
Packages and shadcn components required by this registry item.