# Translation card

A translation that shows its work: the source above, the result below, phrase by phrase, so pointing at any phrase lights the words it came from.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Translation card. A note to a supplier in Monterrey. Point at a phrase to see what it came from, switch the tone, or swap. Preview: https://chatcn.dev/preview/translation-card-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/translation-card
```

## Usage

```tsx
import { TranslationCard } from "@/components/ui/chatcn/pro/translation-card"

<TranslationCard
  from={{ lang: "en" }}
  to={{ lang: "es-MX" }}
  pairs={[
    { source: "Could you move the delivery", target: "¿Podría mover la entrega" },
    { source: " to Thursday morning?", target: " al jueves por la mañana?" },
  ]}
  variants={{ formal, casual }}
  onSwap={swap}
/>
```

Pass the text as aligned phrases, the way a model returns them when asked for a phrase map; spaces live inside the phrases. Point at a phrase in either text, or tab into the translation and use the arrow keys, and its partner lights in the other text, so a reader can check the meaning rather than trust it. `variants` adds a tone switch; only the phrases that changed rise in. Each side has a listen button that speaks with the browser's voice for that language, and copy takes the translation. `onSwap` shows the swap button; translate again and pass the new sides. Language names come from `Intl.DisplayNames` unless you set `name`.

## Examples

### States

Example: States. A short phrase with no tones, Japanese with a swap, and a translation on its way. Preview: https://chatcn.dev/preview/translation-card-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `from`, `to` | `TranslationSide` | `{ lang, name? }`; `lang` is BCP 47 |
| `pairs` | `TranslationPair[]` | `{ source, target }` phrases, in order |
| `variants` | `Record<string, TranslationPair[]>` | Tones by name; two or more show the switch |
| `tone`, `defaultTone`, `onToneChange` | `string` | The tone shown |
| `onSwap` | `() => void` | Shows the swap button |
| `loading` | `boolean` | The source shows and the translation is a placeholder |
| `labels` | `Partial<TranslationCardLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Tab | Into the translation, then on to the controls |
| Arrow left, right | The previous or next phrase; its source lights |

## Accessibility

- Each text carries its `lang`, so screen readers switch voice.
- A focused phrase has its source as a tooltip; listen buttons are toggles named with the language.
- While loading, a status names the wait.

## Motion

Lit phrases fade their tint in 150 ms. Changed phrases fade and unblur in 320 ms on a tone switch; the swap arrow turns. Reduced motion keeps the tint and drops the rest.

Source: https://chatcn.dev/docs/components/translation-card