Internationalization
The library ships its own text in four languages (Simplified Chinese, Traditional Chinese, English, Japanese) and follows the app’s language; the docs exist in Chinese and English, and example data switches with the gallery’s language.
The library’s own text
Section titled “The library’s own text”Fixed text inside components (“Clear”, “More”, “10 / page”, “No results for these filters”) is not hard-coded: components read it with uiText(key), from four files in packages/ui/locales/, keyed by component (ui.<component>.<meaning>). Each file is a Record<UiTextKey, string>: a missing or extra key fails nsh check.
At startup the app hands its language to the library, which then follows it:
import { setUiLocale, setUiText } from 'nacre'import { locale, t } from '../i18n'
setUiLocale(locale) // a signal / getter: follows itsetUiText((key) => (key === 'ui.table.empty_filtered' ? t('records_filter_empty') : undefined)) // the app's own text for a key; undefined keeps the library'sThe app’s text
Section titled “The app’s text”Business text (titles, buttons, hints) is passed in by the app (title, label, placeholder, accessibilityLabel) through its own t() and locales/; components do not know the app’s keys. Conditions use enums and fields, never translated text.
Long text
Section titled “Long text”English and Japanese often run 30%–100% longer than Chinese. Components leave room: buttons, tags and segments have no fixed width; single-line text that does not fit truncates with “…” and shows in full on hover; form labels sit above their controls; numbers use tabular-nums. Switch the gallery’s top bar to English / 日本語 to check each page.
Docs and examples
Section titled “Docs and examples”- A page’s English lives in the
enfield of the same source file; Traditional Chinese reads the Chinese, Japanese reads the English. Outputs:docs/md/en/<key>.md,llms.en.txt,llms-full.en.txt; passlocale: "en"to MCP tools such asget_component. - Example data is written as
tx('转派客诉', 'Reassign complaint', '苦情を転送', '轉派客訴')(Japanese and Traditional Chinese optional). The gallery shows the current language; the Code tab and the Markdown carry the literal of that language, so copied code has plain strings. Calltxinside component functions only: the top level of a module runs once and would not follow a language switch.