DEV Community

Cover image for Building Next.js app in 7 different languages 🇫🇷 🇩🇪🇧🇷 with i18n. Open Source.
Iuliia Shnai
Iuliia Shnai

Posted on Edited on

Building Next.js app in 7 different languages 🇫🇷 🇩🇪🇧🇷 with i18n. Open Source.

Languages

Localisation is one of the ways how to make your project open and accessible for more users.

So I decided to add different languages to my app.

Project I am working on

Post Generator - Linkedin Post Generator I wrote full story how I started it (Open Source)

You can fork it here https://github.com/shnai0/linkedin-post-generator

Translations

Resources I used to build it?

Using ChatGPT
Using next-i18next
https://github.com/i18next/next-i18next

What you will find in this article?

  1. How install and select localisation library?

  2. How I create each common.js file

  3. Adding dropdown for languages

Step 1. Select library and install

There were two which ChatGpt recommend me. I selected i18next. No big clue why, but it works well with my pages directory.

I installed it here:

npm install i18next
npm install react-i18next

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

Step 2.Create next-18next.config.js and next.config.js

next-18next.config.js

module.exports = {
  debug: process.env.NODE_ENV === "development",
  i18n: {
    locales: ["en", "de", "pt", "es", "ch", "fr", "it"],
    defaultLocale: "en",
  },
  localePath:
    typeof window === "undefined"
      ? require("path").resolve("./public/locales")
      : "/locales",

  reloadOnPrerender: process.env.NODE_ENV === "development",
};

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

next.config.js

/** @type {import('next').NextConfig} */

const { i18n } = require("./next-i18next.config.js");
const nextConfig = {
  i18n,
  reactStrictMode: true,
};

module.exports = nextConfig;

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

Step 3. Create locales structure

locales

Step 4. Add variables in each common.js file

After that I had all variables I asked chat

{
  "title": "Linkedin Post Generator 🚀",
  "posts_generated": "50.000 amazing posts generated 💫",
  "subtitle": "Generate high quality posts with AI like top LinkedIn creators. Time to go viral.",
  "inside_post": "Type or copy your post here",
  "submit_button": "Generate your post",
  "generated_post": "Your generated post",
  "post copied": "Post copied to clipboard",

  "prompts.story": "prompt",
  "prompts.crisp": "prompt",
  "prompts.list": "prompt",
  "prompts.unpopular_opinion": "prompt",

  "meta.viewport": "width=device-width, initial-scale=1",
  "meta.favicon": "👩‍💼",
  "meta.description": "Meta.",
  "meta.og.title": "LinkedIn Viral Post Generator with AI",
  "meta.og.type": "website",
  "meta.og.image": "https://postgenerator.app/cover.png",

  "vibes.story": "Story",
  "vibes.crisp": "Crisp",
  "vibes.list": "List",
  "vibes.unpopular_opinion": "Unpopular opinion",
  "vibes.case_study": "Case Study"
🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

Step 4. Replace hard coded code in index

In your JavaScript/TypeScript code, you would then import the relevant locale file based on the user's chosen language.

First imports use translations.

import { useTranslation, Trans } from "next-i18next";
🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

💡 Prompts, if your application using OpenAI can be also variables.

You would replace all the hard-coded text in your application with the respective keys from the locale files.

<button className="bg-blue-700 font-medium rounded-md w-full text-white px-4 py-2 hover:bg-blue-600 disabled:bg-blue-800">
  {loading && <LoadingDots color="white" style="large" />}
  {!loading && `Generate new post `}
</button>
🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

Instead I use this- as I am adding variable

<button className="bg-blue-700 font-medium rounded-md w-full text-white px-4 py-2 hover:bg-blue-600 disabled:bg-blue-800">
  {loading && <LoadingDots color="white" style="large" />}
  {!loading && locale.submit_button }
</button>
🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

Step 5. Create menu in NavBar to connect different languages

const languages = [
    { name: "English", flag: "🇬🇧", code: "en" },
    { name: "Deutsch", flag: "🇩🇪", code: "de" },
    { name: "Português", flag: "🇧🇷", code: "pt" },
    { name: "Français", flag: "🇫🇷", code: "fr" },
    { name: "Español", flag: "🇪🇸", code: "es" },
    { name: "中文", flag: "🇨🇳", code: "ch" },
    { name: "Italiano", flag: "🇮🇹", code: "it" },
    // add more languages as needed
  ];

  const currentLanguage =
    languages.find((language) => i18n.language === language.code) ||
    languages[0];

  console.log("currentlanguages", currentLanguage);

  const [isOpen, setIsOpen] = React.useState(false);
  const toggle = () => setIsOpen(!isOpen);

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026

NavBAr

What am I doing now?

I am building different micro-tools for LinkedIn and actively develop Post generator https://www.postgenerator.app

If you like this article and would like to support me on my coding journey, here one of the open source project I am on.

Papermark.io - open source alternative to Docsend. Check it ⭐️

Stars

If you are building something in Open Source, share, I am curious to fork it 👀

Follow my journey, more micro-projects here https://linktr.ee/shnai

My Twitter https://twitter.com/shnai0

Top comments (23)

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
mateusabelli profile image
Mateus Abelli •

I like i18n although I don't implement it too often in projects I enjoyed reading your process to add such feature.

I have a question, with this setup, is it possible to have next.js figure out the user's preferred language and automatically render the matching language?

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
shnai0 profile image
Iuliia Shnai •

Thanks Mateus!

It is actually a good questions. I actually have no idea. I did not build it or did not try. But understand what you mean.

I build just standard always users get on the English page.

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
mateusabelli profile image
Mateus Abelli •

Oh that's cool, thanks for replying!

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
mfts profile image
Marc Seitz •

💪 Great job!

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
aydrian profile image
Aydrian •

This is great. Where did you source all your translations? I'm also starting to build a lot using i18next.
I also created a i18next Backend Plugin for those who want to store their translations in a database using Prisma ORM.

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
shnai0 profile image
Iuliia Shnai •

Sourcing is all from ChatGPT:)

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
juanfrank77 profile image
Juan F Gonzalez •

