Skip to content

How to Fix Docusaurus i18n Locale Issues

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Docusaurus i18n Locale Issues. We cover key concepts, practical examples, and best practices.

Your Docusaurus internationalized site shows only the default language β€” translations are not applied, the locale switcher is missing, or localized pages return 404.

The Wrong Way

// Creating translation files manually without the Docusaurus i18n CLI
mkdir -p i18n/fr/docusaurus-plugin-content-docs/current

Manual file creation misses required JSON structure. Always use the extraction CLI.

The Right Way

Step 1: Configure i18n in docusaurus.config.js

module.exports = {
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'fr', 'de', 'zh'],
    localeConfigs: {
      en: { label: 'English' },
      fr: { label: 'FranΓ§ais' },
      de: { label: 'Deutsch' },
      zh: { label: 'δΈ­ζ–‡' },
    },
  },
};

Step 2: Extract translation files

npm run write-translations -- --locale fr

This creates i18n/fr/ with JSON translation files for navbar, footer, and sidebar labels.

Step 3: Translate content separately

# Translate docs:
# Copy docs/ to i18n/fr/docusaurus-plugin-content-docs/current/
# Translate the markdown files

# Translate theme strings:
# Edit i18n/fr/code.json β€” contains navbar, footer, and UI text

Step 4: Build for all locales

npm run build -- --locale fr
# Or build all locales:
npm run build

The build generates build/fr/, build/de/, etc.

French locale builds β€” 12 translated pages, locale switcher in navbar, /fr/ prefix URLs work.

Prevention

  • Always run write-translations after changing navbar, footer, or sidebar labels.
  • Keep translations in Git β€” use the same repository for source and translations.
  • The locale management pattern is used by Doda Browser's multilingual interface β€” extraction keys are tracked centrally, translations are separate files.

Common Mistakes with i18n locale

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world DOCUSAURUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my Docusaurus locale switcher not appear?

The locale switcher only shows when two or more locales are configured AND at least one translated page exists. If you have locales: ['en', 'fr'] but no French content, the switcher is hidden.

How do I set the default locale in Docusaurus?

Set defaultLocale: 'en' in the i18n section of docusaurus.config.js. The default locale does not get a path prefix (/en/docs/ β†’ /docs/).

Can I have locale-specific sidebars?

Yes. Sidebar labels can be translated in the i18n/*/docusaurus-theme-classic/*.json files. The sidebar structure itself (page order) is the same across locales β€” only the labels are translated.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro