Skip to content

Conditional link rendering via process.env.DOCUSAURUS_CURRENT_LOCALE no longer works in Docusaurus v3 #11320

Closed
@adarSonmez

Description

@adarSonmez

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

In Docusaurus v2, we used process.env.DOCUSAURUS_CURRENT_LOCALE in docusaurus.config.js to switch sidebar paths, navbar links, etc., based on the current locale. After upgrading to Docusaurus v3, the same pattern no longer has any effect: the config file is evaluated only once at build time and never re-evaluates per‐locale.

Image Image

Reproducible demo

No response

Steps to reproduce

    let currentLocal = process.env.DOCUSAURUS_CURRENT_LOCALE;
    let sidebarLocal = currentLocal;

    if (currentLocal === 'en') {
      sidebarLocal = 'en';
    } else {
      sidebarLocal = 'tr';
    }

    module.exports = {
      i18n: {
        defaultLocale: 'tr',
        locales: ['tr', 'en'],
      },
      plugins: [
        [
          '@docusaurus/plugin-content-docs',
          {
            id: 'activities',
            path: 'projects/activities',
            routeBasePath: 'activities',
            sidebarPath: require.resolve(`./sidebars/${sidebarLocal}/activitiesSidebar.js`),
          },
        ],
      ],
      themeConfig: {
        navbar: {
          logo: {
            href: `/${currentLocal}`,
          },
        },
      },
    };
  1. Build the site (yarn build) and serve.
  2. Switch the locale via the dropdown to English.
  3. Notice that the sidebar and logo links remain pointing at /tr/....

Expected behavior

  • When switching to English, process.env.DOCUSAURUS_CURRENT_LOCALE should update so that:
    • sidebarPath resolves to sidebars/en/...
    • Navbar logo href becomes /en/

Actual behavior

  • The value of process.env.DOCUSAURUS_CURRENT_LOCALE is fixed at build time and does not change per‐locale.
  • All locale‐specific config remains at the default locale.

Your environment

No response

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionstatus: needs triageThis issue has not been triaged by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions