Chinese Localization

Bopomofo Ruby Text (React ruby typography component)

A React ruby typography component that annotates Chinese characters with Bopomofo (Zhuyin) or Hanyu Pinyin above them — switch between Bopomofo and Pinyin, highlight a character on hover, adjust the annotation size and spacing. Suited to teaching materials, dictionaries, and children's sites.

Semantic <ruby> / <rt> / <rp> markup annotates Chinese characters with Bopomofo (Zhuyin) symbols (tone marks are simplified to the right-hand side, following the horizontal-writing convention) or Hanyu Pinyin. Switching modes fades the annotations in character by character, and hovering a character highlights and slightly enlarges it together with its annotation — suited to language teaching, children's books, and literacy interfaces.

Bring this into your project

Run this command in your project folder. The CLI adds the source and dependencies; then follow the usage example below.

npx webberui@latest add zhuyin-ruby-text.en

New project or installation trouble? Start here →

Playground

Tune the props live — the code snippet updates as you go, so you can dial in the look you want before copying it.

Active edited usageDefault props
<ZhuyinRubyText/>

The complete example includes the preview layout and data. Install the component first, then paste this file into your project.

Installation

npx webberui@latest add https://webberui.com/r/zhuyin-ruby-text.en.json

Or, once registries are configured in components.json, install it as @webberui/zhuyin-ruby-text.

Usage

import { ZhuyinRubyText } from "@/components/ui/zhuyin-ruby-text";

<ZhuyinRubyText
  items={[
    { char: "Phonetic", zhuyin: "ㄓㄨˋ", pinyin: "zhù" },
    { char: "sound", zhuyin: "ㄧㄣ", pinyin: "yīn" },
    { char: "! " },
  ]}
  mode="zhuyin"
  size="md"
/>

The component also exports zhuyinRubySampleLines (sample data for the first two lines of the children's song 〈SmallStars〉, about 30 characters) so you can preview it quickly. That is only a small demo dataset — in practice, produce an items array of the same shape from your edited content or from a Bopomofo / Pinyin conversion service. Punctuation simply omits zhuyin and pinyin, and is then rendered as plain text and excluded from the hover highlighting.

Props

PropTypeDefaultDescription
itemsZhuyinRubyItem[]—Per-character annotation data; each entry is { char, zhuyin?, pinyin? }
mode"zhuyin" | "pinyin" | "none""zhuyin"Annotation mode; none still reserves the annotation row's height, so switching does not shift the layout
size"sm" | "md" | "lg""md"Type size (the characters and their annotations scale together)
classNamestring—Forwarded to the outermost container

Accessibility

  • It uses semantic <ruby> / <rt> / <rp> markup, so environments without ruby typography support fall back to showing the annotations in parentheses
  • Annotation content is hidden from screen readers (aria-hidden), so Bopomofo symbols and tone marks are not read out one by one and do not disrupt the meaning
  • When the user has "reduce motion" enabled at the system level, a mode switch plays no fade in and hover does not scale (only the color change remains)
  • The outermost container is marked lang="zh-TW", helping assistive technology pick the right voice