You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -680,21 +681,21 @@ To make use of Payload SCSS variables / mixins to use directly in your own compo
680
681
681
682
### Getting the current language
682
683
683
-
When developing custom components you can support multiple languages to be consistent with Payload's i18n support. The best way to do this is to add your translation resources to the [i18n configuration](https://payloadcms.com/docs/configuration/i18n) and import `useTranslation` from `react-i18next` in your components.
684
+
When developing custom components you can support multiple languages to be consistent with Payload's i18n support. The best way to do this is to add your translation resources to the [i18n configuration](https://payloadcms.com/docs/configuration/i18n) and import `useTranslation` from `@payloadcms/ui/providers/Translation` in your components.
Not only does Payload support managing localized content, it also has internationalization support so that admin users can work in their preferred language. Payload's i18n support is built on top of [i18next](https://www.i18next.com). It comes included by default and can be extended in your config.
9
+
Not only does Payload support managing localized content, it also has internationalization support so that admin users can work in their preferred language. It comes included by default and can be extended in your config.
10
10
11
11
While Payload's built-in features come translated, you may want to also translate parts of your project's configuration too. This is possible in places like collections and globals labels and groups, field labels, descriptions and input placeholder text. The admin UI will display all the correct translations you provide based on the user's language.
12
12
@@ -72,9 +72,7 @@ After a user logs in, they can change their language selection in the `/account`
72
72
73
73
Payload's backend uses express middleware to set the language on incoming requests before they are handled. This allows backend validation to return error messages in the user's own language or system generated emails to be sent using the correct translation. You can make HTTP requests with the `accept-language` header and Payload will use that language.
74
74
75
-
Anywhere in your Payload app that you have access to the `req` object, you can access i18next's extensive internationalization features assigned to `req.i18n`. To access text translations you can use `req.t('namespace:key')`.
76
-
77
-
Read the i18next [API documentation](https://www.i18next.com/overview/api) to learn more.
75
+
Anywhere in your Payload app that you have access to the `req` object, you can access payload's extensive internationalization features assigned to `req.i18n`. To access text translations you can use `req.t('namespace:key')`.
78
76
79
77
### Configuration Options
80
78
@@ -88,9 +86,8 @@ import { buildConfig } from 'payload/config'
88
86
exportdefaultbuildConfig({
89
87
//...
90
88
i18n: {
91
-
fallbackLng: 'en', // default
92
-
debug: false, // default
93
-
resources: {
89
+
fallbackLanguage: 'en', // default
90
+
translations: {
94
91
en: {
95
92
custom: {
96
93
// namespace can be anything you want
@@ -107,4 +104,63 @@ export default buildConfig({
107
104
})
108
105
```
109
106
110
-
See the i18next [configuration options](https://www.i18next.com/overview/configuration-options) to learn more.
107
+
## Types for custom translations
108
+
109
+
In order to use custom translations in your project, you need to provide the types for the translations. Here is an example of how you can define the types for the custom translations in a custom react component:
const { i18n, t } =useTranslation<CustomTranslationObject, CustomTranslationKeys>() // These generics merge your custom translations with the default client translations
131
+
132
+
returnt('general:test')
133
+
}
134
+
135
+
```
136
+
137
+
Additionally, payload exposes the `t` function in various places, for example in labels. Here is how you would type those:
{ t }: { t:TFunction<CustomTranslationKeys|DefaultTranslationKeys> }, // The generic passed to TFunction does not automatically merge the custom translations with the default translations. We need to merge them ourselves here
0 commit comments