Installation & Setup
Get started with @better-i18n/use-intl in three steps — install, wrap your app with the provider, and start translating.
- 01
Install
Add @better-i18n/use-intl and use-intl to your project.
terminalbashnpm install lefine - 02
Wrap your app with BetterI18nProvider
Place the provider at the root of your component tree. It fetches messages from the CDN and makes them available via hooks.
App.tsx// strings.ts (server)import { createStrings } from 'lefine/server';export const strings = createStrings({ project: 'app_3f9c0e4b2a7d4e1f9b6c5a8d7e2f1a0b' });// in your route loader or server function:// const props = await strings.load(locale, ['common']);// App.tsximport { StringsProvider } from 'lefine/react';function App({ props }) { return ( <StringsProvider {...props}> <YourApp /> </StringsProvider> );} - 03
Use translations
Call useTranslations() in any component to access your translation keys with full TypeScript support.
MyComponent.tsximport { useStrings } from 'lefine/react';function MyComponent() { const t = useStrings('common'); return <h1>{t('welcome')}</h1>;}