I18n
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 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 is 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:
Config Options
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' . |
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. |
Adding Languages
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:
Custom Translations
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:
Project Translations
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:
Node
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')
.
TypeScript
In order to use custom translations in your project, you need to provide the types for the translations.
Here we create a shareable translations object. We will import this in both our custom components and in our Payload config.
Import the shared translations object into our Payload config so they are available for use:
Import the shared translation types to use in your Custom Component:
Additionally, Payload exposes the t
function in various places, for example in labels. Here is how you would type those: