---
title: i18n
description: Add locale-prefixed URLs and translated copy with next-intl, extracting inline strings into per-locale catalogs, without Shopify Markets.
url: "https://vercel.shop/docs/skills/enable-i18n"
docs_index: /llms.txt
lastUpdated: 2026-12-05
type: guide
---

> For an index of all documentation, see [/llms.txt](/llms.txt).

## How to use

Ask your agent to use the `enable-i18n` skill, or run it as a slash command in Claude Code:

```text
/enable-i18n
```

<div className="pb-6" />

# Enable i18n

The template serves clean URLs with inline English copy and `shopConfig.localization = { country: "US", language: "EN", locale: "en-US" }`. This skill adds locale-prefixed routes such as `/fr-CA/products/shoe` and translates copy where it stands with next-intl's [`useExtracted`](https://next-intl.dev/docs/usage/extraction): strings stay inline, and `next dev` and `next build` extract them into PO catalogs. `useExtracted` is experimental; read the docs for the installed next-intl version before wiring it.

A copy locale never selects a market. Shopify country, language, currency, and product content stay as `shopConfig.localization` configures them.

If the storefront already uses next-intl, extend its routing, catalogs, and providers instead of following these steps from the start. Keyed `useTranslations` calls keep working beside `useExtracted`. Get approval before changing public URLs.

## 1. Decide

Ask the user, or in a noninteractive run stop and report the open choices:

- The source locale, usually `shopConfig.localization.locale`, and the target locales. Each tag becomes a URL prefix.
- `localePrefix`: `"always"` (`/en-US/...` for every locale) or `"as-needed"` (no prefix for the default locale).
- Who reviews the translations. An agent can draft target catalogs, but a locale goes public only when its catalog is complete and reviewed.

## 2. Wire next-intl

Run `pnpm add next-intl@latest`. These steps need 4.16 or later, which accepts a query string in `useRouter`, `redirect`, and `getPathname`. If the storefront's `minimumReleaseAge` holds back the newest release, take the newest one it allows, as long as it is 4.16 or later. Then create these files.

`lib/i18n/index.ts` is the only list of locales. Routing, the switcher, metadata, and the sitemap all read it:

```ts
import { defineRouting } from "next-intl/routing";

export const routing = defineRouting({
  // Metadata and the sitemap emit alternates; a proxy `Link` header would duplicate them.
  alternateLinks: false,
  defaultLocale: "en-US",
  localePrefix: "always",
  locales: ["en-US", "fr-CA"],
});
```

`lib/i18n/types.ts` makes `Locale` from `next-intl` the union of those tags:

```ts
import type { routing } from "./index";

declare module "next-intl" {
  interface AppConfig {
    Locale: (typeof routing.locales)[number];
  }
}
```

`lib/i18n/navigation/index.ts` is universal: server code uses `getPathname` and `redirect`, and the switcher uses `usePathname` and `useRouter`:

```ts
import { createNavigation } from "next-intl/navigation";

import { routing } from "@/lib/i18n";

export const { getPathname, redirect, usePathname, useRouter } = createNavigation(routing);
```

`lib/i18n/request/server.ts` reads the locale from the root param:

```ts
import { hasLocale } from "next-intl";
import { getRequestConfig } from "next-intl/server";
import { notFound } from "next/navigation";
import { locale as rootLocale } from "next/root-params";

import { routing } from "@/lib/i18n";

// The root param keeps locale a static cache input; next-intl's `requestLocale` reads a request header.
export default getRequestConfig(async ({ locale }) => {
  if (!locale) {
    const param = await rootLocale();
    if (!hasLocale(routing.locales, param)) notFound();
    locale = param;
  }
  return {
    locale,
    messages: (await import(`../messages/${locale}.po`)).default,
    timeZone: "UTC",
  };
});
```

In `next.config.ts`, add the plugin to the list passed to `withShopConfig`, keeping the conditional `withBotId` and `withEve` entries:

