StringsProvider
StringsProvider sets the text Todae writes by itself for everything inside it: the default names of parts with no words of their own, such as an icon-only Dialog.Close, and screen reader messages, such as those of Field.Counter. Todae ships English only. Pass the keys you want to change; each key you leave out comes from the nearest StringsProvider above, else English. It renders no element.
On this page
const korean: Partial<Strings> = {
close: '닫기',
dismiss: '닫기',
removeChip: (label) => `${label} 삭제`,
moreChips: (count) => `${count}개 더 있음`,
characterLimit: (max) => `최대 ${max}자`,
charactersLeft: (remaining) => `${remaining}자 남음`,
characterLimitReached: '글자 수 한도에 도달했습니다',
}
<StringsProvider strings={korean}>
<App />
</StringsProvider>
A nested provider changes only the keys it passes:
<StringsProvider strings={korean}>
<StringsProvider strings={{ close: '취소' }}>
{/* close is 취소 here; every other key is still Korean. */}
</StringsProvider>
</StringsProvider>
A part's own prop still wins over the provider: a non-empty aria-label on a close button, Attachment.Remove, Conversation.ScrollButton or landmark, removeLabel on Chip.Root, removeLabel, overflowLabel or panelLabel on ChipList.Root, chipRemoveLabel or overflowLabel on Field.ChipInput, a non-empty statusLabel on Steps.Item, and createLabel on useCombobox. useStrings() returns the strings in effect, for your own components.
Strings
A string that depends on a number or a label is a function.
| Key | Used by | English |
|---|---|---|
close | Dialog.Close, Drawer.Close, BottomSheet.Close without words | Close |
dismiss | Alert.Close, Toast.Close without words | Dismiss |
notifications | Toast.Region landmark | Notifications |
breadcrumbs | Breadcrumbs.Root landmark | Breadcrumb |
pagination | Pagination.Root landmark | Pagination |
contents | Contents.Root landmark | On this page |
resizeSheet | BottomSheet.Grabber | Resize sheet |
resizePanel | Splitter.Handle with no aria-label or aria-labelledby | Resize |
options | getSheetProps() and getDialogProps() of useCombobox | Options |
removeChip(label) | Chip remove buttons | Remove {label} |
removeAttachment(name) | Attachment.Remove with no content, given Attachment.Name's text, or an empty string without one | Remove {name}, or Remove with no name |
moreChips(count) | +N chips | {count} more |
moreChipsPanel(count) | ChipList popover of folded chips | {count} more chips, or 1 more chip |
characterLimit(max) | Field.Counter, the input's description | Up to {max} characters |
charactersLeft(remaining) | Field.Counter, from 20 left | {remaining} characters left, or 1 character left |
characterLimitReached | Field.Counter, at or past the limit | Character limit reached |
createOption(query) | useCombobox's create row, without createLabel | Create "{query}" |
suggestions | useMentions' list, without a trigger label | Suggestions |
suggestionCount(count) | useMentions, when its list opens or its count changes | 3 suggestions, No suggestions |
saturation | ColorPicker.Area, its left-to-right input | Saturation |
brightness | ColorPicker.Area, its bottom-to-top input | Brightness |
hue | ColorPicker.Hue, without aria-label | Hue |
colorPicker | A Field.Picker with swatch and no typed input beside it: its popover, and its button beside another control | Color picker |
datePicker | A Field.Picker beside a Field.DateInput: its popover and its button | Choose date |
timePicker | A Field.Picker beside a Field.TimeInput: its popover and its button | Choose time |
dateTimePicker | A Field.Picker beside a Field.DateTimeInput: its popover and its button | Choose date and time |
dateRangePicker | A Field.Picker beside a Field.DateRangeInput: its popover and its button | Choose dates |
picker | A Field.Picker with no typed input beside it and no swatch: its popover, and its button beside another control | Open picker |
increment(field) | Field.Increment, unless its own text names it, given the text of its Field.NumberInput's label, or an empty string without one | Increase {field}, or Increase with no label |
decrement(field) | Field.Decrement, unless its own text names it, given the text of its Field.NumberInput's label, or an empty string without one | Decrease {field}, or Decrease with no label |
previousMonth | Calendar.Header's previous-month button | Previous month |
nextMonth | Calendar.Header's next-month button | Next month |
previousYears | Calendar.Header's button to the previous page of years | Previous years |
nextYears | Calendar.Header's button to the next page of years | Next years |
pickEndDate | Calendar in range mode, announced after the first pick | Choose an end date |
copied | useClipboard, after a copy | Copied |
copyFailed | useClipboard, when a copy fails | Could not copy |
sortedAscending(column) | Table.SortButton, after its column becomes sorted in ascending order | Sorted by {column}, ascending |
sortedDescending(column) | Table.SortButton, after its column becomes sorted in descending order | Sorted by {column}, descending |
sortCleared(column) | Table.SortButton, after its column is no longer sorted | {column}, not sorted |
conversation | Conversation.Viewport's region, without aria-label or aria-labelledby | Conversation |
scrollToLatest | Conversation.ScrollButton with no content | Scroll to latest message |
messageStarted | Conversation, when a message starts arriving | New message |
messageFinished | Conversation, when a message finishes arriving | Message complete |
stepDone | Steps.Item's hidden status word for a done step | Done |
stepCurrent | Steps.Item's hidden status word for the current step | In progress |
stepPending | Steps.Item's hidden status word for a pending step | Not started |
stepError | Steps.Item's hidden status word for a step with an error | Failed |
back | Drilldown.Back when its own text does not name it and the view below has no label | Back |
backTo(label) | Drilldown.Back when its own text does not name it, with the label of the view it goes back to | Back to {label} |
required | What a required ChipInput's text box is described by, since the text box is not what aria-required says is required | Required |
valueMissing | A control the browser reports empty though it is required, shown by ErrorMessage.Root and Form.Summary | This field is required |
typeMismatchEmail | An email input whose value is not an email address | Enter an email address |
typeMismatchUrl | A url input whose value is not a URL | Enter a URL |
typeMismatch | An input whose value does not fit its type, other than email and url | Enter a value in the right format |
badInput | An input whose entry the browser cannot turn into a value | Enter a valid value |
patternMismatch | An input whose value does not match its pattern | Match the requested format |
tooShort(min) | A value shorter than minLength | Use at least {min} characters |
tooLong(max) | A value longer than maxLength | Use at most {max} characters |
rangeUnderflow(min) | A value below min; min is the attribute's text | Enter {min} or more |
rangeOverflow(max) | A value above max; max is the attribute's text | Enter {max} or less |
dateRangeUnderflow(min) | A date, time, date and time, or range of dates before min; min is in the field's own format | Enter {min} or later |
dateRangeOverflow(max) | A date, time, date and time, or range of dates after max; max is in the field's own format | Enter {max} or earlier |
stepMismatch | A value that does not fit step | Enter a value that fits the allowed steps |
formErrors(count) | Form.Summary's title | {count} problems to fix |
Breadcrumbs and Pagination from the server entries, @tounsoo/todae/breadcrumbs and @tounsoo/todae/pagination, render on the server without context, so they always use English. Pass aria-label, or import them from @tounsoo/todae to use the provider.
Accessible composition
Todae handles: The text Todae writes by itself: default names of close buttons, landmarks, chip and attachment remove buttons, the +N chip and Conversation.ScrollButton, the sheet name from useCombobox, and the live messages of Field.Counter, useClipboard, Table.SortButton and Conversation, with the counter's description, and the status words of Steps.Item, and the validation text of ErrorMessage.Root and Form.Summary. A part's own prop wins, as listed above.
You supply: Every key your app shows, in the reader's language. The function keys get the label or the number, so place it where your language needs it and pick the plural form there. StringsProvider renders no element and sets no lang, so set lang on <html>, or on an element around a part in another language, so screen readers pronounce the words right. For Breadcrumbs and Pagination from the server entries, pass aria-label yourself, as above.
Watch for: An empty string. Unlike undefined, it replaces the string above it, so a close button with no words of its own loses the name Todae would have given it. Expecting close or dismiss to name a close button that shows words: the button is named by its own words, and the key is not used.
When to use
StringsProvider
When: Your app is not in English, or you want other wording for Todae's own text, across a whole app or one part of it.
When not: A name for one part → pass its prop, such as aria-label. Text you write yourself, such as a dialog title → it is yours to translate.
useStrings
When: A component of your own that writes text Todae's strings cover, such as a close button's name.
When not: Text only your component writes → your own translations.
Props
| Name | Type | Description |
|---|---|---|
strings Required | Partial<Strings> | The strings to change. Each key left out comes from the nearest StringsProvider above, else English. A component prop such as aria-label still wins. |
children | React.ReactNode | Subtree that uses these strings. |