Internationalization (i18n)¶
Atlas ERP is designed to be used globally. To support multiple languages seamlessly, we use LinguiJS. Lingui is highly optimized for React applications and uses minimal overhead.
Setup & Configuration¶
The configuration for Lingui is found in lingui.config.js at the root of apps/web.
| JavaScript | |
|---|---|
How to Translate Strings¶
1. Using the <Trans> Component¶
The most common way to translate text inside JSX is by wrapping it in the <Trans> component. Lingui will automatically extract the string as an ID during the extraction phase.
| TSX | |
|---|---|
2. Using the t Macro for Variables¶
When you need a translated string as a variable (e.g., for an input placeholder or a toast message), use the t macro.
| TSX | |
|---|---|
Extracting and Compiling Translations¶
When you add new <Trans> or t strings to your code, you must run the extraction script so they appear in the .po message catalogs.
| Bash | |
|---|---|
The compiled JavaScript files are then loaded by the Next.js application at runtime depending on the user's selected locale.
Best Practices¶
- Avoid manual IDs: Write natural English text inside
<Trans>. Lingui uses the English text as the ID by default. - Context: If a word has multiple meanings in English (e.g., "Right" as a direction vs. "Right" as a permission), provide context using the
messageandidprops or comments so translators know which to use. - Plurals: Lingui supports complex pluralization rules via ICU message format.