Locale Picker

Combobox for picking a BCP 47 locale with native names, English names and country flags.

@drift-ui/locale-pickerRegistry JSONOpen in v0

Keyboard

↑↓
Open, then move through locales
Enter
Pick the locale
Escape
Close the picker
On this page

Installation

The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.

Usage

locale-picker-usage.tsx
"use client"

import { useState } from "react"
import { LocalePicker } from "@/components/ui/locale-picker"

export function LanguageSetting() {
  const [locale, setLocale] = useState("en-US")

  return (
    <LocalePicker
      aria-label="Language"
      value={locale}
      onValueChange={setLocale}
      locales={["en-US", "de-DE", "ja-JP", "pt-BR"]}
    />
  )
}

Examples

A short list

Pass locales to restrict choices to the specific regional BCP 47 locales your application supports.

Language tags without regions

Language-level tags such as 'de' or 'fr' display native and English names without regional country flags.

API reference

LocalePicker

A button that opens a searchable list of BCP 47 locales, showing native names, display language names, and country flags. Arrow keys navigate, Enter selects, and Escape closes the popover.

Prop
valuestringControlled BCP 47 language tag.
defaultValuestringDefault""Initial value when uncontrolled.
onValueChange(value: string) => voidCalled when a locale is picked.
localesstring[]DefaultDEFAULT_LOCALESLimits the list to these BCP 47 language tags. Defaults to 34 common global locales.
displayLocalestringDefault"en"Language used to format the secondary name in each option via Intl.DisplayNames.
placeholderstringDefault"Select a locale"Shown while no locale is selected.
searchPlaceholderstringDefault"Search locales"Placeholder for the search input.
showTagbooleanDefaulttrueWhether to show the monospace BCP 47 tag badge next to the names.
namestringName for the hidden form input that submits the selected locale value.
disabledbooleanDefaultfalseDisables the trigger button and hidden form input.

Other props go to the <button>.

locale-picker-utils

isValidLocale(tag: string): boolean; normalizeLocale(tag: string): string; getLocaleFlag(tag: string): string | null; formatLocaleNames(tag: string, displayLocale?: string): { nativeName: string; currentName: string; label: string }; listLocales(tags?: string[], displayLocale?: string): LocaleOption[]; filterLocales(options: LocaleOption[], query: string): LocaleOption[]

Pure logic functions for BCP 47 tag validation, canonical normalization, country flag derivation, Intl.DisplayNames formatting, and search filtering. Import from @/lib/locale-picker-utils.

Source

components/ui/locale-picker.tsx