@k8ordo/ui

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.ts
import { 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.

Warning

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.ts
import { 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.ts
import 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.ts
import { 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.ts
import { 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:

  1. A component prop: a prop that takes wording, such as Spinner’s label
  2. A registered dictionary: one passed to registerMessages
  3. 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.tsx
import { 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.tsx
import { 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
KeyUsed byjaen (no locale set)
closeAlert / Dialog / Drawer / Response閉じるClose
requiredFormControl必須Required
loadingSpinner / Progress / Combobox読み込み中Loading
avatarAvatarアバターAvatar
colorCode色Color
alertSuccessAlert / Callout成功Success
alertInfoAlert / Callout情報Information
alertWarningAlert / Callout警告Warning
alertErrorAlert / CalloutエラーError
toastRegionToastProvider通知Notifications
copyCopyButton / Message.CopyコピーCopy
copiedCopyButton / CodeBlock / Message.CopyコピーしましたCopied
copyFailedCopyButton / CodeBlock / Message.CopyコピーできませんでしたCould not copy
autocompletePlaceholderAutocomplete入力して絞り込めますType to filter
autocompleteRemoveTagAutocompleteタグを削除Remove tag
autocompleteClearAutocompleteすべて削除Clear all
autocompleteEmptyAutocomplete該当なしNo results
comboboxToggleCombobox候補を開くShow options
comboboxEmptyCombobox該当なしNo results
comboboxFailedCombobox候補を読み込めませんでしたCould not load options
fileFieldRemoveFileFieldファイルを削除Remove file
fileFieldTriggerFileField.Dropzone / FileField (generative UI)ファイルを選択Select files
fileFieldDropFileField.Dropzone / FileField (generative UI)ここにファイルをドロップDrop files here
numberFieldIncrementNumberField増やすIncrease
numberFieldDecrementNumberField減らすDecrease
numberFieldRangeUnderflowNumberField{min} 以上で入力してくださいEnter {min} or more
numberFieldRangeOverflowNumberField{max} 以下で入力してくださいEnter {max} or less
rangeSliderStartRangeSlider最小minimum
rangeSliderEndRangeSlider最大maximum
calendarPreviousMonthCalendar / DatePicker前の月Previous month
calendarNextMonthCalendar / DatePicker次の月Next month
datePickerOpenDatePickerカレンダーから選ぶChoose from calendar
datePickerDialogDatePicker日付を選ぶChoose a date
colorPickerHueColorPicker色相Hue
colorPickerSaturationColorPicker彩度Saturation
colorPickerLightnessColorPicker明度Lightness
colorPickerSwatchesColorPicker色の見本Swatches
colorPickerOpenColorPickerパレットから選ぶChoose from palette
passwordShowPasswordInputパスワードを表示Show password
passwordHidePasswordInputパスワードを非表示Hide password
listBoxPlaceholderListBox選択してくださいSelect an option
breadcrumbBreadcrumbパンくずリストBreadcrumb
tabListTabs (generative UI)タブTabs
paginationLabelPaginationページネーションPagination
paginationPreviousPagination前へPrevious
paginationNextPagination次へNext
stepperCompleteStepper完了completed
dataTableColumnsDataTable表示する列Columns
dataTableSelectAllDataTableすべての行を選択Select all rows
dataTableSelectRowDataTable行を選択Select row
codeBlockCopyCodeBlockコードをコピーCopy code
carouselCarouselカルーセルCarousel
carouselSlideCarousel.SlideスライドSlide
carouselPreviousCarousel前のスライドPrevious slide
carouselNextCarousel次のスライドNext slide
resizablePanelsHandleResizablePanels.Handleパネルの大きさPanel size
tableOfContentsTableOfContents目次Contents
commandPaletteCommandPaletteコマンドCommands
commandPaletteSearchCommandPaletteコマンドを検索Search commands
commandPaletteEmptyCommandPalette一致するコマンドはありませんNo matching commands
chatConversation.MessagesチャットChat
scrollToLatestConversation.ScrollButton最新のメッセージへ移動Scroll to latest message
reasoningReasoning思考の過程Reasoning
reasoningStreamingReasoning思考中…Thinking…
suggestionsSuggestion.List候補Suggestions
sendPromptInput送信Send
stopPromptInput停止Stop
attachPromptInput.Attachファイルを添付Attach files
attachmentsAttachment.List / PromptInput.Attachments添付ファイルAttachments
attachmentRemovePromptInput.Attachments添付を外すRemove attachment
attachmentImageAttachment.Item / PromptInput.Attachments添付画像Attached image
sourcesSource.List出典Sources
messageActionsMessage.Actionsメッセージの操作Message actions
regenerateMessage.Regenerate再生成Regenerate
feedbackPositiveMessage.Feedback良い回答Good response
feedbackNegativeMessage.Feedback良くない回答Bad response
toolInputToolInvocation入力Input
toolOutputToolInvocation出力Output
toolErrorToolInvocationツールの実行でエラーが発生しました。The tool failed to run.
toolDeniedToolInvocationツールの実行は許可されませんでした。The tool run was not approved.
toolApprovalRequestToolInvocationこのツールの実行を許可しますか?Allow this tool to run?
toolApproveToolInvocation許可Allow
toolDenyToolInvocation拒否Deny
responseCopiedResponseコピーしましたCopied
responseCopyCodeResponseコードをコピーCopy code
responseCopyLinkResponseリンクをコピーCopy link
responseCopyTableResponse表をコピーCopy table
responseCopyTableAsCsvResponse表を CSV でコピーCopy table as CSV
responseCopyTableAsMarkdownResponse表を Markdown でコピーCopy table as Markdown
responseCopyTableAsTsvResponse表を TSV でコピーCopy table as TSV
responseDownloadDiagramResponse図をダウンロードDownload diagram
responseDownloadDiagramAsMmdResponse図を MMD でダウンロードDownload diagram as MMD
responseDownloadDiagramAsPngResponse図を PNG でダウンロードDownload diagram as PNG
responseDownloadDiagramAsSvgResponse図を SVG でダウンロードDownload diagram as SVG
responseDownloadFileResponseファイルをダウンロードDownload file
responseDownloadImageResponse画像をダウンロードDownload image
responseDownloadTableResponse表をダウンロードDownload table
responseDownloadTableAsCsvResponse表を CSV でダウンロードDownload table as CSV
responseDownloadTableAsMarkdownResponse表を Markdown でダウンロードDownload table as Markdown
responseExitFullscreenResponse全画面表示を終了Exit fullscreen
responseViewFullscreenResponse全画面表示View fullscreen
responseImageNotAvailableResponse画像を表示できませんImage not available
responseOpenExternalLinkResponse外部リンクを開きますか?Open external link?
responseExternalLinkWarningResponse外部サイトに移動しようとしています。You're about to visit an external website.
responseOpenLinkResponseリンクを開くOpen link
k8ordo

React libraries that use Baseline features without holding back.