DocsReact
Dictionaries
Keyed strings with dot-path ids, for teams that prefer a dictionary file over inline text.
On this page
A dictionary is a nested JSON file of messages addressed by id. It is the keyed alternative to inline <T> and t("..."). Both feed the same pipeline: each entry is hashed from its source text (plus optional context), so the id is a lookup convenience, not part of the key. Entries share translations with inline strings that have identical text and context.
File format
Leaves are either a message string or a two-element array of message and metadata. Ids are dot paths.
{
"nav": { "home": "Home", "pricing": "Pricing" },
"actions": { "save": ["Save", { "context": "button label" }] },
"cart": { "items": "{count, plural, one {# item} other {# items}}" }
}
Messages are ICU messages (see Message format). Ids here are nav.home, nav.pricing, actions.save and cart.items.
Configure
Point the CLI at the file in generic-translation.config.json:
{ "dictionary": "dictionary.json" }
generic-translation extract and generic-translation translate include its entries. With generic-translation validate, calls such as d("nav.hmoe") are checked against the file’s ids.
Pass the same content to the provider:
import dictionary from "./dictionary.json";
<GenericTranslationProvider dictionary={dictionary} ... />
In Next.js the server provider loads it for you from the dictionary path in generic-translation.config.json (withGenericTranslation exports it to the server as GENERIC_TRANSLATION_DICTIONARY_PATH), or you can pass dictionary explicitly.
Use
Client components:
const d = useDictionary();
d("nav.home");
d("cart.items", { count: 3 });
Server components (Next.js):
import { getDictionary } from "@generic-translation/react/next";
const d = await getDictionary();
d("nav.home");
An unknown id returns the id itself and logs a warning in development. Translated text is validated against the source: a translation with different variables or tags is discarded in favour of the source.
Notes
- Changing an entry’s text or its
contextchanges its hash and requires a new translation. Renaming an id does not. - Arrays must start with the message string; the metadata object may carry
context. - Prefer inline
<T>for rich content with elements, and a dictionary for short, shared UI labels.
Something wrong or unclear on this page? Open an issue.