Translating Your App (i18n)
App localization is zero-config end to end: write UI strings with Lingui macros, extract them into .po catalogs, and the compiled translations ship with the bundle and load at runtime for the Crowdin user’s locale.
Writing and extracting strings
Section titled “Writing and extracting strings”Write strings with Lingui macros and wrap the app in AppI18nProvider:
import { AppI18nProvider } from "@crowdin/serverless-apps-sdk/i18n";import { Trans } from "@lingui/react/macro";
function Root() { return ( <AppI18nProvider fallback={<p>Loading…</p>}> <Trans>Hello from my app!</Trans> </AppI18nProvider> );}Then run the CLI:
crowdin-serverless-apps extractcrowdin-serverless-apps buildextractcollects the strings intolocales/<locale>.pocatalogs - translate those (in Crowdin, naturally);buildanddevcompile the catalogs todist/locales/<locale>.json, which ship inside the bundle as runtime assets.
Runtime behavior
Section titled “Runtime behavior”At runtime, AppI18nProvider detects the Crowdin user’s locale from the host context and loads the matching catalog from the bundle. If no catalog exists for the user’s locale, the source locale is used (default en-US, configurable via the sourceLocale prop).
Catalog naming
Section titled “Catalog naming”Name catalogs after full Crowdin locale codes (uk-UA.po, pt-BR.po) - the CLI warns about names Crowdin will never request (such as uk.po), and the runtime never falls back to base languages.
The Crowdin UI ships in a fixed set of locales, so these are the only catalogs the host will ever request:
en-US, ar-SA, be-BY, cs-CZ, da-DK, de-DE, es-ES, fr-FR, hu-HU, it-IT, ja-JP, pl-PL, pt-BR, pt-PT, ru-RU, sk-SK, tr-TR, uk-UA, xh-ZA, zh-CN, zu-ZA
Translating the catalogs in Crowdin
Section titled “Translating the catalogs in Crowdin”The natural loop is to translate the app in a Crowdin project of its own:
- Create a project and upload
locales/en-US.poas the source file. - Set the file’s resulting-file-name pattern to produce full locale codes, e.g.
/locales/%locale%.po- the default two-letter%two_letters_code%would exportuk.po, which the runtime never requests. - Translate, then download the built translations into the app’s
locales/directory. - Re-run
buildandpublish- the new catalogs ship with the bundle.
- The pipeline needs no
lingui.config.ts. If you add one, keep the PO format and thelocales/{locale}catalog layout - see customization. - Catalogs are compiled once when
devstarts; restart the dev server after editing.pofiles.