Skip to content

Comments

feat: allow configuring locale base URL#6731

Closed
xiaosongxiaosong wants to merge 8 commits intofacebook:mainfrom
xiaosongxiaosong:feat/i18n-locale-config-base-url
Closed

feat: allow configuring locale base URL#6731
xiaosongxiaosong wants to merge 8 commits intofacebook:mainfrom
xiaosongxiaosong:feat/i18n-locale-config-base-url

Conversation

@xiaosongxiaosong
Copy link

Motivation

Make the locale baseUrl support configurable.

In my case, i want the url of English docs(default locale) to be like http://localhost:3000/en-US/, the url of Chinese docs to be like http://localhost:3000/zh-CN/.

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

Default Config Test

  1. use docusaurus website i18n config to test

  2. yarn start
    The url of English docs homepage is http://localhost:3000/.
    The url of English docs homepage is http://localhost:3000/zh-CN/.

  3. yarn build
    The generated static file directories are build and build/zh-CN.

  4. yarn workspace website serve
    The url of English docs homepage is http://localhost:3000/.
    The url of English docs homepage is http://localhost:3000/zh-CN/.

Custom Config Test

  1. change docusaurus website i18n config
        localeConfigs: {
          en: {
            label: 'English',
            direction: 'ltr',
            baseUrl: '/en-US/',
          },
          'zh-cn': {
            label: '中文(中国)',
            direction: 'ltr',
            baseUrl: 'zh-CN',
          },
        },
  1. yarn start
    The url of English docs homepage is http://localhost:3000/en-US/.
    The url of English docs homepage is http://localhost:3000/zh-CN/.

  2. yarn build
    The generated static file directories are build/en-US and build/zh-CN.

  3. yarn workspace website serve
    The url of English docs homepage is http://localhost:3000/en-US/.
    The url of English docs homepage is http://localhost:3000/zh-CN/.

Related PRs

#4723 (comment)

@netlify
Copy link

netlify bot commented Feb 21, 2022

@github-actions
Copy link

github-actions bot commented Feb 21, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 56
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-6731--docusaurus-2.netlify.app/

Copy link
Collaborator

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly something we want (#6075), because currently the base URL is coupled to the locale name—no good. I've made a few comments in ossrs/srs-docs#11 which I'll restate here:

  1. Why not Nginx redirects? I've seen you've raised that possibility in your repo's issue, but have you investigated?
  2. If two locales both contain a base URL, the root of your website will become inaccessible because http://ossrs.io/ will be 404. I think that's bad UX.

@Josh-Cena
Copy link
Collaborator

There are a few things missing in this PR. Not everything is working (from a quick eyeballing, because we don't have tests for this) and it's not really in the direction I'd like. Don't worry @xiaosongxiaosong I will do the further refactoring needed.

Basically, the logic would be like:

  • The default locale has a default base URL of /, while for the others, it's /<locale>/. All of these would be customizable through the baseUrl option.
  • In build, if a locale has been specified, we will not localize paths whatsoever (localizePaths: false), and the base URL would always be /. If we are building all locales or running start, the baseUrl would need to be used for both file emit and computing base URL.

@Josh-Cena Josh-Cena changed the title feat: support config locale baseUrl feat: allow configuring locale base URL Feb 21, 2022
@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Feb 21, 2022
@Josh-Cena Josh-Cena marked this pull request as draft February 21, 2022 10:05
@slorber
Copy link
Collaborator

slorber commented Jul 28, 2025

Implemented in #11316

@slorber slorber closed this Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SEO: hreflang alternate link wrongful destination if baseURL contains defaultlocale.

4 participants