The Admin Panel is translated in over 30 languages and counting. With I18n, editors can navigate the interface and read API error messages in their preferred language. This is similar to Localization, but instead of managing translations for the data itself, you are managing translations for your application's interface.
By default, Payload comes with preinstalled with English, but you can easily load other languages into your own application. Languages are automatically detected based on the request. If no language was detected, or if the user's language is not yet supported by your application, English will be chosen.
To configure I18n, use the i18n
key in your Payload Config:
You can easily customize and override any of the i18n settings that Payload provides by default. Payload will use your custom options and merge them in with its own.
The following options are available:
Option | Description |
---|---|
fallbackLanguage | The language to fall back to if the user's preferred language is not supported. Default is 'en' . |
debug | Whether to log debug information to the console. Default is false . |
translations | An object containing the translations. The keys are the language codes and the values are the translations. |
supportedLanguages | An object containing the supported languages. The keys are the language codes and the values are the translations. |
You can easily add new languages to your Payload app by providing the translations for the new language. Payload maintains a number of built-in translations that can be imported from @payloadcms/translations
, but you can also provide your own Custom Translations to support any language.
To add a new language, use the i18n.supportedLanguages
key in your Payload Config:
You can customize Payload's built-in translations either by extending existing languages or by adding new languages entirely. This can be done by injecting new translation strings into existing languages, or by providing an entirely new language keys altogether.
To add Custom Translations, use the i18n.translations
key in your Payload Config:
While Payload's built-in features come fully translated, you may also want to translate parts of your own project. This is possible in places like Collections and Globals, such as on their labels and groups, field labels, descriptions or input placeholder text.
To do this, provide the translations wherever applicable, keyed to the language code:
Payload's backend sets 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.
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')
.
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 Component:
Additionally, Payload exposes the t
function in various places, for example in labels. Here is how you would type those: