Quick Start

Next.js

This page demonstrates the minimal setup of Intor in a Next.js project.


Installation

This example assumes a Next.js App Router setup using the src/ directory structure.
For details, see: Next.js .

Install Intor:

npm install intor
yarn add intor
pnpm add intor
bun add intor

Project Structure

index.json
U

index.json
U

layout.tsx
M
page.tsx
M

intor-config.ts
U
intor-client-provider.tsx
U

Integration Steps

♯1 Messages

Create a messages directory in your project, and add a subdirectory for each locale.
Each locale provides an index.json file.

index.json
U

index.json
U
{
  "hello": "Hello, {name}",
  "rich": "A <tag>text</tag>."
}
{
  "hello": "Bonjour, {name}",
  "rich": "Un <tag>texte</tag>."
}

♯2 Config

Create an i18n/ directory under src/, and add an intor-config.ts file inside it.
This example uses the most basic translation loading approach by defining messages directly in the config.

For more details, see: Message Loading

intor-config.ts
U
import { defineIntorConfig } from "intor";
import EN from "../../messages/en/index.json";
import FR from "../../messages/fr/index.json";

export const intorConfig = defineIntorConfig({
  defaultLocale: "en",
  supportedLocales: ["en", "fr"],
  messages: {
    en: EN,
    fr: FR,
  },
});

♯3 Initialization

Create intor-client-provider.tsx inside the i18n/ directory.

intor-client-provider.tsx
U
import type { ReactNode } from "react";
import { IntorProvider, type IntorValue } from "intor/react";

export function IntorClientProvider({
  value,
  children,
}: {
  value: IntorValue;
  children: ReactNode;
}) {
  return <IntorProvider value={value}>{children}</IntorProvider>;
}

Then, call intor() in layout.tsx to initialize the translation system, and pass the returned value into IntorClientProvider.

layout.tsx
M
// ...
import { intor } from "intor/next/server";
import { intorConfig } from "@/i18n/intor-config";
import { IntorClientProvider } from "@/i18n/intor-client-provider";

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const value = await intor(intorConfig);

  return (
    <html lang={value.locale}>
      <body>
        <IntorClientProvider value={value}>{children}</IntorClientProvider>
      </body>
    </html>
  );
}

Usage Example

Use useTranslator to access translation capabilities:

  • t: returns the resolved text
  • tRich: renders structured messages with semantic tags

<Link />: handles both page navigation and locale switching.

page.tsx
M
"use client";

import { useTranslator } from "intor/react";
import { Link } from "intor/next";

export default function Home() {
  const { t, tRich } = useTranslator();

  return (
    <>
      <p>{t("hello", { name: "Intor" })}</p>

      <p>{tRich("rich", { tag: (children) => <b>{children}</b> })}</p>

      <Link locale="en">English</Link>
      <Link locale="fr">French</Link>
    </>
  );
}

Server-side

On the server side, the same translation capabilities can be accessed via getTranslator().
This can be used for metadata generation, API routes, or other server-only execution environments.

layout.tsx
M
// ...
import { Metadata } from "next";
import { getTranslator } from "intor/next/server";

export const generateMetadata = async (): Promise<Metadata> => {
  const { t } = await getTranslator(intorConfig);
  return { title: t("hello") };
};
// ...