Quick Start
Hono
This page demonstrates the minimal setup of Intor in a Hono project.
Installation
This example follows the official Hono setup process and selects cloudflare-workers as the execution environment.
For related setup details, see: Hono
Install Intor:
npm install intoryarn add intorpnpm add intorbun add intor
Project Structure
index.jsonUindex.jsonUindex.tsMintor-config.tsU
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 intor-config.ts under src/.
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
Register Intor’s request handler with Hono.
index.tsM
import { Hono } from "hono"; import { createIntorHandler } from "intor/hono"; import { intorConfig } from "./intor-config"; const app = new Hono(); app.use(createIntorHandler(intorConfig)); export default app;
Usage Example
Use getTranslator to access translation capabilities:
t: returns the resolved texttRich: renders structured messages with semantic tags
index.tsM
import { getTranslator } from "intor/hono"; // ... app.get("/", async (c) => { const { t, tRich } = await getTranslator(intorConfig, c); return c.json({ hello: t("hello", { name: "Intor" }), rich: tRich("rich", { tag: (children) => `<b>${children}</b>` }), }); }); // ...
As a convenience option, translation helpers are also available directly on
c, though type inference is limited in this mode.app.get("/", async (c) => { return c.json({ hello: c.get("t")("hello", { name: "Intor" }), rich: c.get("tRich")("rich", { tag: (children) => `<b>${children}</b>` }), }); });