nook
Browse the docs

Components

Language switcher

Native

A native language selector using names in their own language.

See the prompt

Changes apply to your account only.

Installation

npx nook-ui@latest add language-switcher

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Language switcher" component to this project, exactly as Nook ships it.

A native language selector using names in their own language.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add language-switcher`. It writes `components/ui/language-switcher.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/language-switcher.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { LanguageSwitcher } from "@/components/ui/language-switcher";
export default function Example() {
  return (
    <div className="grid w-full max-w-xs gap-2">
      <label htmlFor="workspace-language" className="text-sm font-medium">
        Workspace language
      </label>
      <LanguageSwitcher
        id="workspace-language"
        name="language"
        defaultValue="en"
        items={[
          { value: "en", label: "English", lang: "en" },
          { value: "id", label: "Bahasa Indonesia", lang: "id" },
          { value: "de", label: "Deutsch", lang: "de" },
          { value: "ja", label: "日本語", lang: "ja" },
          { value: "ar", label: "العربية", lang: "ar", dir: "rtl" },
        ]}
      />
      <p className="text-xs text-muted-foreground">
        Changes apply to your account only.
      </p>
    </div>
  );
}
```

API
- `LanguageSwitcher`: A native language selector using names in their own language.
  - `display` (`"name" | "code" | "flag" | "flag-name"`, default "name"): What each choice shows. Codes use `code` on each item (EN, ID), flags use `flag`. A flag stands for a country, so prefer flag-name, which keeps the language name beside it.
  - `variant` (`"select" | "segmented"`, default "select"): A native dropdown, or a row of buttons for two or three languages.
  - `items` (`LanguageOption[]`): Value, endonym, language tag and optional direction.
  - `value / defaultValue` (`string`): Selected language ID.
  - `onValueChange` (`(value: string) => void`): Host app handles translation or navigation.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Each option carries its language and optional writing direction; the select is named.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { LanguageSwitcher } from "@/components/ui/language-switcher";
export default function Example() {
  return (
    <div className="grid w-full max-w-xs gap-2">
      <label htmlFor="workspace-language" className="text-sm font-medium">
        Workspace language
      </label>
      <LanguageSwitcher
        id="workspace-language"
        name="language"
        defaultValue="en"
        items={[
          { value: "en", label: "English", lang: "en" },
          { value: "id", label: "Bahasa Indonesia", lang: "id" },
          { value: "de", label: "Deutsch", lang: "de" },
          { value: "ja", label: "日本語", lang: "ja" },
          { value: "ar", label: "العربية", lang: "ar", dir: "rtl" },
        ]}
      />
      <p className="text-xs text-muted-foreground">
        Changes apply to your account only.
      </p>
    </div>
  );
}

Examples

Right to left

Many languages

Flags with names

Selamat datang kembali, Maya.

A flag stands for a country, not a language, so the name stays beside it.

Short codes

Chosen: English

Segmented, EN and ID

Ringkasan minggu Anda

Tiga rapat, dua tenggat, dan satu hari libur.

Segmented with flags

Props

LanguageSwitcher

A native language selector using names in their own language.

PropTypeDefaultDescription
display"name" | "code" | "flag" | "flag-name""name"What each choice shows. Codes use `code` on each item (EN, ID), flags use `flag`. A flag stands for a country, so prefer flag-name, which keeps the language name beside it.
variant"select" | "segmented""select"A native dropdown, or a row of buttons for two or three languages.
itemsLanguageOption[]–Value, endonym, language tag and optional direction.
value / defaultValuestring–Selected language ID.
onValueChange(value: string) => void–Host app handles translation or navigation.

Accessibility

Each option carries its language and optional writing direction; the select is named.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.