npm install @alepha/react
Add i18n support to your Alepha React application. SSR and CSR compatible.
It supports lazy loading of translations and provides a context to access the current language.
Primitives are functions that define and configure various aspects of your application. They follow the convention of starting with $ and return configured primitive instances.
For more details, see the Primitives documentation.
Register a dictionary entry for translations.
It allows you to define a set of translations for a specific language. Entry can be lazy-loaded, which is useful for large dictionaries or when translations are not needed immediately.
1import { $dictionary } from "@alepha/react/i18n"; 2 3const Example = () => { 4 const { tr } = useI18n<App, "en">(); 5 return <div>{tr("hello")}</div>; // 6} 7 8class App { 9 10 en = $dictionary({11 // { default: { hello: "Hey" } }12 lazy: () => import("./translations/en.ts"),13 });14 15 home = $page({16 path: "/",17 component: Example,18 })19}20 21run(App);
Hooks provide a way to tap into various lifecycle events and extend functionality. They follow the convention of starting with use and return configured hook instances.
Hook to access the i18n service.