Installation & Setup
Comienza con @better-i18n/use-intl en tres pasos: instala, envuelve tu app con el proveedor y empieza a traducir.
- 01
Install
Agrega @better-i18n/use-intl y use-intl a tu proyecto.
terminalbashnpm install lefine - 02
Envuelve tu app con BetterI18nProvider
Coloca el proveedor en la raíz de tu árbol de componentes. Obtiene los mensajes desde la CDN y los pone disponibles mediante 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
Llama a useTranslations() en cualquier componente para acceder a tus claves de traducción con soporte completo para TypeScript.
MyComponent.tsximport { useStrings } from 'lefine/react';function MyComponent() { const t = useStrings('common'); return <h1>{t('welcome')}</h1>;}