Translating a Next Js Website (App Router i18n)

preview_player
Показать описание
I migrated my website to the `app` directory router. However, it’s a multilingual website with content both in French and English, and the translation library I was using, i18next, doesn’t work server-side. So this is the story of how I rolled my own translation system and what I had to set up to make it work.

And even if you don’t need to translate your NextJS website, you might need to use a middleware or a lookup for something else. If you don’t, this video on the new SEO features in Next JS might be interesting to you.

For those of you who are still here, there are three parts to this :
- first how I structured my app directory to handle locales
- second, how I coded the lookup function to translate strings within pages
- third, how I set up the middleware to switch users from one version to the other depending on their browser language.

Let’s dive right in.

----
Рекомендации по теме
Комментарии
Автор

Thanks again for providing this solution. We needed to add internationlization to our project and having this as a ready tool for being able to improve our ability to get our content up faster.

steckdev
Автор

Amazed by the line by line explanation👌

niki
Автор

But what if I want to fetch data from a firebase or any other database. I can't have the data locally.

parshuram
Автор

I have been looking for this and your SEO using the app router video for days! thank you!! im starting to build a project and these come in handy 💪

vibray
Автор

i really wish you explain it more in depth with code source repo and show us how you apply on dummy data that u import from data file to a component

mohamed-zhioua
Автор

Can you please make a video on how toh use next-auth and i18n in a single project.

deepaknegi
Автор

Hi, are you able to share the source code for it? Would appreciate it!
Thanks for the great video, definitely understood it more now

xdLol-ft
Автор

I saw that you are passing lang to props (I am guessing for client components) Is it a good practice do prop drilling?

Saleh_Balakisiyev
Автор

So how about urls ? I understand how to change language param from but it you want have url friendly? I think i can create one [aboutUrl] for can create 2 pages with 2 URLs but how can use the midelware to change language ?

icedev
Автор

how translate if translation words on backend side ?

Rasty_Boss
Автор

How do you handle a link with the current language?

iosonotan
Автор

Hi, could you do an explaination of how you implemented the update lang button in your navbar ?

I tried setting a cookie to store the lang value and access it, but did not manage to update my <html lang> prop with it.

jeandesauw
Автор

This is so helpful. Thanks! 🙂
Do you know how to get the translations (json files) from an http endpoint, instead of having them locally stored?

carlosromera
Автор

Where is your link to your code in the description?

egillanton
Автор

Great solution for the translations, very cool how you did... Is that a reason why someone would implement that instead of using a already tested and in the vercel community a 3rd party library? Something like `next-intl`?

Great video!

cartfion
Автор

Can you show the sitemap bruh ? how can you setup sitemap with localization? wait feedback thank you

JavohirXasanov-ktoi
Автор

where to have the source code ? or its in your premium video course?

crosshorizon
Автор

Why are you using a json instead of a javascript object?

juanferrer
Автор

hi, tks a lot you are too good :) where we could fing the source code please ? tks

prolland
Автор

dude why you do this?, no source code, no complete screen to see whats happening in every component that you explain touch... are you triying to tech something or to proove that you know a lot ? its a little bit useless this video for someone that is learning how to use this library

gabrielmaglia