Components · Messages
MessageItemTranslation
The parts that show a message was translated — a short Space Mono status line under the body that switches between the translation and the original, the original kept below, and the translating and failed states.
Also called MessageTranslation, Translation
import { MessageItemTranslation } from "@botiverse/raft-ui";A translated message shows the translation in its body and one short line of Space Mono text under it, which says it was translated and switches to the original. The same line says when a translation is on its way or failed. When both languages should stay visible, the original sits under the translation. These parts go inside MessageItemContent (MessageItem).
When to use
Anatomy
MessageItemTranslationStatus: one line intext-mono-meta,foreground-hint, under the body: an icon, then the words or the action.MessageItemTranslationAction: the text button in the status line that switches between translation and original.MessageItemTranslationOriginal: the original text, drawn as a quote in the message, withMessageItemTranslationOriginalLabelabove it.MessageItemTranslationProgressTrack: a 4px track inside a Progress, in the body while the translation is on its way.MessageItemTranslationFailedStatus: the status line inwarning-strong, for a failure.MessageItemTranslationRetryAction: the text button in the failed line.
Variants
States
Behavior
- The action switches the body between the translation and the original; you swap the text. raft-ui doesn't hold which one is showing.
- Retry replaces the failed line with the translating state.
Content
- Say what the action does, in sentence case: Show original, Show translation.
- Label the original Original.
- Say the translation is on its way: "Translating…".
- Say a failure in a few words, then offer Retry: "Translation unavailable · Retry".
Accessibility
MessageItemTranslationActionandMessageItemTranslationRetryActionare native<button type="button">elements; their visible text is their name. An icon-only Retry needs anaria-label.- Give the failed and translating status lines
aria-live="polite", so the change after Retry is announced. - Give the
Progressanaria-label, such as "Translating message". - Hide the icons in the status line from screen readers; the words carry the meaning.
Rules
- Keep the status to one short line of Space Mono text under the message, and don't add a color for it (Built from existing parts).
- Use orange for a failed translation, as for any failure (Feedback).
API
MessageItemTranslationAction, MessageItemTranslationFailedStatus, MessageItemTranslationOriginal, MessageItemTranslationOriginalLabel
Takes the attributes of its element.
MessageItemTranslationProgressTrack
Also takes the attributes of its element.
MessageItemTranslationRetryAction, MessageItemTranslationStatus
Takes the attributes of its element.