alepha@docs:~/docs/packages/@alepha-react$
cat i18n.md
1 min read
Last commit:

#@alepha/react - I18n

#Installation

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

#Primitives

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.

#$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.

ts
 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

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.

On This Page
No headings found...
ready
mainTypeScript
UTF-8packages_alepha_react_i18n.md