@alepha/react - I18n
Installation
This module is part of the Alepha framework:
npm install @alepha/react
Overview
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.
API Reference
Descriptors
Descriptors are functions that define and configure various aspects of your application. They follow the convention of starting with $ and return configured descriptor instances.
For more details, see the Descriptors documentation.
$dictionary()
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.
import { $dictionary } from "@alepha/react/i18n";
const Example = () => {
const { tr } = useI18n<App, "en">();
return <div>{tr("hello")}</div>; //
}
class App {
en = $dictionary({
// { default: { hello: "Hey" } }
lazy: () => import("./translations/en.ts"),
});
home = $page({
path: "/",
component: Example,
})
}
run(App);
Hooks
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.
useI18n()
Hook to access the i18n service.
Table of contents