Alepha React I18n

Internationalization (i18n) support for React applications using Alepha.

Installation

This package is part of the Alepha framework and can be installed via the all-in-one package:

npm install alepha

Alternatively, you can install it individually:

npm install @alepha/core @alepha/react-i18n

Module

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

$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

useI18n()

Hook to access the i18n service.

Table of contents