Website Translator
ProNewA language switcher as a menu button, an inline list or a button pinned to a corner, with 18 flags drawn in the file. It reports the choice through onChange; the translating is yours.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
| Prop | Type | Default |
|---|---|---|
| languages | TranslatorLanguage[]The languages on offer. | DEFAULT_LANGUAGES |
| value | stringThe chosen language code, when you control it. | — |
| defaultValue | stringThe language chosen at first, when you do not. | — |
| onChange | (code: string, language: TranslatorLanguage) => voidCalled with the chosen code. The component does not translate anything: load your own translations here. | — |
| layout | "dropdown" | "inline" | "floating"`dropdown` is a menu button, `inline` lists every language, `floating` pins the menu button to a corner. | "dropdown" |
| flag | "square" | "round" | "none"Shape of the flags, or `none` to leave them out. | "square" |
| icon | "flag" | "globe" | "translate" | "none"What the menu button shows before its label. | "flag" |
| label | "name" | "native" | "code" | "none"The text for each language: its name, its name in its own language, its code, or nothing. | "name" |
| position | "top-right" | "top-left" | "bottom-right" | "bottom-left"Corner for the `floating` layout. | "top-right" |
| offset | numberDistance from the edges in pixels, for `floating`. | 16 |
| contained | booleanPositions `floating` inside the nearest `relative` parent instead of the window. | false |
| loading | booleanShows a spinner while your translations load. | false |
| disabled | boolean | false |
| "aria-label" | stringAccessible name of the control. | — |
| className | string | — |
Accessibility
- The menu is a Radix dropdown of radio items: arrows, Home/End and type-ahead move, Enter picks, Escape closes and focus returns to the button.
- The button is named with the current language, so flag-only and code-only versions still read in full.
- Inline languages are toggle buttons with aria-pressed; native names carry their lang so they are pronounced correctly.
- Flags are decorative; loading marks the control busy. Under reduced motion the menu appears without the scale and the spinner holds still.