Use when new translation keys are added to packages to generate new translations strings
Payload has two separate translation systems:
When to use: Adding translations to core Payload packages (packages/ui, packages/payload, packages/next)
Add the English translation to packages/translations/src/languages/en.ts
authentication, general, fields, etc.)export const enTranslations = {
authentication: {
// ... existing keys
newFeature: 'New Feature Text',
},
}
Add client key (if needed for client-side usage) to packages/translations/src/clientKeys.ts
'authentication:newFeature'Generate translations for all languages
cd tools/scriptspnpm generateTranslations:coreWhen to use: Adding translations to any plugin package (packages/plugin-*)
Verify plugin has translations folder
packages/plugin-{name}/src/translations existsAdd the English translation to the plugin's packages/plugin-{name}/src/translations/languages/en.ts
export const enTranslations = {
'plugin-multi-tenant': {
'new-feature-label': 'New Feature',
},
}
Generate translations for all languages
cd tools/scriptspnpm generateTranslations:plugin-{name}pnpm generateTranslations:plugin-multi-tenantpnpm generateTranslations:plugin-ecommercepnpm generateTranslations:plugin-import-exportIf a plugin doesn't have a translations folder yet, ask the user if they want to scaffold one.
packages/plugin-{name}/src/translations/
├── index.ts
├── types.ts
└── languages/
├── en.ts
├── es.ts
└── ... (all other language files)
Create tools/scripts/src/generateTranslations/plugin-{name}.ts
plugin-multi-tenant.ts as a templateAdd script to tools/scripts/package.json:
"generateTranslations:plugin-{name}": "node --no-deprecation --import @swc-node/register/esm-register src/generateTranslations/plugin-{name}.ts"
OPENAI_KEY environment variable to be set