---
updatedAt: 2026-08-06T12:36:59.000Z
agentTools:
  siteIndex: https://documentation.bloomreach.com/llms.txt
  projectIndex: https://documentation.bloomreach.com/content/llms.txt
---

# Implement Next.js internationalized routing

## Introduction

### Goal

Implement support for localized channels using Next.js internationalized routing in your frontend application.

### Background

Next.js has built-in support for [internationalized (i18n) routing](https://nextjs.org/docs/advanced-features/i18n-routing). You can provide a list of locales, the default locale, and domain-specific locales and Next.js will automatically handle the routing.

This page shows how to implement Next.js i18n routing in your Content SaaS frontend application using the [Reference SPA](https://documentation.bloomreach.com/content/docs/bloomreach-reference-spa) as an example.

### Prerequisites

* You are familiar with the [development environment](https://documentation.bloomreach.com/content/docs/development-environment).
* Your frontend application is (based on) the [Reference SPA](https://documentation.bloomreach.com/content/docs/bloomreach-reference-spa).

The easiest way to get started is to create your channels using the [Reference SPA](https://documentation.bloomreach.com/content/docs/bloomreach-reference-spa) [channel template](https://documentation.bloomreach.com/content/docs/storefront-integrations) in the *Experience manager* and clone the [Reference SPA frontend application from Github](https://github.com/bloomreach/bloomreach-reference-spa).

## Set up localized channels

Set up your channels using a naming pattern that includes a channel's locale. For example, `<name>-<locale>`:

* `mychannel-en`
* `mychannel-fr`

Your frontend application will rely on this naming pattern to match the selected locale to the correct channel and corresponding [Delivery API](https://documentation.bloomreach.com/content/reference/delivery-api) endpoint.

## Configure endpoint environment variables

In your frontend application's `.env` file, add environment variables for each localized channel's [Delivery API](https://documentation.bloomreach.com/content/reference/delivery-api) endpoint as in the following snippet (replace "mycontent" and "mychannel" with the relevant names):

```text .env
NEXT_PUBLIC_BRXM_ENDPOINT_en=https://mycontent.bloomreach.io/delivery/site/v1/channels/mychannel-en/pages
NEXT_PUBLIC_BRXM_ENDPOINT_fr=https://mycontent.bloomreach.io/delivery/site/v1/channels/mychannel-fr/pages
```

> 👍 Tip
>
> If you don't have an `.env` file yet, you can create one by copying the provided `.env.dist` file.

## Configure locales

Add the `i18n` configuration to your frontend application's `next.config.js` file. Provide a list of `locales` that matches the endpoints you configured, as well as the `defaultLocale`:

```javascript next.config.js
module.exports = {
  // existing configuration here
  i18n: {
    locales: ['en', 'fr'],
    defaultLocale: 'en'
}};
```

The above configuration uses sub-path routing by default. You may also add domains configuration in order to use domain routing. See [Locale Strategies](https://nextjs.org/docs/advanced-features/i18n-routing#locale-strategies) in the Next.js i18n documentation for details.

## Update your front-end code

In `src/utils.ts`, find the `buildConfiguration` function and adapt it so it accepts a `locale` parameter and uses it to select the correct endpoint environment variable:

```javascript src/utils.js
export function buildConfiguration(path: string, query: ParsedUrlQuery, locale: any): Omit<Configuration, 'httpClient'> {
  const endpointQueryParameter = 'endpoint';
  const configuration: Record<string, any> = {
    endpointQueryParameter,
    path,
    locale,
  };
  const endpoint = query[endpointQueryParameter];
  if (!endpoint) {
    configuration.endpoint = process.env[`NEXT_PUBLIC_BRXM_ENDPOINT_${locale}`];
  }
  return configuration;
}
```

In `pages/[[...route]].tsx`, adapt `Index.getInitialProps` to use the `locale` and pass it into the call to `buildConfiguration`:

```javascript pages/[[...route]].tsx
Index.getInitialProps = async ({ req: request, res: response, asPath: path, query, locale }) => {
```

```javascript pages/[[...route]].tsx
const configuration = buildConfiguration(path ?? '/', query, locale);
```

In `pages/_error.tsx`, do the same for `Error.getInitialProps`:

```javascript pages/_error.tsx
Error.getInitialProps = async ({ req: request, res: response, err, asPath, query, locale }) => {
```

```javascript pages/_error.tsx
const configuration = buildConfiguration(path, query, locale);
```