Great stuff here! Love to see you building cool stuff with Next.js.

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
shnai0 profile image
Iuliia Shnai •

Thanks Juan. Are you building smth at the moment?

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
juanfrank77 profile image
Juan F Gonzalez •

Not anything code related atm. 😅
But building content for folks in SaaS.

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 Thread
 
shnai0 profile image
Iuliia Shnai •

That is great! Which type of content? For website or social?

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026 Thread
 
juanfrank77 profile image
Juan F Gonzalez •

Mostly for websites. Blog content that can then be used for social media and to get more organic traffic. 😀

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
softwaresennin profile image
Lionel♾️☁️ •

Awesome job @shnai0 awesome job indeed!!

with this ... i am seeing that i really need to learn NextJS once i am done with python and done with JS. Wooow ... still got a roads to go.

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
shnai0 profile image
Iuliia Shnai •

Thanks Lionel!

It seems that it pretty simple language and very clear one.

I don’t know python:) maybe I should also look into it:)

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
ldnovaes profile image
Leandro Duarte •

AWESOME!

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
shnai0 profile image
Iuliia Shnai •

Thanks Leandro 😊

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
ahmadessam profile image
Ahmad Essam •

Nice work

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
shnai0 profile image
Iuliia Shnai •

Thank you Ahmad!

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
gutem profile image
Gutem •

ch == Switzerland (derived from Confoederatio Helvetica)
cn == China

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
shnai0 profile image
Iuliia Shnai •

Omg

Thank you for noticing that Gutem. I was kind of confident it is like that. Need to push update for it.

🔥 Jadwal & Hasil: shnai/building nextjs app in different languages with in open source e - Info Live Streaming 2026
 
tommyleong profile image
TommyLeong •

Hello Iuliia. By any chance did you explore how i18n could pull latest translation content from an API? Not just on first launch, but on subsequent navigation or page refresh to always refer to latest translated content from backend.