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 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:

1
import { buildConfig } from 'payload'
2
3
export default buildConfig({
4
// ...
5
i18n: {
6
// ...
7
},
8
})

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.

1
import { buildConfig } from 'payload'
2
3
export default buildConfig({
4
// ...
5
i18n: {
6
fallbackLanguage: 'en', // default
7
debug: false, // default
8
}
9
})

The following options are available:

OptionDescription
fallbackLanguageThe language to fall back to if the user's preferred language is not supported. Default is 'en'.
debugWhether to log debug information to the console. Default is false.
translationsAn object containing the translations. The keys are the language codes and the values are the translations.
supportedLanguagesAn 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:

1
import { buildConfig } from 'payload'
2
import { en } from '@payloadcms/translations/languages/en'
3
import { de } from '@payloadcms/translations/languages/de'
4
5
export default buildConfig({
6
// ...
7
i18n: {
8
supportedLanguages: { en, de },
9
},
10
})

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:

1
import { buildConfig } from 'payload'
2
3
export default buildConfig({
4
//...
5
i18n: {
6
translations: {
7
en: {
8
custom: {
9
// namespace can be anything you want
10
key1: 'Translation with {{variable}}', // translation
11
},
12
// override existing translation keys
13
general: {
14
dashboard: 'Home',
15
},
16
},
17
},
18
},
19
//...
20
})

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:

1
import { CollectionConfig } from 'payload'
2
3
export const Articles: CollectionConfig = {
4
slug: 'articles',
5
labels: {
6
singular: {
7
en: 'Article',
8
es: 'Artículo',
9
},
10
plural: {
11
en: 'Articles',
12
es: 'Artículos',
13
},
14
},
15
admin: {
16
group: {
17
en: 'Content',
18
es: 'Contenido',
19
},
20
},
21
fields: [
22
{
23
name: 'title',
24
type: 'text',
25
label: {
26
en: 'Title',
27
es: 'Título',
28
},
29
admin: {
30
placeholder: {
31
en: 'Enter title',
32
es: 'Introduce el título'
33
},
34
},
35
},
36
],
37
}

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 is an example of how you can define the types for the custom translations in a Custom Component:

1
'use client'
2
import type { NestedKeysStripped } from '@payloadcms/translations'
3
import type React from 'react'
4
5
import { useTranslation } from '@payloadcms/ui/providers/Translation'
6
7
const customTranslations = {
8
en: {
9
general: {
10
test: 'Custom Translation',
11
},
12
},
13
}
14
15
type CustomTranslationObject = typeof customTranslations.en
16
type CustomTranslationKeys = NestedKeysStripped<CustomTranslationObject>
17
18
export const MyComponent: React.FC = () => {
19
const { i18n, t } = useTranslation<CustomTranslationObject, CustomTranslationKeys>() // These generics merge your custom translations with the default client translations
20
21
return t('general:test')
22
}

Additionally, Payload exposes the t function in various places, for example in labels. Here is how you would type those:

1
import type {
2
DefaultTranslationKeys,
3
NestedKeysStripped,
4
TFunction,
5
} from '@payloadcms/translations'
6
import type { Field } from 'payload'
7
8
const customTranslations = {
9
en: {
10
general: {
11
test: 'Custom Translation',
12
},
13
},
14
}
15
16
type CustomTranslationObject = typeof customTranslations.en
17
type CustomTranslationKeys = NestedKeysStripped<CustomTranslationObject>
18
19
const field: Field = {
20
name: 'myField',
21
type: 'text',
22
label: (
23
{ 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
24
) => t('fields:addLabel'),
25
}
Next

Localization