Nextjs Localization Guide for Building Multilingual Sites

Category
Next.js
Reading Time
0
 min
Date
July 27, 2025

Localization and internationalization, two words that sound like corporate jargon, yet they're really all about connection. Localization is the process of adapting your app for specific languages and cultures, while internationalization sets the foundation to make that possible.

Think of it like building a house: internationalization is the solid framework, and localization is the paint, decor, and personal touches that make it feel like home to users around the world.

Now, why does this matter so much? Because we live in a global marketplace. If your app only speaks one language, you're leaving potential users, and let's be honest, profits, on the table.

Multilingual sites expand your market reach, create a better user experience, and foster inclusivity. People feel valued when they can interact with technology in their native tongue. That kind of consideration is both polite and powerful.

And the benefits don't stop there. Multilingual apps are SEO gold. Search engines love content that caters to diverse regions, helping your site rank higher and get noticed.

Plus, with Next.js, adding localization often feels much more manageable. It's fast, efficient, and packed with tools to make every user feel at home, no matter where they're browsing from.

Setting Up Your Nextjs Localization Project

Before starting with localization, you'll need a few essentials: Node.js 18+ installed, npm or yarn for handling dependencies, and a basic grasp of JavaScript or TypeScript.

Got all that? Great, let's set up your Next.js project.

Start by initializing a fresh Next.js app with some powerful defaults like TypeScript, Tailwind CSS, and the App Router. Just run this command:

npx create-next-app@latest my-next-app --typescript --tailwind --app

Once that's done, navigate to your project directory:

cd my-next-app

Next, install the required dependencies to fully integrate Tailwind CSS:

npm install tailwindcss postcss autoprefixer

You'll also need a postcss.config.mjs file in your root directory, where you'll define Tailwind's PostCSS plugin:

export default {
  plugins: {
    'tailwindcss': {},
  },
};

Add Tailwind directives to your global stylesheet—typically app/globals.css—to bring its utility classes into your project:

@tailwind base;
@tailwind components;
@tailwind utilities;

Then, connect this stylesheet in your root layout file:

import './globals.css';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}

At this point, you have the basics in place.

If you're planning for scalability, a goal for most projects, organizing your project directory matters. A typical structure might look like this:

my-next-app/
├── app/
│   ├── [locale]/
│   │   ├── page.tsx
│   │   ├── layout.tsx
│   │   └── globals.css
│   └── favicon.ico
├── components/
├── public/
├── styles/
├── i18n-config.ts
├── next.config.js
├── package.json
└── tsconfig.json

Enable internationalized routing by creating an i18n-config.ts file. This is where you'll define your supported locales and a default language:

export const i18n = {
  locales: ['en', 'fr', 'es'],
  defaultLocale: 'en',
};

Localization adds complexity, but this setup gives you a solid foundation to build on.

It makes future updates or language additions feel more like a breeze than a chore.

Configuring Internationalization and Managing Translations

To configure internationalization in your Next.js app, you’ll start by updating the next.config.js file. This is where you define your supported locales and set a default, think of it as giving your app a roadmap for handling multiple languages. Here’s an example:

module.exports = {
  i18n: {
    locales: ['en-US', 'fr', 'nl-NL'],
    defaultLocale: 'en-US',
  },
};

Next.js also offers automatic locale detection; by default, it reads the Accept-Language header to guess the user’s preferred language.

If you’d rather keep things simpler or avoid any surprises, you can disable this feature by adding localeDetection: false to your configuration.

Organizing your translation files is the next step. A common approach is to create a public/locales directory, with subfolders for each locale. For instance, translations for English might go in public/locales/en/common.json.

Keeping things organized ensures your workflow doesn’t spiral into chaos when your app scales.

When it comes to managing translations, a library like next-intl can save you a ton of headaches. After installing it with npm install next-intl, you can set up middleware for handling routing:

import createMiddleware from 'next-intl/middleware';

export default createMiddleware({
  locales: ['en', 'fr', 'nl-NL'],
  defaultLocale: 'en',
});

Fetching translated content in your components is a breeze with the useTranslations hook; it lets you pull in localized strings without breaking a sweat:

import { useTranslations } from 'next-intl';

function MyComponent() {
  const t = useTranslations('common');
  return <h1>{t('welcome')}</h1>;
}

