Lingui
Lingui is a JavaScript library for internalization (i18n) of JavaScript projects, including React, Vue, Next.js, Node.js, Angular, and others.
Installation
First, you need to install and set up Lingui for your project.
Then, install the Crowdin OTA Client:
- npm
- Yarn
- pnpm
npm install @crowdin/ota-client
yarn add @crowdin/ota-client
pnpm add @crowdin/ota-client
Usage
Integrating the Crowdin OTA Client with Lingui is pretty straightforward. You just need to load messages received from the OTA client instead of the local files.
import { i18n } from "@lingui/core"
import otaClient from "@crowdin/ota-client"
export const locales = {
en: "English",
cs: "Česky",
}
export const defaultLocale = "en"
export async function dynamicActivate(locale: string) {
const client = new otaClient('<distribution-hash>')
const messages = await client.getStringsByLocale(locale)
i18n.load(locale, messages)
i18n.activate(locale)
}
tip
Over-The-Air Content Delivery with Lingui requires compilation of the catalogs on the client side.
If you are using the po
format, you can avoid this compilation step by using the Lingui String Exporter.