Tutorial
This tutorial walks you through building a React app with full i18n support using Fluenti and Vite. By the end, you will have a working app with English and Japanese translations.
What you will build
Section titled “What you will build”A small task manager app with:
- A greeting message with the user’s name
- A task counter with plural forms
- A locale switcher
-
Create a new project
Terminal window npm create vite@latest my-i18n-app -- --template react-tscd my-i18n-app -
Install Fluenti
Terminal window npm install @fluenti/core @fluenti/reactnpm install -D @fluenti/cli -
Initialize Fluenti
Terminal window npx fluenti initWhen prompted, set source locale to
en, target locales toja, and format topo. This generatesfluenti.config.tsand adds scripts topackage.json. -
Configure Vite
Update
vite.config.ts:import { defineConfig } from 'vite'import react from '@vitejs/plugin-react'import fluentiReact from '@fluenti/react/vite-plugin'export default defineConfig({plugins: [fluentiReact(), react()],}) -
Write your component
Replace
src/App.tsxwith a simple component that uses tagged templates for translation:import { I18nProvider, useI18n, t } from '@fluenti/react'function TaskApp() {const { setLocale, locale } = useI18n()return (<div><h1>{t`Hello, ${'Alice'}!`}</h1><p>{t`You have ${3} tasks today`}</p><button onClick={() => setLocale(locale === 'en' ? 'ja' : 'en')}>{t`Switch language`}</button></div>)}export default function App() {return (<I18nProvider locale="en" messages={{}}><TaskApp /></I18nProvider>)} -
Extract and translate
Run
npm run i18n:extractto generate PO catalogs, then openlocales/ja.poand add translations:msgid "Hello, {name}!"msgstr "こんにちは、{name}さん!"msgid "You have {taskCount} tasks today"msgstr "今日のタスクは{taskCount}件です"msgid "Switch language"msgstr "言語を切り替え" -
Compile and load messages
Run
npm run i18n:compileto generate optimized JS modules, then updateApp.tsxto load them:import { I18nProvider, useI18n, t } from '@fluenti/react'import en from './locales/compiled/en'import ja from './locales/compiled/ja'function TaskApp() {const { setLocale, locale } = useI18n()return (<div><h1>{t`Hello, ${'Alice'}!`}</h1><p>{t`You have ${3} tasks today`}</p><button onClick={() => setLocale(locale === 'en' ? 'ja' : 'en')}>{t`Switch language`}</button></div>)}export default function App() {return (<I18nProvider locale="en" fallbackLocale="en" messages={{ en, ja }}><TaskApp /></I18nProvider>)} -
Run
Terminal window npm run devOpen your browser and click “Switch language” to see the translations in action.
Next steps
Section titled “Next steps”- Message Format — plurals, selects, and ICU syntax
- Code Splitting — lazy-load translations per locale
- Best Practices — production patterns