Quick Start (React)
-
Install packages
Terminal window pnpm add @fluenti/core @fluenti/reactpnpm add -D @fluenti/cli @fluenti/vite-plugin -
Configure Vite
vite.config.ts import { defineConfig } from 'vite'import react from '@vitejs/plugin-react'import fluenti from '@fluenti/vite-plugin'export default defineConfig({plugins: [fluenti({ framework: 'react' }),react(),],}) -
Create
fluenti.config.tsfluenti.config.ts import { defineConfig } from '@fluenti/cli'export default defineConfig({sourceLocale: 'en',locales: ['en', 'zh-CN'],catalogDir: './locales',format: 'po',include: ['./src/**/*.{tsx,ts,jsx}'],compileOutDir: './src/locales/compiled',}) -
Write your component — just use
t“ and<Trans>src/Home.tsx import { useI18n } from '@fluenti/react'import { Trans, Plural } from '@fluenti/react'export function Home() {const { setLocale } = useI18n()const name = 'World'const count = 3return (<div>{/* t`` tagged template — compiler macro, no import needed */}<h1>{t`Welcome to my app`}</h1><p>{t`Hello, ${name}!`}</p>{/* Rich text with real HTML — no XSS, no indexed placeholders */}<Trans>Read the <a href="/docs">documentation</a> to learn more.</Trans>{/* Locale-aware plurals */}<Plural value={count} one="# item in cart" other="# items in cart" /><button onClick={() => setLocale('en')}>English</button><button onClick={() => setLocale('zh-CN')}>中文</button></div>)}No manual keys. No JSON files. The
t`...`tagged template is a compiler macro — the Vite plugin injects it automatically. -
Extract messages
Terminal window npx fluenti extractThis scans your source files and generates catalog files in
./locales/. -
Add translations
Open
locales/zh-CN.poand fill inmsgstrfields:msgid "Welcome to my app"msgstr "欢迎使用我的应用"msgid "Hello, {name}!"msgstr "你好,{name}!" -
Compile messages
Terminal window npx fluenti compile -
Initialize from compiled output
src/main.tsx import { createRoot } from 'react-dom/client'import { I18nProvider } from '@fluenti/react'import { Home } from './Home'import en from './locales/compiled/en'import zhCN from './locales/compiled/zh-CN'function App() {return (<I18nProviderlocale="en"fallbackLocale="en"messages={{ en, 'zh-CN': zhCN }}><Home /></I18nProvider>)}createRoot(document.getElementById('root')!).render(<App />)
Rich text with <Trans>
Section titled “Rich text with <Trans>”import { Trans } from '@fluenti/react'
<Trans>Click <a href="/next">here</a> to continue.</Trans><Trans>This is <strong>important</strong> information.</Trans>Plurals with <Plural>
Section titled “Plurals with <Plural>”import { Plural } from '@fluenti/react'
<Plural value={count} zero="No items" one="# item" other="# items" />Framework compatibility
Section titled “Framework compatibility”@fluenti/react works with any React-based framework:
- React SPA (Vite) — full Vite plugin support
- React Router — Quick Start (React Router)
- Next.js — Quick Start (Next.js)
- TanStack Start — Quick Start (TanStack Start)
Next steps
Section titled “Next steps”- React SPA guide — deeper patterns for React SPAs
- Translating Content — all translation APIs
- Configuration — full
fluenti.config.tsreference