Intlayer next js

From aymericzip/intlayer · View interactive version

Intlayer next js is an AI agent skill from the GitHub repository aymericzip/intlayer. Integrates Intlayer internationalization with Next.js App Router and Pages Router. Use when the user asks to "setup Next.js i18n", use "useIntlayer" in Server Components, or handle client-side translations in Next.js.

How to use this skill

Skill file

Intlayer Next.js Usage

Core Philosophy

Intlayer promotes Component-Level Content Declaration. Instead of a massive global translation file, content is declared in *.content.ts files adjacent to the Next.js components that use them.

Workflow

To create a translated component, you need two files:

  1. Declaration: A content file (e.g., myComponent.content.ts) defining the dictionary.
  2. Implementation: A Next.js component (Server or Client) using the useIntlayer hook.

1. Declare Content

Create a content file using t() for translations.

File: src/components/MyComponent/myComponent.content.ts

import { t, type Dictionary } from "intlayer";

const content = {
  // The 'key' must be unique and matches what you pass to useIntlayer()
  key: "my-component",
  content: {
    text: t({
      en: "Welcome",
      fr: "Bienvenue",
      es: "Hola",
    }),
  },
} satisfies Dictionary;

export default content;

Setup

Provider

Mount one IntlayerProvider (from next-intlayer/server) in the [locale] layout. It serves both server and client components, so pages don't wrap themselves (see the Next.js guide).

useIntlayer Hook

next-intlayer is isomorphic: the same useIntlayer import works in Server Components and in "use client" components.

import { useIntlayer } from "next-intlayer";

export const MyComponent = () => {
  const content = useIntlayer("my-component");

  return <h1>{content.text}</h1>;
};

Next.js package Documentation

Bundle Optimization

Read content fields by name (dot access or destructuring) so the build can purge and minify the dictionary. Never index content at runtime (content.statuses[status], use select()), and call useIntlayer in each child component instead of passing content as a prop. See the intlayer-bundle-optimization skill.

Compiler

The Intlayer Compiler can extract all your content keys from your components, using one CLI command (npx intlayer extract) or automatically at app build.

References

Environments

Concepts

Packages

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.