```ts
import createNextIntlPlugin from "next-intl/plugin";

import { routing } from "./lib/i18n";

const withNextIntl = createNextIntlPlugin({
  experimental: {
    extract: true,
    messages: {
      format: "po",
      locales: routing.locales,
      path: "./lib/i18n/messages",
      precompile: true,
      sourceLocale: routing.defaultLocale,
    },
    srcPath: ["./app", "./components", "./lib"],
  },
  requestConfig: "./lib/i18n/request/server.ts",
});
```

next-intl needs the request config as a default export: add `lib/i18n/request/server.ts` to the `import/no-default-export` override in `.oxlintrc.json`.

`sourceLocale` is the language the inline strings are written in; change it if that is not the default locale. Extraction writes `lib/i18n/messages/<locale>.po` on every `next dev` and `next build`. Commit the catalogs and review their diffs.

Validate untrusted locale strings with `hasLocale(routing.locales, value)`, or with `z.enum(routing.locales)` in a Server Action schema.

## 3. Move routes under `app/[locale]/`

Move every storefront route and the root layout into `app/[locale]/`, including blogs and custom pages, then delete `app/layout.tsx`. These stay at `app/`: `api/`, `agent/`, `md/`, `llms.txt/`, `sitemap.xml/`, `sitemap/`, `robots.ts`, `manifest.ts`, `global-error.tsx`, `globals.css`, and the icon files.

In `app/[locale]/layout.tsx`:

- Import `"../globals.css"`.
- Keep every export, including `ensureStatic`, `viewport`, and `generateMetadata`.
- Add `generateStaticParams`, set `lang`, and pass only the `client` namespace (Step 4) to the browser:

```tsx
import { NextIntlClientProvider } from "next-intl";
import { getLocale, getMessages } from "next-intl/server";

import { routing } from "@/lib/i18n";

export const generateStaticParams = () => routing.locales.map((locale) => ({ locale }));

export default async function RootLayout({ children }: LayoutProps<"/[locale]">) {
  const [locale, messages] = await Promise.all([getLocale(), getMessages()]);
  // ...
  return (
    <html lang={locale}>
      {/* ... */}
      <NextIntlClientProvider messages={{ client: messages.client }}>
        {/* existing body content */}
      </NextIntlClientProvider>
    </html>
  );
}
```

Add `[locale]` to every `PageProps`, `LayoutProps`, and `RouteContext` route generic, for example `PageProps<"/[locale]/products/[handle]">`. Restart `next dev` after the move so route types regenerate.

## 4. Translate copy in place

- In Server Components, `generateMetadata`, and server helpers, call `const t = await getExtracted()` from `next-intl/server` and wrap each string: `t("Add to cart")`. A non-async Server Component can call `useExtracted()` instead.
- Replace string building with ICU messages, such as `t("Hello {name}", { name })` and `t("{count, plural, one {# item} other {# items}} found", { count })`, and use `t.rich` for inline markup. This replaces `formatCount` in `lib/content/index.ts`.
- `t` takes a string literal and must be called in the function that obtained it. Move label maps, enum lookups, and module-scope label constants into a function that owns `t` and returns plain strings.
- When a short string is ambiguous, add a description: `t({ description: "Badge on discounted products", message: "Sale" })`.
- Client leaves keep receiving translated primitive labels from their server parent. A leaf that must format with client state calls `useExtracted("client")`; the locale layout passes only that namespace.
- `components/ui/` stays copy-free. Cover `error.tsx`, `not-found.tsx`, metadata, `alt` text, and `aria-label` values. `global-error.tsx` renders outside the locale layout, so its copy stays static.
- Format with the active locale. Find formatting that reads `shopConfig.localization.locale` with `rg "localization.locale" app components lib agent`, and give helpers such as `formatPrice` and `formatDate` a required `locale: Locale` parameter so `tsc` lists every caller. Server Components pass `await getLocale()`, client components pass `useLocale()`, and code outside a request, such as Shop Agent tools, passes `routing.defaultLocale`. Currency still comes from Shopify's `Money`.
- Delete `lib/content/index.ts` helpers once nothing calls them.
- Server Actions and Route Handlers have no root param, so `next/root-params` throws there. Parse the locale from their input and call `getExtracted({ locale })`.

