Get started in 3 steps
- 01
Install the React-friendly SDK
For most Vite projects, start with @better-i18n/vite, @better-i18n/use-intl and use-intl: the plugin injects translations server-side before first paint.
terminalbashnpm install lefine - 02
Wrap your app once
Mount BetterI18nProvider in your Vite entry file so locale data is available before the first render.
src/main.tsx// src/entry-server.tsx (Vite SSR)import { renderToString } from 'react-dom/server';import { createStrings } from 'lefine/server';import { StringsProvider } from 'lefine/react';import App from './App';const strings = createStrings({ project: 'app_3f9c0e4b2a7d4e1f9b6c5a8d7e2f1a0b' });export async function render(locale: string) { const props = await strings.load(locale, ['landing']); return { html: renderToString( <StringsProvider {...props}> <App /> </StringsProvider> ), props, // send as JSON so the client renders the same strings };} - 03
Translate inside components
Use useTranslations() for keys and interpolation while keeping Vite hot reload fast during content iteration.
src/components/Hero.tsximport { useStrings } from 'lefine/react';export function Hero() { const t = useStrings('landing'); return <h1>{t('headline')}</h1>;}