i18n
The wording a component renders by itself, such as a close button’s label or the required marker, follows @k8ordo/i18n’s current locale. Here you register another language, replace a few entries, and read the same wording from your own elements.
On this page
Locale selection
src/i18n.tsimport { defineLocales } from '@k8ordo/i18n';
export const locales = defineLocales({
ja: { timeZone: 'Asia/Tokyo', dir: 'ltr' },
en: { timeZone: 'UTC', dir: 'ltr' },
});When the application defines its locale set with defineLocales, the components render in the same locale as its messages: the one in the URL, or the set’s default. There is no provider and nothing to pass.
Pitfall
The module that defines the set has to load in the browser too. Without the set in the browser, the components render in English and no longer match the server’s HTML during hydration. @k8ordo/framework loads src/i18n.ts in the browser before anything renders; elsewhere, import it from a Client Component the root renders.
Apps without a locale set
src/i18n.tsimport { defineLocales } from '@k8ordo/i18n';
export const locales = defineLocales({
ja: { timeZone: 'Asia/Tokyo', dir: 'ltr' },
});A Japanese-only application defines a set with a single locale, like this.
An application that defines no locale set with @k8ordo/i18n, such as a Next.js or plain Vite app, renders the components in English. The URL starting with /ja/ changes nothing, so the server and the browser agree.
Registering another language
src/messages/ui-fr.tsimport type { Messages } from '@k8ordo/ui/i18n';
export const fr: Messages = {
close: 'Fermer',
required: 'Requis',
loading: 'Chargement',
// ...
};The library ships the Japanese and English dictionaries. Any other locale is registered with registerMessages from @k8ordo/ui/i18n. Annotate the dictionary with Messages, and a missing or extra key is a type error, including a key the library adds later.
src/i18n.tsimport { defineLocales } from '@k8ordo/i18n';
import { registerMessages } from '@k8ordo/ui/i18n';
import { fr } from './messages/ui-fr';
export const locales = defineLocales({
ja: { timeZone: 'Asia/Tokyo', dir: 'ltr' },
fr: { timeZone: 'Europe/Paris', dir: 'ltr' },
});
registerMessages('fr', fr);Call registerMessages in the module that defines the locale set.
A regional tag such as en-US uses its language’s dictionary (en) when it has none of its own. Rendering in a locale with neither a registered nor a built-in dictionary fails with an error that names the locale, such as no built-in text for "de", and asks you to register it with registerMessages.
Replacing a few entries
src/i18n.tsimport { en, ja, registerMessages } from '@k8ordo/ui/i18n';
registerMessages('ja', { ...ja, close: '閉じる (Esc)' });
registerMessages('en', { ...en, autocompleteEmpty: 'No matches' });Spread the built-in ja or en, put the keys you want to change on top, and register the result.
Precedence
Each piece of wording comes from the first of these that has it:
- A component prop: a prop that takes wording, such as
Spinner’slabel - A registered dictionary: one passed to
registerMessages - A built-in dictionary: the Japanese and English the library ships
To change the wording in one place only, use the prop.
Wording in your own elements
dismiss-button.tsximport { getMessages } from '@k8ordo/ui/i18n';
export function DismissButton({ onDismiss }) {
const { close } = getMessages();
return (
<button aria-label={close} onClick={onDismiss} type="button">
×
</button>
);
}getMessages() from @k8ordo/ui/i18n returns the wording for the current locale. It is not a hook, so you can call it from Server and Client Components alike.
Read from getMessages() in an element returned from renderItem or in a component of your own, and the language and any replacements match the components.
Wording in props
src/components/add-to-cart.tsximport { Button } from '@k8ordo/ui';
import { add } from '../messages/cart';
export function AddToCart() {
return <Button>{add()}</Button>;
}A message written with message from @k8ordo/i18n is a function, so pass what it returns to the prop. See Messages.
Key list
Every key Messages holds. The values are read from the library’s own dictionaries.
close- Used by: Alert / Dialog / Drawer / Response
- ja: 閉じる
- en (no locale set): Close
required- Used by: FormControl
- ja: 必須
- en (no locale set): Required
loading- Used by: Spinner / Progress / Combobox
- ja: 読み込み中
- en (no locale set): Loading
avatar- Used by: Avatar
- ja: アバター
- en (no locale set): Avatar
color- Used by: Code
- ja: 色
- en (no locale set): Color
alertSuccess- Used by: Alert / Callout
- ja: 成功
- en (no locale set): Success
alertInfo- Used by: Alert / Callout
- ja: 情報
- en (no locale set): Information
alertWarning- Used by: Alert / Callout
- ja: 警告
- en (no locale set): Warning
alertError- Used by: Alert / Callout
- ja: エラー
- en (no locale set): Error
toastRegion- Used by: ToastProvider
- ja: 通知
- en (no locale set): Notifications
copy- Used by: CopyButton / Message.Copy
- ja: コピー
- en (no locale set): Copy
copied- Used by: CopyButton / CodeBlock / Message.Copy
- ja: コピーしました
- en (no locale set): Copied
copyFailed- Used by: CopyButton / CodeBlock / Message.Copy
- ja: コピーできませんでした
- en (no locale set): Could not copy
autocompletePlaceholder- Used by: Autocomplete
- ja: 入力して絞り込めます
- en (no locale set): Type to filter
autocompleteRemoveTag- Used by: Autocomplete
- ja: タグを削除
- en (no locale set): Remove tag
autocompleteClear- Used by: Autocomplete
- ja: すべて削除
- en (no locale set): Clear all
autocompleteEmpty- Used by: Autocomplete
- ja: 該当なし
- en (no locale set): No results
comboboxToggle- Used by: Combobox
- ja: 候補を開く
- en (no locale set): Show options
comboboxEmpty- Used by: Combobox
- ja: 該当なし
- en (no locale set): No results
comboboxFailed- Used by: Combobox
- ja: 候補を読み込めませんでした
- en (no locale set): Could not load options
fileFieldRemove- Used by: FileField
- ja: ファイルを削除
- en (no locale set): Remove file
fileFieldTrigger- Used by: FileField.Dropzone / FileField (generative UI)
- ja: ファイルを選択
- en (no locale set): Select files
fileFieldDrop- Used by: FileField.Dropzone / FileField (generative UI)
- ja: ここにファイルをドロップ
- en (no locale set): Drop files here
numberFieldIncrement- Used by: NumberField
- ja: 増やす
- en (no locale set): Increase
numberFieldDecrement- Used by: NumberField
- ja: 減らす
- en (no locale set): Decrease
numberFieldRangeUnderflow- Used by: NumberField
- ja: {min} 以上で入力してください
- en (no locale set): Enter {min} or more
numberFieldRangeOverflow- Used by: NumberField
- ja: {max} 以下で入力してください
- en (no locale set): Enter {max} or less
rangeSliderStart- Used by: RangeSlider
- ja: 最小
- en (no locale set): minimum
rangeSliderEnd- Used by: RangeSlider
- ja: 最大
- en (no locale set): maximum
calendarPreviousMonth- Used by: Calendar / DatePicker
- ja: 前の月
- en (no locale set): Previous month
calendarNextMonth- Used by: Calendar / DatePicker
- ja: 次の月
- en (no locale set): Next month
datePickerOpen- Used by: DatePicker
- ja: カレンダーから選ぶ
- en (no locale set): Choose from calendar
datePickerDialog- Used by: DatePicker
- ja: 日付を選ぶ
- en (no locale set): Choose a date
colorPickerHue- Used by: ColorPicker
- ja: 色相
- en (no locale set): Hue
colorPickerSaturation- Used by: ColorPicker
- ja: 彩度
- en (no locale set): Saturation
colorPickerLightness- Used by: ColorPicker
- ja: 明度
- en (no locale set): Lightness
colorPickerSwatches- Used by: ColorPicker
- ja: 色の見本
- en (no locale set): Swatches
colorPickerOpen- Used by: ColorPicker
- ja: パレットから選ぶ
- en (no locale set): Choose from palette
passwordShow- Used by: PasswordInput
- ja: パスワードを表示
- en (no locale set): Show password
passwordHide- Used by: PasswordInput
- ja: パスワードを非表示
- en (no locale set): Hide password
listBoxPlaceholder- Used by: ListBox
- ja: 選択してください
- en (no locale set): Select an option
breadcrumb- Used by: Breadcrumb
- ja: パンくずリスト
- en (no locale set): Breadcrumb
tabList- Used by: Tabs (generative UI)
- ja: タブ
- en (no locale set): Tabs
paginationLabel- Used by: Pagination
- ja: ページネーション
- en (no locale set): Pagination
paginationPrevious- Used by: Pagination
- ja: 前へ
- en (no locale set): Previous
paginationNext- Used by: Pagination
- ja: 次へ
- en (no locale set): Next
stepperComplete- Used by: Stepper
- ja: 完了
- en (no locale set): completed
dataTableColumns- Used by: DataTable
- ja: 表示する列
- en (no locale set): Columns
dataTableSelectAll- Used by: DataTable
- ja: すべての行を選択
- en (no locale set): Select all rows
dataTableSelectRow- Used by: DataTable
- ja: 行を選択
- en (no locale set): Select row
codeBlockCopy- Used by: CodeBlock
- ja: コードをコピー
- en (no locale set): Copy code
carousel- Used by: Carousel
- ja: カルーセル
- en (no locale set): Carousel
carouselSlide- Used by: Carousel.Slide
- ja: スライド
- en (no locale set): Slide
carouselPrevious- Used by: Carousel
- ja: 前のスライド
- en (no locale set): Previous slide
carouselNext- Used by: Carousel
- ja: 次のスライド
- en (no locale set): Next slide
resizablePanelsHandle- Used by: ResizablePanels.Handle
- ja: パネルの大きさ
- en (no locale set): Panel size
tableOfContents- Used by: TableOfContents
- ja: 目次
- en (no locale set): Contents
commandPalette- Used by: CommandPalette
- ja: コマンド
- en (no locale set): Commands
commandPaletteSearch- Used by: CommandPalette
- ja: コマンドを検索
- en (no locale set): Search commands
commandPaletteEmpty- Used by: CommandPalette
- ja: 一致するコマンドはありません
- en (no locale set): No matching commands
chat- Used by: Conversation.Messages
- ja: チャット
- en (no locale set): Chat
scrollToLatest- Used by: Conversation.ScrollButton
- ja: 最新のメッセージへ移動
- en (no locale set): Scroll to latest message
reasoning- Used by: Reasoning
- ja: 思考の過程
- en (no locale set): Reasoning
reasoningStreaming- Used by: Reasoning
- ja: 思考中…
- en (no locale set): Thinking…
suggestions- Used by: Suggestion.List
- ja: 候補
- en (no locale set): Suggestions
send- Used by: PromptInput
- ja: 送信
- en (no locale set): Send
stop- Used by: PromptInput
- ja: 停止
- en (no locale set): Stop
attach- Used by: PromptInput.Attach
- ja: ファイルを添付
- en (no locale set): Attach files
attachments- Used by: Attachment.List / PromptInput.Attachments
- ja: 添付ファイル
- en (no locale set): Attachments
attachmentRemove- Used by: PromptInput.Attachments
- ja: 添付を外す
- en (no locale set): Remove attachment
attachmentImage- Used by: Attachment.Item / PromptInput.Attachments
- ja: 添付画像
- en (no locale set): Attached image
sources- Used by: Source.List
- ja: 出典
- en (no locale set): Sources
messageActions- Used by: Message.Actions
- ja: メッセージの操作
- en (no locale set): Message actions
regenerate- Used by: Message.Regenerate
- ja: 再生成
- en (no locale set): Regenerate
feedbackPositive- Used by: Message.Feedback
- ja: 良い回答
- en (no locale set): Good response
feedbackNegative- Used by: Message.Feedback
- ja: 良くない回答
- en (no locale set): Bad response
toolInput- Used by: ToolInvocation
- ja: 入力
- en (no locale set): Input
toolOutput- Used by: ToolInvocation
- ja: 出力
- en (no locale set): Output
toolError- Used by: ToolInvocation
- ja: ツールの実行でエラーが発生しました。
- en (no locale set): The tool failed to run.
toolDenied- Used by: ToolInvocation
- ja: ツールの実行は許可されませんでした。
- en (no locale set): The tool run was not approved.
toolApprovalRequest- Used by: ToolInvocation
- ja: このツールの実行を許可しますか?
- en (no locale set): Allow this tool to run?
toolApprove- Used by: ToolInvocation
- ja: 許可
- en (no locale set): Allow
toolDeny- Used by: ToolInvocation
- ja: 拒否
- en (no locale set): Deny
responseCopied- Used by: Response
- ja: コピーしました
- en (no locale set): Copied
responseCopyCode- Used by: Response
- ja: コードをコピー
- en (no locale set): Copy code
responseCopyLink- Used by: Response
- ja: リンクをコピー
- en (no locale set): Copy link
responseCopyTable- Used by: Response
- ja: 表をコピー
- en (no locale set): Copy table
responseCopyTableAsCsv- Used by: Response
- ja: 表を CSV でコピー
- en (no locale set): Copy table as CSV
responseCopyTableAsMarkdown- Used by: Response
- ja: 表を Markdown でコピー
- en (no locale set): Copy table as Markdown
responseCopyTableAsTsv- Used by: Response
- ja: 表を TSV でコピー
- en (no locale set): Copy table as TSV
responseDownloadDiagram- Used by: Response
- ja: 図をダウンロード
- en (no locale set): Download diagram
responseDownloadDiagramAsMmd- Used by: Response
- ja: 図を MMD でダウンロード
- en (no locale set): Download diagram as MMD
responseDownloadDiagramAsPng- Used by: Response
- ja: 図を PNG でダウンロード
- en (no locale set): Download diagram as PNG
responseDownloadDiagramAsSvg- Used by: Response
- ja: 図を SVG でダウンロード
- en (no locale set): Download diagram as SVG
responseDownloadFile- Used by: Response
- ja: ファイルをダウンロード
- en (no locale set): Download file
responseDownloadImage- Used by: Response
- ja: 画像をダウンロード
- en (no locale set): Download image
responseDownloadTable- Used by: Response
- ja: 表をダウンロード
- en (no locale set): Download table
responseDownloadTableAsCsv- Used by: Response
- ja: 表を CSV でダウンロード
- en (no locale set): Download table as CSV
responseDownloadTableAsMarkdown- Used by: Response
- ja: 表を Markdown でダウンロード
- en (no locale set): Download table as Markdown
responseExitFullscreen- Used by: Response
- ja: 全画面表示を終了
- en (no locale set): Exit fullscreen
responseViewFullscreen- Used by: Response
- ja: 全画面表示
- en (no locale set): View fullscreen
responseImageNotAvailable- Used by: Response
- ja: 画像を表示できません
- en (no locale set): Image not available
responseOpenExternalLink- Used by: Response
- ja: 外部リンクを開きますか?
- en (no locale set): Open external link?
responseExternalLinkWarning- Used by: Response
- ja: 外部サイトに移動しようとしています。
- en (no locale set): You're about to visit an external website.
responseOpenLink- Used by: Response
- ja: リンクを開く
- en (no locale set): Open link
| Key | Used by | ja | en (no locale set) |
|---|---|---|---|
close | Alert / Dialog / Drawer / Response | 閉じる | Close |
required | FormControl | 必須 | Required |
loading | Spinner / Progress / Combobox | 読み込み中 | Loading |
avatar | Avatar | アバター | Avatar |
color | Code | 色 | Color |
alertSuccess | Alert / Callout | 成功 | Success |
alertInfo | Alert / Callout | 情報 | Information |
alertWarning | Alert / Callout | 警告 | Warning |
alertError | Alert / Callout | エラー | Error |
toastRegion | ToastProvider | 通知 | Notifications |
copy | CopyButton / Message.Copy | コピー | Copy |
copied | CopyButton / CodeBlock / Message.Copy | コピーしました | Copied |
copyFailed | CopyButton / CodeBlock / Message.Copy | コピーできませんでした | Could not copy |
autocompletePlaceholder | Autocomplete | 入力して絞り込めます | Type to filter |
autocompleteRemoveTag | Autocomplete | タグを削除 | Remove tag |
autocompleteClear | Autocomplete | すべて削除 | Clear all |
autocompleteEmpty | Autocomplete | 該当なし | No results |
comboboxToggle | Combobox | 候補を開く | Show options |
comboboxEmpty | Combobox | 該当なし | No results |
comboboxFailed | Combobox | 候補を読み込めませんでした | Could not load options |
fileFieldRemove | FileField | ファイルを削除 | Remove file |
fileFieldTrigger | FileField.Dropzone / FileField (generative UI) | ファイルを選択 | Select files |
fileFieldDrop | FileField.Dropzone / FileField (generative UI) | ここにファイルをドロップ | Drop files here |
numberFieldIncrement | NumberField | 増やす | Increase |
numberFieldDecrement | NumberField | 減らす | Decrease |
numberFieldRangeUnderflow | NumberField | {min} 以上で入力してください | Enter {min} or more |
numberFieldRangeOverflow | NumberField | {max} 以下で入力してください | Enter {max} or less |
rangeSliderStart | RangeSlider | 最小 | minimum |
rangeSliderEnd | RangeSlider | 最大 | maximum |
calendarPreviousMonth | Calendar / DatePicker | 前の月 | Previous month |
calendarNextMonth | Calendar / DatePicker | 次の月 | Next month |
datePickerOpen | DatePicker | カレンダーから選ぶ | Choose from calendar |
datePickerDialog | DatePicker | 日付を選ぶ | Choose a date |
colorPickerHue | ColorPicker | 色相 | Hue |
colorPickerSaturation | ColorPicker | 彩度 | Saturation |
colorPickerLightness | ColorPicker | 明度 | Lightness |
colorPickerSwatches | ColorPicker | 色の見本 | Swatches |
colorPickerOpen | ColorPicker | パレットから選ぶ | Choose from palette |
passwordShow | PasswordInput | パスワードを表示 | Show password |
passwordHide | PasswordInput | パスワードを非表示 | Hide password |
listBoxPlaceholder | ListBox | 選択してください | Select an option |
breadcrumb | Breadcrumb | パンくずリスト | Breadcrumb |
tabList | Tabs (generative UI) | タブ | Tabs |
paginationLabel | Pagination | ページネーション | Pagination |
paginationPrevious | Pagination | 前へ | Previous |
paginationNext | Pagination | 次へ | Next |
stepperComplete | Stepper | 完了 | completed |
dataTableColumns | DataTable | 表示する列 | Columns |
dataTableSelectAll | DataTable | すべての行を選択 | Select all rows |
dataTableSelectRow | DataTable | 行を選択 | Select row |
codeBlockCopy | CodeBlock | コードをコピー | Copy code |
carousel | Carousel | カルーセル | Carousel |
carouselSlide | Carousel.Slide | スライド | Slide |
carouselPrevious | Carousel | 前のスライド | Previous slide |
carouselNext | Carousel | 次のスライド | Next slide |
resizablePanelsHandle | ResizablePanels.Handle | パネルの大きさ | Panel size |
tableOfContents | TableOfContents | 目次 | Contents |
commandPalette | CommandPalette | コマンド | Commands |
commandPaletteSearch | CommandPalette | コマンドを検索 | Search commands |
commandPaletteEmpty | CommandPalette | 一致するコマンドはありません | No matching commands |
chat | Conversation.Messages | チャット | Chat |
scrollToLatest | Conversation.ScrollButton | 最新のメッセージへ移動 | Scroll to latest message |
reasoning | Reasoning | 思考の過程 | Reasoning |
reasoningStreaming | Reasoning | 思考中… | Thinking… |
suggestions | Suggestion.List | 候補 | Suggestions |
send | PromptInput | 送信 | Send |
stop | PromptInput | 停止 | Stop |
attach | PromptInput.Attach | ファイルを添付 | Attach files |
attachments | Attachment.List / PromptInput.Attachments | 添付ファイル | Attachments |
attachmentRemove | PromptInput.Attachments | 添付を外す | Remove attachment |
attachmentImage | Attachment.Item / PromptInput.Attachments | 添付画像 | Attached image |
sources | Source.List | 出典 | Sources |
messageActions | Message.Actions | メッセージの操作 | Message actions |
regenerate | Message.Regenerate | 再生成 | Regenerate |
feedbackPositive | Message.Feedback | 良い回答 | Good response |
feedbackNegative | Message.Feedback | 良くない回答 | Bad response |
toolInput | ToolInvocation | 入力 | Input |
toolOutput | ToolInvocation | 出力 | Output |
toolError | ToolInvocation | ツールの実行でエラーが発生しました。 | The tool failed to run. |
toolDenied | ToolInvocation | ツールの実行は許可されませんでした。 | The tool run was not approved. |
toolApprovalRequest | ToolInvocation | このツールの実行を許可しますか? | Allow this tool to run? |
toolApprove | ToolInvocation | 許可 | Allow |
toolDeny | ToolInvocation | 拒否 | Deny |
responseCopied | Response | コピーしました | Copied |
responseCopyCode | Response | コードをコピー | Copy code |
responseCopyLink | Response | リンクをコピー | Copy link |
responseCopyTable | Response | 表をコピー | Copy table |
responseCopyTableAsCsv | Response | 表を CSV でコピー | Copy table as CSV |
responseCopyTableAsMarkdown | Response | 表を Markdown でコピー | Copy table as Markdown |
responseCopyTableAsTsv | Response | 表を TSV でコピー | Copy table as TSV |
responseDownloadDiagram | Response | 図をダウンロード | Download diagram |
responseDownloadDiagramAsMmd | Response | 図を MMD でダウンロード | Download diagram as MMD |
responseDownloadDiagramAsPng | Response | 図を PNG でダウンロード | Download diagram as PNG |
responseDownloadDiagramAsSvg | Response | 図を SVG でダウンロード | Download diagram as SVG |
responseDownloadFile | Response | ファイルをダウンロード | Download file |
responseDownloadImage | Response | 画像をダウンロード | Download image |
responseDownloadTable | Response | 表をダウンロード | Download table |
responseDownloadTableAsCsv | Response | 表を CSV でダウンロード | Download table as CSV |
responseDownloadTableAsMarkdown | Response | 表を Markdown でダウンロード | Download table as Markdown |
responseExitFullscreen | Response | 全画面表示を終了 | Exit fullscreen |
responseViewFullscreen | Response | 全画面表示 | View fullscreen |
responseImageNotAvailable | Response | 画像を表示できません | Image not available |
responseOpenExternalLink | Response | 外部リンクを開きますか? | Open external link? |
responseExternalLinkWarning | Response | 外部サイトに移動しようとしています。 | You're about to visit an external website. |
responseOpenLink | Response | リンクを開く | Open link |