i18next / next-app-dir-i18next-example-ts

Next.js 13/14 app directory feature in combination with i18next
https://locize.com/blog/next-app-dir-i18n/
117 stars 29 forks source link

is possible to remove the default locale in route ? #10

Closed eggcaker closed 4 months ago

eggcaker commented 4 months ago

🚀 Feature Proposal

when acess http://website/route-one will render http://website/en/route-one (en as default locale)

Motivation

Please outline the motivation for the proposal.

Example

Please provide an example for how this feature would be used.

adrai commented 4 months ago

Not tested yet, but you would need to have those pages doubled... also present in the app directory... and then you would also need to adapt the middleware.ts file to not redirect if the detected language is the default one...

eggcaker commented 4 months ago

it'works , but is only way can do that ? mean i need copy all layouts and pages

adrai commented 4 months ago

You may also try something like this instead:

  if (
    !languages.some(loc => req.nextUrl.pathname.startsWith(`/${loc}`)) &&
    !req.nextUrl.pathname.startsWith('/_next')
  ) {
+   if (lng === fallbackLng) {
+     return NextResponse.rewrite(new URL(`/${lng}${req.nextUrl.pathname}`, req.url))
+   }
    return NextResponse.redirect(new URL(`/${lng}${req.nextUrl.pathname}`, req.url))
  }
eggcaker commented 4 months ago

yes, it's works too, just one issue , when access webiste.com/ has a loop redirect to /en/en/en/en/en/en/en.... haha but, thanks for help, i'll try fix that loop redirect go with second way.