withastro / starlight

🌟 Build beautiful, accessible, high-performance documentation websites with Astro
https://starlight.astro.build
MIT License
4.83k stars 522 forks source link

Multiple languages generate wrong language directory #784

Closed LuHugo closed 1 year ago

LuHugo commented 1 year ago

What version of starlight are you using?

0.10.2

What version of astro are you using?

3.0.6

What package manager are you using?

yarn

What operating system are you using?

Mac

What browser are you using?

Edge

Describe the Bug

When multiple languages are configured, the built directory ignores uppercase letters and changes them all to lowercase letters, which results in routing to the 404 page.

...
locales: {
  root: {
      label: 'English',
      lang: 'en-US'
  },
  'zh-CN': {
      label: '简体中文',
      lang: 'zh-CN'
  }
},
defaultLocale: 'root'
...

build logs

  generating static routes 
The collection **i18n** does not exist or is empty. Ensure a collection directory with this name exists.
▶ node_modules/@astrojs/starlight/404.astro
  └─ /404.html (+241ms)
▶ node_modules/@astrojs/starlight/index.astro
  ├─ /guides/example/index.html (+62ms)
  ├─ index.html (+140ms)
  ├─ /reference/example/index.html (+16ms)
  ├─ /zh-cn/guides/example/index.html (+39ms)
  ├─ /zh-cn/index.html (+52ms)
  ├─ /zh-cn/reference/example/index.html (+35ms)
  ├─ /zh-CN/guides/example/index.html (+17ms)
  ├─ /zh-CN/index.html (+10ms)
  ├─ /zh-CN/reference/example/index.html (+14ms)
  ├─ /zh-CN/zh-cn/guides/example/index.html (+17ms)
  ├─ /zh-CN/zh-cn/index.html (+8ms)
  └─ /zh-CN/zh-cn/reference/example/index.html (+9ms)

 generating optimized images 
  ▶ /_astro/houston.1bcfcd2a_2v3t3T.webp (before: 96kB, after: 27kB) (+1.23s) (1/1)
Completed in 1.94s.
image

In the built folder dist, the zh-cn directory will be generated, and the correct one should be the zh-CN directory.

Link to Minimal Reproducible Example

No response

Participation

jsparkdev commented 1 year ago
'zh-CN': {
  label: '简体中文',
  lang: 'zh-CN'
}

Change the above code to the code below.

'zh': {
  label: '简体中文',
  lang: 'zh-CN'
}

And change the folder name to zh.

For more information, see https://starlight.astro.build/guides/i18n/#configure-i18n.

LuHugo commented 1 year ago
'zh-CN': {
  label: '简体中文',
  lang: 'zh-CN'
}

Change the above code to the code below.

'zh': {
  label: '简体中文',
  lang: 'zh-CN'
}

And change the folder name to zh.

For more information, see https://starlight.astro.build/guides/i18n/#configure-i18n.

@jsparkdev I know this is completely feasible, but how to define en-US, en-CA, en-UK at the same time and what the routing should be. Is it possible to do routing like: http://localhost:4321/en-US/docs/ and http://localhost:4321/en-UK/docs/. If you use keys like enus or enuk, the meaning is not very clear.

Some examples I have seen :

Ideally, this feature should support keys such as en-US, en-UK, etc. I don't know if this is intentionally designed like this or if it is a bug. It would be really great if such a configuration could be achieved.

HiDeoo commented 1 year ago

If I am not missing anything, this is the expected behavior.

Each route segments in a content collection are slugified using github-slugger. This change was introduced in https://github.com/withastro/astro/pull/5666 and the maintainCase option, which defaults to false, is not used meaning that every character is lowercased.

To handle en-US, en-CA, en-UK you can use the same pattern used in the Starlight documentation for pt-BR:

The generated URLs will be https://starlight.astro.build/pt-br/guides/i18n/ for example with pt-br avoiding the enus or enuk like you mentioned.

LuHugo commented 1 year ago

If I am not missing anything, this is the expected behavior.

Each route segments in a content collection are slugified using github-slugger. This change was introduced in withastro/astro#5666 and the maintainCase option, which defaults to false, is not used meaning that every character is lowercased.

To handle en-US, en-CA, en-UK you can use the same pattern used in the Starlight documentation for pt-BR:

The generated URLs will be https://starlight.astro.build/pt-br/guides/i18n/ for example with pt-br avoiding the enus or enuk like you mentioned.

@HiDeoo Thank you, this is very good. I noticed the maintainCase parameter you mentioned. Can it be reconfigured to true by the user? If it can be set to true, can the folder (with a name similar to en-US, etc.) be generated correctly?

HiDeoo commented 1 year ago

Can it be reconfigured to true by the user?

At the moment, this parameter is not something used or exposed in Astro and this is where this change would need to happen I guess. Altho, I guess a good first step would be to open an issue in the Astro repo to discuss this, not sure if this is something that would be accepted or not, maybe there is a good reason why this is done this way and not configurable I don't know. etc.

LuHugo commented 1 year ago

Got it, I think it would be a good idea to allow users to keep the original folder naming.