## 5. Links and redirects

Keep `Link` from `@/components/ui/link`, which owns intent prefetching, and localize root-relative string hrefs inside it, so call sites keep passing unprefixed paths like `/products/shoe`:

```tsx
const locale = useLocale();
const localizedHref =
  typeof href === "string" && href.startsWith("/") ? getPathname({ href, locale }) : href;
```

Use `useLocale()` from `next-intl`, which reads the layout's provider. `useParams()` here fails prerendering of every dynamic route with `encountered URL data useParams() in a Client Component outside of <Suspense>`. Pass `localizedHref` to `NextLink` and to the intent-prefetch destination key.

In Server Components and server helpers, replace `redirect` from `next/navigation` with `redirect({ href: "/account/profile", locale: await getLocale() })` from `@/lib/i18n/navigation` when the target is an app route; an unprefixed redirect costs a second hop through the proxy. Paths that Hydrogen's handlers serve in `proxy.ts`, such as `/account/login` and `/account/refresh` in `lib/auth/server.ts`, stay unprefixed; a prefixed one misses Shopify dispatch. Hydrogen's auth handlers redirect to unprefixed paths such as `/account`, and next-intl adds the locale.

## 6. Proxy

Compose next-intl where `proxy.ts` falls through after Shopify dispatch and Markdown negotiation. Keep the template matcher. Gate negotiation in code so `/api/*` Route Handlers that Hydrogen declines, such as webhooks, and dotted public files keep their paths:

```ts
import createMiddleware from "next-intl/middleware";
import { NextRequest, NextResponse } from "next/server";

import { routing } from "@/lib/i18n";

const handleI18n = createMiddleware(routing);
const UNLOCALIZED_PATH = /^\/api(?:\/|$)|\./;

// Inside proxy(), replacing the NextResponse.next() branch:
const forwarded = forwardCustomerRefreshAttempt(request.nextUrl, headers);
const response = markdownPath
  ? NextResponse.rewrite(/* unchanged */)
  : UNLOCALIZED_PATH.test(pathname)
    ? NextResponse.next({ request: { headers: forwarded } })
    : handleI18n(new NextRequest(request, { headers: forwarded }));
applyProxyResponseHeaders(requestContext, response.headers);
```

next-intl redirects bare `/` and unprefixed paths to the negotiated locale.

`NextRequest` is a value import here. The proxy bundle has no `next/root-params`, so nothing `proxy.ts` imports may reach `@/lib/i18n/navigation` or the request config; otherwise the build fails with `Export locale doesn't exist in target module [next]/root-params.js [middleware]`.

## 7. SEO, sitemap, and Markdown

Every public URL comes from `getPathname({ href, locale })`, never from `` `/$\{locale\}` `` string building.

- `buildAlternates` in `lib/seo/index.ts` takes `locale: Locale`. It prefixes the canonical and returns `languages` for each of `routing.locales`, plus `x-default` for `routing.defaultLocale`, all built from `buildCanonicalPath` so filter and cursor handling still applies. Callers pass `await getLocale()`, and synchronous metadata helpers become async to do so.
- `app/sitemap/[shard]/route.ts` emits one `<url>` per locale for each resource and static path, each listing every locale and `x-default` as `<xhtml:link rel="alternate" hreflang="..." href="..."/>`. Add `xmlns:xhtml="http://www.w3.org/1999/xhtml"` to `<urlset>`. The sitemap index is unchanged.
- Move `getMarkdownPath`, `getMarkdownMirrorPath`, and `getMarkdownRewritePath` into `lib/markdown/representation/request.ts` and import them from there in `proxy.ts`. `getMarkdownPath` strips a prefix that passes `hasLocale`, so `/fr-CA/products/shoe` and its `.md` mirror reach the same `app/md` handlers. Mirrors serve Shopify content in the deployment language, so they are the same for every locale. `markdownHeaders` stays in `index.ts` and builds its canonical `Link` with `routing.defaultLocale`.
- Structured data renders inside pages: its URLs and `inLanguage` use the page locale.
- Absolute URLs built outside pages, such as `app/llms.txt` and Shop Agent outputs, use `routing.defaultLocale`.

