Next.js Discord

Discord Forum

i18n routing with Next 15 App router with default locale

Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
Open in Discord
African Slender-snouted CrocodileOP
I recently started working with next 15 using app router for my e-commerce project. I'm confused with implementing the i18n. I'm having two types of url
1. domain.com/collection/accesories
2. domain.com/en-US/collection/accesories

I need help on this

14 Replies

@African Slender-snouted Crocodile I recently started working with next 15 using app router for my e-commerce project. I'm confused with implementing the i18n. I'm having two types of url 1. domain.com/collection/accesories 2. domain.com/en-US/collection/accesories I need help on this
when you integrated i18n with this guide ([link](https://nextjs.org/docs/app/building-your-application/routing/internationalization)) you will always have your language code inside the pathname. So yes, technically you have two urls, but the one without a language code will be redirected to the one with language code.

domain.com/collection/accesories -- Redirect (thought middleware) --> domain.com/en/collection/accesories
@African Slender-snouted Crocodile Yeah this is exactly what's happening but i want to exclude the locale segment for my default locale 'en'
you can do that while checking in your middleware if the "new redirection" is with the language code "en". If so, don't redirect. Then inside all of your pages you need to check if there is a language code and if not use "en" (as default) and if there is one use that one.

You can see, that this can get quite complex very fast so I recommend you to keep the language code inside your path even if it's the default
@JChicano but if you have the proyect inside the folder [lang], you have to put the route like /en/ bcs if you put / is empty no?
yep, that's another problem, that OP want to solve. As said:
You can see, that this can get quite complex very fast so I recommend you to keep the language code inside your path even if it's the default
@B33fb0n3 yep, that's another problem, that OP want to solve. As said: > You can see, that this can get quite complex very fast so I recommend you to keep the language code inside your path even if it's the default
anyways Im having a hidratation problem with that, i have the layout generated with staticparams and the other pages with promises and awaits, is this correct, or i miss something bcs idk how to fix this hidratation problem bcs outside of that the web is working well
Note that i didnt install any library, just follow the documentation on next, editing just the middleware, and this files that i mencioned
ok, i do it
just wondering what could get complex. Can you spot some light on the complexity you mentioned. TIA
@African Slender-snouted Crocodile I kept the language segment but as i'm migrating my old shopify store to headless, it's kind of SEO concern that i need to keep the url same. That's why i want to exclude the default locale and include the rest
You don't need to worry about it, as the user (without the language code) can stay the same. It will be still reachable and there will be still content (as you middleware just redirect to the correct path)
@African Slender-snouted Crocodile solved?