With this setup, you’re building a multilingual app that’s scalable and efficient.

It’s all about creating a seamless experience, no matter where your users come from.

Handling Localized Routing and Middleware

When it comes to handling localized routing in Next.js, there are two primary strategies: sub-path routing and domain routing. Sub-path routing adds locale identifiers to your URLs, like /fr/about, while domain routing ties specific languages to separate domains, such as example.fr for French. Both options are baked right into Next.js, making setup straightforward.

To bring this to life, you'll configure the i18n object in your next.config.js file with your supported locales and a default one. This acts as your app's language blueprint, ensuring every route knows where it's headed.

But here's where things get even smoother, middleware.

By implementing custom middleware or enabling Next.js's built-in localeDetection option, you can handle language preferences and route users accordingly based on their Accept-Language header. Just don't forget to exclude static assets from middleware processing—nobody likes unnecessary performance hits.

Then there's navigation. Updating layout and link components to support locale-aware links is a must. With Next.js's locale prop in next/link, you can make sure users are seamlessly guided to the right content.

And remember to include a language switcher for user convenience. Add it to your header, set it to remember preferences via the NEXT_LOCALE cookie, and your users will thank you.

Accessibility shouldn't be overlooked; it's non-negotiable. Add ARIA attributes to your switcher and any interactive elements. Prioritizing inclusivity makes your app feel intuitive and polished.

Localized routing shapes an experience that feels personal, fluid, and respectful.

a wooden table topped with scrabble tiles that spell out online languages

Rendering Localized Content and Advanced Features

Rendering localized content in a Next.js application is a technical step that also creates a personalized experience for users around the globe. Next.js provides powerful tools that make dynamic localization both straightforward and efficient.

Start by fetching the active locale. Within your components, use the useRouter hook to access the locale property directly:

import { useRouter } from 'next/router';
const { locale } = useRouter();

For server-side functions like getStaticProps or getServerSideProps, retrieve the locale from the context parameter. This way, you can fetch localized data based on the user's preference:

export async function getStaticProps(context) {
  const { locale } = context;
  // Fetch locale-specific content here
}

Once you've got the locale, you'll want to pass translations as props to your components. Libraries like next-i18next simplify this. Just load your translations and include them in the props:

import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

export async function getStaticProps({ locale }) {
  return {
    props: {
      ...(await serverSideTranslations(locale, ['common'])),
    },
  };
}

For dynamic content such as pluralization or variables, use ICU message syntax in your JSON files. For example:

{
  "welcome": "Welcome, {name}!",
  "messages": "{count, plural, =0 {No messages} one {One message} other {# messages}}"
}

In your component, interpolate these variables with the t function:

import { useTranslation } from 'next-i18next';

const { t } = useTranslation();
const message = t('messages', { count: 5 });

For dates and times, the Intl.DateTimeFormat API ensures proper localization:

const formatter = new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short' });
const formattedDate = formatter.format(new Date());

If your content includes rich text, consider integrating MDX. You can create locale-specific files like:

pages/en/page.mdx
pages/es/page.mdx

These techniques enhance functionality and improve user experience.

By embracing advanced localization features, you help build trust with every user who visits.

Scaling Nextjs Localization for Growth

Scaling Next.js localization is all about preparing for growth without losing sight of performance or user experience.

With a thoughtfully organized project structure, adding new locales and pages becomes a smooth process. Automating translation updates and grouping content with tags can save loads of time while keeping everything consistent.

Plus, whether you're dealing with static or dynamic pages, making sure they're fully localized creates a seamless experience across regions.

Managing translation files effectively is another pillar of scalability. Without a clear system, things can spiral quickly as you support more languages. Best practices like maintaining consistent formatting and refreshing translations regularly keep your app ready to scale while maintaining accessibility, SEO, and speed.

With Next.js localization, you’re building a multilingual app that’s primed for global reach and future expansion.

By implementing these strategies, you can scale smartly while keeping user satisfaction front and center.

Now is the time to turn your idea into a scalable app that's built for growth. Reach out to NextBuild and let's create your MVP together, fast, powerful, and ready to disrupt the market.

Ready to Build Your MVP?

Your product deserves to get in front of customers and investors fast. Let's work to build you a bold MVP in just 4 weeks—without sacrificing quality or flexibility.