## 8. Language switcher

Add a leaf Client Component to the nav, wrapped in `Suspense` with a same-size fallback because it reads search params. It reads `useLocale()` from `next-intl`, `usePathname()` and `useRouter()` from `@/lib/i18n/navigation`, and `useSearchParams()` from `next/navigation`, and switches with `router.replace({ pathname, query: searchParams.toString() }, { locale })`, keeping the path and query. Label each option in its own language, for example `new Intl.DisplayNames([option], { type: "language" }).of(option)`. Switching language never touches the cart, country, or currency.

## Cache Components traps

- If `app/layout.tsx` still exists above `app/[locale]/`, the locale is not a root param and `rootLocale()` returns `undefined`.
- A missing `generateStaticParams` on the locale layout fails the build with `A required root parameter (locale) was not provided in generateStaticParams`. Keep each dynamic route's `generateStaticParams` with its `PLACEHOLDER_HANDLE` from `lib/static-params`.
- A child segment with a weaker `ensureStatic` fails with `A child segment cannot override a parent segment with a less-constrained ensureStatic`.
- A `headers()`, `cookies()`, or `searchParams` read outside `<Suspense>` fails every localized route with `encountered uncached or runtime data during prerendering`. `next build --debug-prerender` names the line. Do not opt out with `export const instant = false`.
- Do not add `setRequestLocale`. It is next-intl's legacy API from before root params existed, and the request config above makes it unnecessary.
- Do not add `app/(unlocalized)/page.tsx` for `/`; it fails with `doesn't have a root layout`. The proxy redirects `/`. Unknown locales get Next.js's built-in 404, and a branded one needs the experimental `app/global-not-found.tsx`.

## Verify

```bash
pnpm check
pnpm build   # extracts catalogs; localized storefront routes must stay partially prerendered (◐)
# Prints the number of untranslated entries; it must be 0 before a locale goes public:
awk '/^msgstr ""$/ { if ((getline next_line) <= 0 || next_line !~ /^"/) count++ } END { print count + 0 }' lib/i18n/messages/fr-CA.po
pnpm start
# Replace the handle with a real product:
curl -sI http://localhost:3000/ | grep -i location   # /en-US
curl -s http://localhost:3000/fr-CA/products/HANDLE | grep -oE '<html lang="[^"]*"|rel="(canonical|alternate)"[^>]*' | sort -u
curl -s http://localhost:3000/fr-CA/products/HANDLE | grep -oE '<a [^>]*href="/[^"]*"' | grep -v 'href="/cart/' | grep -vc 'href="/fr-CA'   # 0; Shopify cart permalinks stay unprefixed
curl -sI http://localhost:3000/fr-CA/products/HANDLE.md | grep -i '^content-type'
curl -s http://localhost:3000/sitemap/products-1.xml | grep -c 'hreflang="fr-CA"'
```

- Default-locale pages show the same text as before the migration.
- An empty `msgstr` renders as blank text with no error, so every target catalog must report 0 untranslated entries.
- Each locale serves 200 at its prefix, internal links keep the current locale, and the switcher keeps the path and query.
- Page metadata has a localized canonical and hreflang alternates, and the sitemap lists every locale.
- After a language switch, the cart, Shopify country, and currency are unchanged.
- `/api/*` webhooks, `.md` mirrors, and Shopify routes respond as before.
- Update the installation's `AGENTS.md`: copy is inline through `getExtracted` and `useExtracted`, client leaves use the `client` namespace, and catalogs are committed with every target locale complete.

---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/llms.txt](/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/agents.md](/agents.md)