,

Complete Tutorial for Next.js 13 App Directory & i18n

Posted by






Next.js 13 App Directory & i18n – Full Tutorial

Next.js 13 App Directory & i18n – Full Tutorial

Welcome to our full tutorial on creating a Next.js 13 app directory with i18n support. This tutorial will guide you through the process of setting up a multi-language app directory in Next.js using the i18n library.

Step 1: Install Next.js

First, make sure you have Node.js and npm installed on your machine. Then, install Next.js by running the following command:

npm install next

Step 2: Create a new Next.js project

Create a new directory for your project and navigate to it in your terminal. Then, run the following command to create a new Next.js project:

npx create-next-app@13 my-app

Step 3: Install i18n support

Next, install the i18n library by running the following command in your project directory:

npm install next-translate

Step 4: Create language files

Create language files for each language you want to support in your app. For example, create a `en.json` file for English and a `fr.json` file for French. Add key-value pairs for each string you want to localize.

Step 5: Implement i18n in your Next.js app

Modify your Next.js app to support i18n by following the instructions in the Next-translate documentation. You’ll need to modify your pages, components, and API routes to support multiple languages.

Step 6: Test your multi-language app

Once you’ve implemented i18n in your Next.js app, test it by switching between languages and making sure the correct strings are displayed based on the selected language.

Conclusion

Congratulations! You’ve successfully created a multi-language app directory in Next.js with i18n support. You can now localize your app for different languages and provide a better user experience for international users.


0 0 votes
Article Rating
21 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tuomo Kankaanpää
7 months ago

To try everything Brilliant has to offer—free—for a full 30 days, visit https://brilliant.org/Tuomo . The first 200 of you will get 20% off Brilliant’s annual premium subscription.

duc nguyendinh trung
7 months ago

I need to pass the language selected to the Accept-Language of header in API.
What is the best practice to change language dependent content coming from APIs without page refresh and calling manually all the APIs?

Outrospective
7 months ago

Great tutorial, but how would you handle a scenario where you have to pass in a lot of translations to the client component? Let's say the client component is a form which has labels, error messages, placeholder texts etc. You'd get the translations inside the server component, map them manually into a object and then pass that object as translations to the client component?

veracsthedefiled
7 months ago

I don't want to use the [locale] folder, there's no information on how to do that, its incredibly frustrating!

James White
7 months ago

can we switch the locale without refreshing?

toktosunuulu meerbek
7 months ago

i did everything like u did but i have this isssue
app[locale]page.js[locale]/page.js doesn't have a root layout. To fix this error, make sure every page has a root layout.

can u help ne solve this please

I will do What I wanna do
7 months ago

I implemented next-intl and it has many issues.. it feel not stable.. sometimes it routes to completely different locale and it causes caching not working..

D4rzk
7 months ago

Great video, I just want to ask, if I use useTranslations in page.tsx, doesn't everything become a client component? Or is it something different than a classic hook? It confuses me how they have "use" in there, so I want to ask. 🙂

Derek Gygax
7 months ago

This video is great! I had just about given up on using next-intl but this video made it so clear, thank you!

balagopal s nair
7 months ago

hey, how do we chain this middleware with the normal middleware that has conditional statements for rewriting a path?

Sayyed Aaman
7 months ago

Thank you this video. That's great

Gantushig Saruul
7 months ago

Thank you for your great video. Even though everything in the video works. I am currently facing this reloading problem. When I try to change the language of the web, it fully reloads. I want to change the language without reloading the page. Is there any way to do that?

ArmaganVideos
7 months ago

Ughhh this got soooo complicated and bad with the app directory. It was insanely straightforward with pages directory and next-i18next..

Thanks for the explanations tho 🙂

noureddine ettouzany
7 months ago

when creating a i18n.js file I get this error
Module '"next-intl/server"' has no exported member 'getRequestConfig'.
in the next-intl/server there is no getRequestConfig method

Change color life
7 months ago

i have error when i use layout and import'./global.css' module not fount in [locale]

Anhelina Zhurauskaya
7 months ago

Does anyone has the same error? 'Error: Unable to find `next-intl` locale, have you configured the middleware?'

G. Flores
7 months ago

Im using redux and get a 404 after passing the layout, css and page to the [locale] folder, any thouhgts on that? thanks!

Nofy89
7 months ago

Thank you!

Gonzalo Lobo
7 months ago

Useful….

Where is the src folder? Should be there, and you dont have it. All the time this error:

Error: Unable to find `next-intl` locale, have you configured the middleware?`

Next-translate is much better than next-intl.

See ya!

Thomas Luizon
7 months ago

What theme are you using?