Next.js Pages Router with next-i18next + i18nexus

Next.js Logo

Learn the scalable way to localize your Next.js app

(7 minute read)

Last updated: June 2026

Prefer a different library?

Which library should I choose? Compare them: next-i18next vs react-intl, next-i18next vs next-intl, react-i18next vs react-intl

1. Start with a Pages Router app

This guide is for an existing Next.js Pages Router app. Using app instead of pages? Follow the App Router tutorial.

Next.js supplies locale routing for the Pages Router. next-i18next supplies translated messages, and i18nexus manages the strings. next-i18next 16 requires Next.js 14.1+ and React 18+. The snippets use JavaScript, no src directory, and Node.js 22.13+ or 24 LTS.

npm install next-i18next@^16.3 i18next@^26 react-i18next

2. Let i18nexus handle your translations

Write your copy once. i18nexus stores your source strings, AI translates them into your project languages, and gives your team a place to review the results. The CLI brings those translations into your app.

Already have an i18nexus project?

Use its project API key instead of creating another project with init. Install @i18nexus/cli as a dev dependency, add the key to .env, and run npx i18nexus pull. Follow the CLI guide to add development and build sync. The library, languages, namespaces, and output path must match the imports in this tutorial.

To create a new i18nexus project, run this from your app directory:

npx @i18nexus/cli@latest init

For this example, use these choices:

  • Sign in or create an account in the browser opened by the CLI.
  • Use i18next as your library. Installed libraries are detected automatically.
  • For a new app, choose that you do not have translation JSON yet. Set English (en) as the base language and German (de) as an additional language.
  • Use one namespace: common.
  • Accept automatic sync in package.json. This installs the CLI locally and adds development and build sync scripts.
Already have translation JSON?

The CLI can detect and import it into your new i18nexus project. Keep your existing language codes and namespaces, and adjust the examples below to match.

If you keep a custom translation folder, the CLI includes it in your sync scripts. For manual pulls, include that same path: npx i18nexus pull --path ./your-folder.

When setup finishes, add the project API key printed by the CLI to .env in the app root. Add .env to .gitignore:

.env
I18NEXUS_API_KEY="your_project_api_key"

Add your first two strings

Open the dashboard link printed by the CLI and add these English strings in the common namespace. The key is what your code uses; the value is what your users read.

Click + String to enter a key and its English text, then save with the checkmark. This sample project uses the default namespace; select common for this tutorial. Your notes column may say Description or Team Notes, depending on your project settings. Select an image to enlarge it.
  • welcome: Welcome to my app!
  • greeting: Hello, {{name}}!

Save each string, then expand its row to see the translations. You can review and edit them in the same place as your source text.

Expand a saved string to review its AI translations. This sample project uses different keys and languages; follow the keys above and use English and German for this guide.

Prefer working with an AI coding assistant? Choose MCP setup during init, then ask your assistant to create these same strings through i18nexus. The MCP guide explains that workflow. The dashboard remains available for you and your team.

Give AI translation a moment to finish, then download the generated JSON before adding the imports in the next step:

npx i18nexus pull

You should now have public/locales/en/common.json and its German equivalent. These are generated files: make future string changes in i18nexus and let the CLI sync them.

3. Configure next-i18next

next-i18next.config.js
module.exports = {
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'de']
  },
  defaultNS: 'common',
  reloadOnPrerender: process.env.NODE_ENV === 'development'
};
next.config.js
const {i18n} = require('./next-i18next.config');

module.exports = {i18n};

Merge i18n into your existing Next.js config. Keep a single Next.js config file. The default translation location matches the CLI output: public/locales.

pages/_app.js
import {appWithTranslation} from 'next-i18next/pages';

function App({Component, pageProps}) {
  return <Component {...pageProps} />;
}

export default appWithTranslation(App);

Keep your global CSS import and any existing providers in _app.js. Version 16 uses the next-i18next/pages entry point for this router.

4. Render translations

pages/index.js
import {useTranslation} from 'next-i18next/pages';
import {serverSideTranslations} from 'next-i18next/pages/serverSideTranslations';
import LanguageSwitcher from '../components/LanguageSwitcher';

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

export default function Home() {
  const {t} = useTranslation('common');
  return (
    <main>
      <h1>{t('welcome')}</h1>
      <p>{t('greeting', {name: 'Sam'})}</p>
      <LanguageSwitcher />
    </main>
  );
}

Add serverSideTranslations to each page that needs translations and list the namespaces that page uses. You can use it in getServerSideProps when the page requires request-time data.

5. Change languages

components/LanguageSwitcher.js
import {useRouter} from 'next/router';

export default function LanguageSwitcher() {
  const router = useRouter();

  function changeLanguage(locale) {
    document.cookie = `NEXT_LOCALE=${locale};path=/;max-age=2592000;SameSite=Lax`;
    router.push(
      {pathname: router.pathname, query: router.query},
      router.asPath,
      {locale}
    );
  }

  return (
    <select aria-label="Language" value={router.locale} onChange={e => changeLanguage(e.target.value)}>
      <option value="en">English</option>
      <option value="de">Deutsch</option>
    </select>
  );
}

Use Link from next/link for navigation between pages; Next.js preserves the current locale. The switcher also preserves dynamic route parameters and the current URL.

Run npm run dev and try the language switcher. The welcome message and greeting should change together:

English
Deutsch
The example running in English and German. Your app's styling and AI-generated wording may differ.

Keep translations in sync

The sync script added by the CLI runs i18nexus listen alongside your app. It pulls on startup and updates the generated JSON when strings or translations change in i18nexus. Refresh the page if your app still shows a cached translation.

For deployment, set I18NEXUS_API_KEY in your build environment and run npm run build. The CLI-added prebuild script pulls the latest JSON before compilation. Install dev dependencies in the build stage so the CLI is available. Updates to bundled translations require a new build.

The Pages Router's built-in internationalized routing requires a Next.js server deployment; it is not compatible with output: 'export'.

Keep adding source strings in the dashboard or through the i18nexus MCP. Your team can review and refine the AI translations in the same project. next-i18next documentation has the details for larger apps.

Level up your localization

It only takes a few minutes to streamline your translations forever.

Get started