Web · APIs and utilities
Language (i18n)
Defines the main dictionary.
Import
defineMessages
functionDefines the main dictionary. Texts are stored as-is (with literal string types) so keys and {name} placeholders are inferred from the type. Library texts can be overridden in the ui namespace.
Examples
createI18n
functionSets up the project's locale configuration. Called once, in a file that is not "use client"; server and client use the same object.
- The default locale's dictionary is the type source: keys and placeholders are checked automatically. To carry the type to
useTas well, addmessagesto theRegisterinterface. - The library's own texts ("Close", "Cancel"…) live in the
uinamespace of the same dictionary; Turkish is the default,enMessagesis a ready English set, and any key can be overridden. - Other locales given via
import()are loaded only when needed.
Examples
enMessages
constantAll library texts, in English. Pass it to the dictionary's ui namespace; it is only bundled into projects that import it.
Examples
trMessages
constantAll library texts, in Turkish. Components already use these by default; import this object to see and override all of them in the dictionary, or as a starting point for translating another language.
Examples
formatMessage
functionFills {name} placeholders. Numbers and dates are formatted per locale (1,234.5, Nov 3, 2026); placeholders without a value are left as-is.
Examples
createTranslator
functionCreates a Translator (t) from a dictionary. Works on the server, the client and outside React. In Next.js, i18n.getT(locale) (createI18n) or useT on the client is usually used instead.
When namespace is given, keys are relative to that namespace: createTranslator(m, "en", "home")("title") → home.title.
Examples
mergeMessages
functionDeep-merges dictionaries; later ones win. Used to fill missing translations from the default locale and by nested UIProviders.
Examples
useT
functionTranslator (t) for client components. The dictionary and locale come from the nearest UIProvider's messages and locale props; in server components use await i18n.getT(locale) (createI18n).
Keys and placeholders are checked against the dictionary given to Register. When namespace is given, keys are relative to it. The returned function stays the same until the locale or dictionary changes.
Examples
LocaleSource
typeA locale's dictionary: a ready object or () => import("./en") that loads it.
I18nConfig
interfaceSettings for createI18n.
| Name | Type | Description |
|---|---|---|
locales | Readonly<Record<string, LocaleSource>> | Locales and their dictionaries. The default locale is usually given directly; others given as () => import("./messages/tr") are loaded only when needed and stay in a separate chunk. |
defaultLocale | string | Default locale: used when no locale matches, and missing keys in other locales are filled from it. |
I18n
interfaceResult of createI18n.
| Name | Type | Description |
|---|---|---|
locales | readonly L[] | Supported languages. |
defaultLocale | L | Base language. |
isLocale | (value: unknown): value is L | Whether the value is a supported locale (e.g. [lang] in the URL). |
match | (request?: string | readonly string[] | null): L | Returns the supported locale that best matches the requested one, or the default locale. Accepts an Accept-Language header ("en-US,en;q=0.9"), a list of locales (navigator.languages) or a single locale. If en-US is requested and only en exists, en is chosen. |
load | (locale?: string | null): Promise<M> | Loads a locale's dictionary; missing keys are filled from the default locale. The result is cached. For an unsupported locale the closest one is chosen via I18n.match. Pass the result to UIProvider's messages. |
A namespace's dictionary (behaves like a root other than ui).
PluralCategory
typeIntl.PluralRules plural categories. one and other are enough for English and Turkish; languages such as Arabic or Russian use the others too.
PluralMessage
typeText that varies with a number. The {count} placeholder and which form is chosen come from the number passed as t("key", { count }); selection follows the locale's rules (Intl.PluralRules), and other is used when no form matches.
Only an object made solely of plural categories (zero, one, two, few, many, other) that contains other counts as plural text, so do not put keys with only these names in a namespace.
| Name | Type | Description |
|---|---|---|
other | string | All other numbers; always required. |
Examples
MessageValue
typeA text: plain text, plural text or a nested namespace.
MessageTree
interfaceNested namespaces; keys are joined with dots ("home.title").
UIMessagesInput
typeThe overridden part of the library texts. Plain texts are given directly; those of large components (kanban, dataGrid, eventCalendar, richText, mediaEditor) in their own namespaces.
Messages
interfaceAll texts of a locale: the app's own namespaces and the ui namespace for library texts.
| Name | Type | Description |
|---|---|---|
ui? | UIMessagesInput | Texts of the library components; provide only the ones you want to change. |
Examples
MessageParam
typeA value that can be passed to a {name} placeholder; numbers and dates are formatted per locale.
MessageParams
typePlaceholder values.
MessageKey
typeText keys in the registered dictionary ("home.title"). If Register is not extended, any string is accepted.
MessageNamespace
typeNamespaces in the registered dictionary ("home", "home.hero"); see useT.
MessageAt
typeThe value of a key in the dictionary.
ParamNames
typeNames of the {name} placeholders in a text.
TranslateArgs
typeArguments after the key in a t(key, ...) call.
Translator
interfaceFunction that translates text from the dictionary. Keys and placeholders are inferred from the dictionary's type: a wrong key or missing value is a compile error.
| Name | Type | Description |
|---|---|---|
locale | string | Locale of the translation (BCP 47). |
has | (key: string): boolean | Whether the key exists in the dictionary. |
Examples
The project's dictionary type. Once messages is added to the Register interface, useT, createI18n and Translation use this type.
Translation
typeAnother locale's dictionary, shaped after the default locale's dictionary. All keys are required and every text must contain the default locale's placeholders ({name}); a missing key or forgotten placeholder is a compile error. Plural texts may use the locale's own categories. The ui namespace is optional.
By default the dictionary given to Register is used.
Extends: string extends keyof M> extends true ? Messages : TranslationOf<AppPart<M> ? true : false
| Name | Type | Description |
|---|---|---|
ui? | UIMessagesInput | Library texts; e.g. the ready English set enMessages. |