MessageTranslation

Message-row translation output, bilingual originals, pending progress, and retry status composed from explicit parts.

Preview#

AT
Atlasowner2:14 PM

让团队保留这条原始消息。

AT
Atlasowner2:14 PM

让团队保留这条原始消息。

Original

Keep this original message available for the team.

AT
Atlasowner2:14 PM
x
Translating…
AT
Atlasowner2:14 PM

Keep this original message available for the team.

Translation unavailable
const ORIGINAL_MESSAGE = "Keep this original message available for the team.";
const TRANSLATED_MESSAGE = "让团队保留这条原始消息。";

export function MessageTranslationBilingualComposition() {
  const [showOriginal, setShowOriginal] = useState(false);

  const handleToggleOriginal = useCallback(() => setShowOriginal((current) => !current), []);

  return (
    <MessageItem>
      <MessageItemAvatarSlot>
        <Avatar size="md" type="agent">
          <AvatarImage src={MESSAGE_FIXTURE_AVATAR_SRC} alt="" />
          <AvatarFallback>AT</AvatarFallback>
        </Avatar>
      </MessageItemAvatarSlot>
      <MessageItemContent>
        <MessageItemHeader>
          <MessageItemSender>Atlas</MessageItemSender>
          <MessageItemMeta>owner</MessageItemMeta>
          <MessageItemTime>2:14 PM</MessageItemTime>
        </MessageItemHeader>
        <MessageItemBody>
          <Markdown>{showOriginal ? ORIGINAL_MESSAGE : TRANSLATED_MESSAGE}</Markdown>
        </MessageItemBody>
        {!showOriginal ? (
          <MessageItemTranslationOriginal>
            <MessageItemTranslationOriginalLabel>Original</MessageItemTranslationOriginalLabel>
            <Markdown>{ORIGINAL_MESSAGE}</Markdown>
          </MessageItemTranslationOriginal>
        ) : null}
        <MessageItemTranslationStatus>
          <Languages size={12} />
          <MessageItemTranslationAction
            title={showOriginal ? "Original shown. Show translation" : "Translated. Show original"}
            aria-label={showOriginal ? "Show translation" : "Show original"}
            onClick={handleToggleOriginal}
          >
            {showOriginal ? "Show translation" : "Show original"}
          </MessageItemTranslationAction>
        </MessageItemTranslationStatus>
      </MessageItemContent>
    </MessageItem>
  );
}

Render translated content in the message body and use the status action to switch between the translated and original text.

AT
Atlasowner2:14 PM

让团队保留这条原始消息。

Keep the translation in the message body and compose the original-content region below it when both languages should remain visible.

AT
Atlasowner2:14 PM

让团队保留这条原始消息。

Original

Keep this original message available for the team.

Use indeterminate Progress while translated content is unavailable. Failure copy and retry behavior remain explicit children of the status row.

AT
Atlasowner2:14 PM
x
Translating…
AT
Atlasowner2:14 PM

Keep this original message available for the team.

Translation unavailable

API#WIP

...props
ComponentProps<"blockquote">
Original-content blockquote for bilingual display. It shares Message Markdown's quote treatment; consumers choose when it is visible.
...props
ComponentProps<"div">
Label inside the bilingual original-content container. Localization and visible copy stay consumer-owned.
...props
ComponentProps<"div">
Translation status row for translated or pending states. Consumers compose icons, copy, and actions.
...props
ProgressTrackProps
Translation progress track with a 4px (`h-1`) height.
...props
ComponentProps<"div">
Failed status row with failure treatment for copy and retry actions.
...props
ComponentProps<"button">
Native button for original/translation toggles. The consumer owns callbacks and accessible labels.
...props
ComponentProps<"button">
Native retry button with the failed-translation action treatment. The consumer owns callbacks, icons, copy, and accessible labels.