payload-localization
Skill0 starsChanged 13 days agoMITView on GitHub
Multilingual Payload CMS 3 + Next.js sites - content locales, RTL (Arabic), translated admin interface that stays in sync with the content locale, next-intl localized routes with proxy.ts, and live preview in the editing language. Use when a site has more than one language, needs RTL, when the admin should switch language and direction together with the content being edited, or when localized pages show the wrong language.
- Installs packages
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-guardrailsSkill
- creative-frontendSkill
- figma-handoffSkill
- payload-admin-brandingSkill
- payload-auth-rbacSkill
- payload-bookings-paymentsSkill
- payload-bootstrapSkill
- payload-deploy-vercelSkill
- payload-forms-crmSkill
- payload-integrationsSkill
- payload-legal-trustSkill
- payload-live-previewSkill
- payload-mcpSkill
- payload-mediaSkill
- payload-performanceSkill
- payload-project-kickoffSkill
- payload-seo-geoSkill
- payload-testingSkill
- project-architectureSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 75
When an editor opens the admin, the content locale switches to the admin language.
- Distinctive: line 76
When the editor changes the admin language (account settings), the content locale follows.
- Distinctive: line 77
When the editor picks a locale in the document header, the admin language and direction follow.
- Very specific: line 84
Add localized: true to text content: titles, rich text, excerpts, SEO fields, image alt.
- Distinctive: line 85
Do not localize slugs (unless translated URLs are required), relationships, numbers, prices, dates, or status fields.
- Very specific: line 87
Run pnpm generate:types. With SQLite, localized fields create _locales tables.
- Very specific: line 101
Every payload.find on the frontend passes locale.
- Very specific: line 103
Use logical CSS properties and Tailwind logical utilities (ms-4, pe-2, text-start) so RTL works without separate styles.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Payload localization
Two separate Payload features work together here:
| Feature | Config key | Controls |
| Admin interface language | i18n | Labels, buttons, and direction of the admin UI |
| Content localization | localization | Which language version of a document is edited and served |
The target behavior: an editor who works in Arabic sees an Arabic RTL admin, edits Arabic content, and the live preview shows the Arabic page. Switching either the admin language or the content locale switches both.
Step 1: One locale list for the whole project
src/i18n/locales.ts:
export const locales = ['en', 'ar'] as const
export type AppLocale = (typeof locales)[number]
export const defaultLocale: AppLocale = 'en'
export const rtlLocales: ReadonlySet<AppLocale> = new Set<AppLocale>(['ar'])
export const localeLabels: Record<AppLocale, string> = { en: 'English', ar: 'Arabic' }Payload config and next-intl both import from this file, so they never drift.
Step 2: Payload config
Install the translations package at the same version as payload: pnpm add @payloadcms/translations@<payload version>.
import { ar } from '@payloadcms/translations/languages/ar'
import { en } from '@payloadcms/translations/languages/en'
import { defaultLocale, localeLabels, locales, rtlLocales } from './i18n/locales'
// inside buildConfig({ ... })
i18n: {
supportedLanguages: { en, ar },
fallbackLanguage: defaultLocale,
},
localization: {
locales: locales.map((code) => ({ code, label: localeLabels[code], rtl: rtlLocales.has(code) })),
defaultLocale,
fallback: true,
},supportedLanguages keys must match the locale codes, or the sync in Step 3 cannot pair them.
Step 3: Sync admin language and content locale
- Copy assets/LocaleLanguageSync.tsx to
src/components/admin/LocaleLanguageSync.tsx. - Register it as an admin provider:
admin: {
components: {
providers: ['@/components/admin/LocaleLanguageSync#LocaleLanguageSync'],
},
},- Run
pnpm generate:importmap.
Behavior:
- When an editor opens the admin, the content locale switches to the admin language.
- When the editor changes the admin language (account settings), the content locale follows.
- When the editor picks a locale in the document header, the admin language and direction follow.
- Live preview recomputes its URL with the new locale (set up in
payload-live-preview), so the iframe follows too.
Skip this step only if PROJECT.md says editors must edit one language while the admin stays in another.
Step 4: Localize fields
- Add
localized: trueto text content: titles, rich text, excerpts, SEO fields, imagealt. - Do not localize slugs (unless translated URLs are required), relationships, numbers, prices, dates, or status fields.
- Drafts skip required-field validation; publishing does not. A required localized field must be filled in each locale before that locale can be published. If the client publishes one language at a time, keep
fallback: trueand document it inPROJECT.md. - Run
pnpm generate:types. With SQLite, localized fields create_localestables; in production this needs a migration (payload-deploy-vercel).
Step 5: Frontend routing with next-intl
Install: pnpm add next-intl. Then create the files in references/next-intl-setup.md:
src/i18n/routing.ts,src/i18n/request.ts,src/i18n/messages/<locale>.jsonsrc/proxy.ts(Next.js 16 usesproxy.ts; do not createmiddleware.ts)src/app/(frontend)/[locale]/layout.tsxwithlanganddirnext.config.tswrapped withcreateNextIntlPlugin
Rules:
- Static interface text (buttons, form labels, errors) lives in
messages/*.json. Editable content lives in Payload. - Every
payload.findon the frontend passeslocale. - The proxy matcher excludes
api,admin,next(preview routes),_next,_vercel,llms,llm, and files with extensions. - Use logical CSS properties and Tailwind logical utilities (
ms-4,pe-2,text-start) so RTL works without separate styles. - Mirror directional icons (arrows, chevrons) with
rtl:rotate-180.
Diagnosis
| Symptom | Cause | Fix |
| Admin stays LTR when editing Arabic | Sync provider missing, or ar not in supportedLanguages | Step 2 and Step 3 |
| Admin language flips back and forth | Locale codes differ from language keys | Use identical codes in both lists |
Frontend shows default language on /ar/... | locale not passed to payload.find | Step 5 rule 2 |
/admin or /next/preview redirects to /en/admin | Proxy matcher does not exclude them | Step 5 rule 3 |
Production save fails after adding localized: true | Missing migration for _locales tables | Create and run a migration |
Done when
src/i18n/locales.tsis the only place locale codes are defined- Switching the admin language to Arabic switches the content locale to Arabic and the admin to RTL
- Switching the document locale switches the admin language
- Live preview shows the page in the locale being edited
/en/...and/ar/...render the right content with correctlanganddir/admin,/api,/next/preview, and/llms.txtare not redirected by the proxy
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

