Dictionary (Database Translations)

Moves static UI translation keys into a localized Payload collection that editors can manage and Next.js reads through a cached helper.

Community 2 MIT v1.0.0

Installation

pnpm add payload-plugin-dictionary

About

This plugin adds a `translations` collection to Payload, grouped under a "Dictionary" admin section. Each document holds a namespace (chosen from the list you pass to the plugin), a dot-separated key such as `auth.login_button`, and a localized `value` field. The goal is to move frontend microcopy like button labels, nav items, and error messages out of `en.json`-style files and into the admin panel, so editors can change them without a code deploy. On the Next.js side, the package exports a `getTranslations` helper and a `getDictionary` function from `payload-plugin-dictionary/cache`. These wrap database reads in `unstable_cache` under the tag `payload-translations`. An `afterChange` and `afterDelete` hook on the collection calls `revalidateTag` on that tag, so cached dictionaries refresh after an edit. The client entry point provides `DictionaryProvider` and a `useTranslations()` hook for Client Components. The `t` function supports `{var}` interpolation and a fallback string when a key is missing. The plugin also registers a `GET /api/dictionary/:namespace?locale=` REST endpoint with HTTP caching headers, and a `payload-dictionary` CLI that generates TypeScript types from the stored keys. There are some limits to be aware of. The plugin requires a namespaces array and throws at startup if it is empty. Key uniqueness is enforced in two places: the `key` field is marked unique, and a `beforeValidate` hook checks the `(namespace, key)` pair. Keys may not contain whitespace. The package targets Payload 3.90 or later, Next.js 15 or 16, and React 19. The `react` peer dependency is optional and only needed for the client helpers. Its `next-intl` and `i18next` compatibility is described in the README as a way to feed stored messages into those libraries.

Package info

Package name
payload-plugin-dictionary
Latest version
1.0.0
Unpacked size
446 kB
License
MIT
Last publish
Oct 12, 2026

More from Mhmod-Hsn

View profile

Similar plugins

More in i18n