Translate

Live translation on device: the original, a row of target languages, the translation streaming in, with copy and an instant swap.

Mock· scripted answersNo model runs in a browser, so every answer here is scripted. On a phone it comes from the model.
  • Apple Foundation Models: supported
  • Gemini Nano: supported
  • Llama (not yet supported): not supported
  • A cloud model: supported

Install

npx ondai add translate

Usage

import { Translate } from '@/components/ondai/translate'

<Translate text={message.text} from="en" to="it" onChangeTarget={setLang} />
  • Picking a language translates again; the translation streams in word by word.
  • Swap flips the pair instantly: the translation becomes the source, with no second model call.
  • languages takes your own list ({ code, label, name }); targets picks which ones show as chips.
  • useTranslate() exposes the same logic headlessly.

Customize

Every AI component takes the same look and customization props, so it fits your app rather than ours.

<Translate
  variant="pop"
  tint="#FF5A5F"
  size="lg"
  radius={12}
  icons={{ title: Globe, direction: null }}
  labels={{ thinking: 'Traduco in {language}', copy: 'Copia' }}
/>
PropWhat it does
variantThe look of the whole component: clean, minimal, glass, pop, candy, metal, shine, bevel
sizesm, md, lg; type, chips, icons and keys scale together
tintAny colour; the variant paints its keys, chips, tiles and glow in it
radiusCorner radius of the card
iconsReplace any icon (a lucide component, an element, or null to hide it): title, direction, run, swap, copy, copied, retry
labelsEvery visible and spoken string; defaults are exported as translateLabels: run, thinking, idle, empty, retry, copy, copied, swap, preparing, languages, source
SlotsDraw a part yourself: renderLanguage, renderResult, renderEmpty, renderError
stylesStyle any named part

Variants

PropOptions
variantclean, minimal, glass, pop, candy, metal, shine, bevel
sizesm, md, lg
toit, es, de, fr, ja (any code in languages)

Token budget

Input budget: 1800 tokens. Input is truncated to half the window so the translation, which can run longer, fits in the rest.

Fallback

When no provider is ready the component renders the unavailable state (AvailabilityGate copy) and, while a model downloads, its progress.

Files

Registry dependencies: button, chip, model-download, on-device-badge, shimmer-text, skeleton, streaming-text, surface

npm dependencies: @ondai/core, @ondai/tokens, expo-clipboard, expo-haptics, lucide-react-native, react-native-reanimated

On this page