Docusaurus has a built-in internationalization (i18n) pipeline that lets plugins and themes participate in the translation workflow. When you runDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/docusaurus/llms.txt
Use this file to discover all available pages before exploring further.
docusaurus write-translations, Docusaurus calls each plugin’s getTranslationFiles method to discover what strings need translating and writes them as JSON files under the site’s i18n/ directory. On the next build, those files are read back and passed to translateContent and translateThemeConfig so each plugin can apply the localized strings to the data it loaded.
Plugin context for i18n
TheLoadContext object passed to every plugin constructor includes an i18n field that exposes the current locale and all locale configuration:
context.i18n.currentLocale inside loadContent to load locale-specific data files or to adjust API queries.
Translation file format
All translation files use the Chrome i18n JSON format, where each key maps to an object with amessage and an optional description:
i18n/<locale>/<pluginName>/ (where pluginName is the value of your plugin’s name field).
i18n-aware plugin skeleton
A plugin that participates in i18n implements up to four methods in addition to its normal lifecycle hooks. Here is the overall shape before diving into each method:translateContent is called before contentLoaded. This means the content your contentLoaded implementation receives has already been translated for the current locale.getTranslationFiles({content})
Declares all translation files the plugin wants to manage. Docusaurus calls this method during docusaurus write-translations to collect translatable strings and write them to disk, and again at build time to load the locale-specific versions.
| Parameter | Type | Description |
|---|---|---|
content | Content | The value returned by loadContent(). Available so you can include dynamic strings (e.g. document titles) alongside static ones. |
TranslationFile objects. Each object’s path is relative to i18n/<locale>/<pluginName>/ and must not include the .json extension.
docusaurus write-translations --locale fr, Docusaurus writes a file like:
i18n/fr/my-plugin/labels.json
message values. On the next build for the fr locale, those translated messages are passed into translateContent.
translateContent({content, translationFiles})
Applies localized strings from the translation files to the plugin’s loaded content. The return value replaces content before it is passed to contentLoaded.
| Parameter | Type | Description |
|---|---|---|
content | Content | The raw content returned by loadContent(). |
translationFiles | TranslationFile[] | The locale-specific translation files loaded from disk. |
Content object with translated strings substituted in.
translateThemeConfig({themeConfig, translationFiles})
Applies localized strings from the translation files to the site’s themeConfig. Returns a new themeConfig with translated values. Use this when your plugin or theme adds labels to themeConfig that users might want to translate (for example, navbar item titles or footer link text).
| Parameter | Type | Description |
|---|---|---|
themeConfig | ThemeConfig | The current site theme configuration. |
translationFiles | TranslationFile[] | The locale-specific translation files for this plugin. |
themeConfig object. Only modify keys your plugin owns; spread the original object to leave other keys untouched.
getDefaultCodeTranslationMessages()
Themes that use the <Translate> JSX component or translate() utility from @docusaurus/Translate can provide default translation messages. These are used when no locale-specific translation file exists for the current locale and serve as the fallback for the default locale.
context.i18n.currentLocale).
getDefaultCodeTranslationMessages looks like this — no description field, just ID-to-message pairs:
translations/fr.json
getDefaultCodeTranslationMessages is typically only needed by themes, not content plugins. Content plugins should use getTranslationFiles + translateContent instead.Complete i18n-aware plugin example
The following example demonstrates all four i18n lifecycle methods working together for a plugin that loads a catalog of items with translatable labels.i18n workflow summary
Extracting translations (write-translations)
Extracting translations (write-translations)
Run
docusaurus write-translations --locale <locale> to extract all strings. Docusaurus calls getTranslationFiles for each plugin and writes the result to i18n/<locale>/<pluginName>/.Translating the strings
Translating the strings
Open the generated JSON files and update each
message value to the translated string. Leave description untouched — it is only for translators’ reference and is never rendered.Building the localized site
Building the localized site
Run
docusaurus build or docusaurus start --locale fr. Docusaurus reads the translated files, passes them to translateContent and translateThemeConfig, and then calls contentLoaded with the translated content. The resulting pages are served under /fr/.