Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Website Translator

ProNew

A 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

pnpm dlx shadcn@latest add @viewport/website-translator

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
languagesTranslatorLanguage[]

The languages on offer.

DEFAULT_LANGUAGES
valuestring

The chosen language code, when you control it.

—
defaultValuestring

The language chosen at first, when you do not.

—
onChange(code: string, language: TranslatorLanguage) => void

Called 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"
offsetnumber

Distance from the edges in pixels, for `floating`.

16
containedboolean

Positions `floating` inside the nearest `relative` parent instead of the window.

false
loadingboolean

Shows a spinner while your translations load.

false
disabledbooleanfalse
"aria-label"string

Accessible name of the control.

—
classNamestring—

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.