Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nextra 4] i18n + static website #3934

Open
jonabricot opened this issue Jan 14, 2025 · 0 comments
Open

[Nextra 4] i18n + static website #3934

jonabricot opened this issue Jan 14, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@jonabricot
Copy link

Context
I'm currently trying to create a multilingual static documentation website. I'm using Nextra 4 and followed the doc using the docs theme and this example to get everything working properly. The only issue I encounter is that all navigation links do not have the language prefix in it.
I cannot use the middleware system since i'm in a static context, do you have any alternative for a static i18n website ?

You can probably reproduce my current situation using the next option output: 'export' on the swr-site example. It's not a static example, but it was my starting point.

Alternatives considered
As of today, i tried to adjust the getPageMap result to force a prefix for every route
Here is an example of the code:

function localizePagemap(config, lang) {
  return config.map(page => {
    const localizedPage = {...page}
    if (page.route) {
      localizedPage.route = `/${lang}${page.route}`
    }
    if (page.children) {
      localizedPage.children = localizePagemap(localizedPage.children, lang)
    }

    return localizedPage
  })
}

...

export default async function RootLayout({ children, params }) {
  const { lang } = await params

  const nativePageMap = await getPageMap(`/${lang}`)
  const localizedPageMap = localizePagemap(nativePageMap, lang)

  ...
}

Unfortunately, this breaks sidebars since they seems to be generated using route parts.

I'm currently considering replacing both sidebar and navbar components with custom ones (ie copy and paste the docs theme components) to alter the route path at the latest possible step.

The solution i'd like
My ideal solution should be an option in components or the nextra plugin to generate links with the current language part directly in it.

I founded multiple warnings in using i18n routing and static generation, both in nextra and next documentation, and I was wondering if I missed something reading the doc or if there is a better approach to implement my use case.

Anyway, thank you for this great project 👌

@jonabricot jonabricot added the enhancement New feature or request label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant