Commit d7f1ea2
authored
fix: inject custom translations into supportedLanguages in sanitization (#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.1 parent 844f99f commit d7f1ea2
1 file changed
+30
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
179 | 208 | | |
180 | 209 | | |
181 | 210 | | |
| |||
0 commit comments