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 intoryarn add intorpnpm add intorbun add intor
Project Structure
index.jsonUindex.jsonUlayout.tsxMpage.tsxMintor-config.tsUintor-client-provider.tsxU
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.jsonUindex.jsonU
{ "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.tsU
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.tsxU
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.tsxM
// ... 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 texttRich: renders structured messages with semantic tags
<Link />: handles both page navigation and locale switching.
page.tsxM
"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.tsxM
// ... 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") }; }; // ...