- Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(plugin-redirects): support translations #14548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| | ||
| ## Custom Translations | ||
| | ||
| The plugin automatically includes translations for English, French, and Spanish. If you want to customize existing translations or add new languages, you can override them in your config: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that other plugins, like eCommerce, only support English. I plan to add all the plugins to our translation script later on to include all the admin panel languages.
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
…on (#14549) ## Description Automatically injects custom translations from `i18n.translations` into `supportedLanguages` during config sanitization. This allows translation functions like `({ t }) => t('namespace:key')` to work with user-defined custom translations, not just the default translations from `@payloadcms/translations`. ## Problem Currently, when users define custom translations in their config: ```typescript i18n: { translations: { de: { 'my-namespace': { customKey: 'Wert' } } } } ``` These translations are **not** accessible to the `t` function used in field labels and options. The `t` function only searches in `config.i18n.supportedLanguages[lang].translations`, causing custom translations to be ignored. This issue was discovered while implementing translation support for plugins in PR #14548, where radio button options using `label: ({ t }) => t('plugin-redirects:key')` failed to translate for custom languages. ## Solution During config sanitization (in `packages/payload/src/config/sanitize.ts`), the code now: 1. Iterates through all languages in `i18n.translations` 2. For existing languages in `supportedLanguages`: merges custom translations with existing ones 3. For new languages: creates them using English as a template, then merges custom translations This ensures that **all custom translations** defined by users or plugins are automatically available to the `t` function throughout the application.
DanRibbens left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#14549 is merged. I think you'll need to merge main to get this to pass, correct?
| Hey @DanRibbens! This PR finally reverts #14549. The real issue was fixed by #14569. The reason I thought #14549 fixed it is because I tested it locally with this PR and it worked with the first language. But it failed when changing the language in CI. It turned out to be a caching issue. When switching languages, the checkbox label remained in the original language. |
| 🚀 This is included in version v3.64.0 |
Allows you to add translations to the plugin fields, replacing the need for verbose field
overridesconfiguration.Usage