Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
description: i18n via Lingui — how strings are marked, extracted, compiled, and loaded at runtime in ERP/MES. paths: - "packages/locale/" - "lingui.config.js" - "apps/erp/app/" - "apps/mes/app/**"
i18n / Lingui System
Lingui v6.9.0 (versions in pnpm-workspace.yaml catalog). The macro transform
is the plugin's own native one: lingui({ macroTransform: true }) from
@lingui/vite-plugin in each app's vite.config.ts — no Babel, no
vite-plugin-babel-macros. It only touches files that import a macro.
Every app gets the plugin from carbon() (@carbon/dev/vite), which wraps it in linguiWithoutIdQuery. Lingui
6.9.0 picks its parser from path.basename(id), so a React Router route module
(route.tsx?__react-router-build-client-route) is parsed as plain JS and the build
fails on its first import type. The wrapper hands the transform the id without
its query; delete it once Lingui strips the query itself.
Config & catalogs
- Root
lingui.config.js:sourceLocale: "en", formatpo(the default; v6 removed theformat: "po"string form),fallbackLocales.default: "en". - Locales:
en, es, de, it, ja, zh, fr, pl, pt, ru, hi, tr, ko(13). The runtime list inpackages/locale/src/config.ts(supportedLanguages) matches this set. - Two catalogs, each extracted from app + shared package sources:
packages/locale/locales/{locale}/erp←apps/erp/app,packages/react/src,packages/form/src,packages/printing/src/uipackages/locale/locales/{locale}/mes←apps/mes/app+ the same three shared dirs- Both
exclude**/*.server.*,**/*.test.*,**/*.spec.*.
.pofiles are committed; compiled.mjsare gitignored (.gitignore:packages/locale/locales/**/*.mjs) and produced at build time.
Scripts (root package.json)
lingui:extract→lingui extract --clean(writes/prunes.po).lingui:compile→lingui compile --namespace es(compiles.po→.mjsas ES modules).lingui:check→ extract + compile.lingui:clean→node ./scripts/strip-po-headers.mjs: stripsPOT-Creation-Dateheader and#: path:linenoorigin refs from every.poto kill per-PR diff churn.translate→ extract, thenpnpx linguito translate --llm(LLM fills missing translations; origins must still exist for source context), thenlingui:clean.
Mark → extract → compile → load
- Mark strings with macros (see patterns below).
- Extract (
lingui:extract) scans configured sources → updates{locale}/{erp,mes}.po. - Compile:
@lingui/vite-plugin(wired in both apps'vite.config.ts) compiles a.poimport into a JS module (export const messages) in every Vite environment — SSR and client — so the catalog is a hashed, immutable chunk per locale. Thelingui:compile→.mjsstep is no longer read by the apps; it stays only as the turbo build input that invalidates the build cache when a.pochanges. Catalog paths inlingui.config.jsuse<rootDir>/…because the plugin resolves them against the config dir while Vite runs fromapps/<app>— a bare relative path fails with "not matched to any of your catalogs paths". - Load:
apps/{erp,mes}/app/services/lingui.ts(isomorphic, one per app because the glob names the app's catalog) —import.meta.glob("…/*/{erp,mes}.po", { import: "messages" })behind a module-levelMap.preloadCatalog(locale)fills it;getCatalog(locale)reads it ({}if missing);useCatalog(locale)reads and, on a cache miss, preloads then re-renders — that is the live language switch (/api/locale→ root revalidates with the new cookie → the new chunk is fetched).- Server: the root loader awaits
preloadCatalog(appLanguage)so SSR is translated, and returns NOTHING about the catalog. It used to return the whole catalog as loader data — ~465 KB raw in every HTML and in every.dataresponse, which single-fetch serves uncompressed (text/x-script), and the root loader re-ran on every action and search-param change.root.tsxnow also has ashouldRevalidatethat skips same-pathname GETs (isSearchParamOnlyNavigation); actions still revalidate because root carries the flashresult. - Client:
entry.client.tsxawaitspreloadCatalog(document.documentElement.lang)BEFOREhydrateRoot— otherwise a non-enpage hydrates against an empty catalog and mismatches the server markup.<html lang>is the resolved language, set by root.
- Server: the root loader awaits
- Provide:
root.tsxrenders<LocaleProvider locale={appLanguage} catalog={useCatalog(appLanguage)}>from@carbon/locale.LocaleProvider(packages/locale/src/i18n.tsx) builds a per-render runtime withsetupI18n(),runtime.load(language, catalog),runtime.activate(language), and wraps children in Lingui's<I18nProvider>. This is the only active i18n instance.
Inside
LocaleProvider,root.tsxalso nests<I18nProvider locale=…>from@react-aria/i18n— unrelated to Lingui (ARIA/locale formatting). Don't conflate them.
Marking strings — correct patterns
- No
runtimeConfigModuleis configured, sotfrom@lingui/core/macrowould compile toi18n._()on the global@lingui/coresingleton, which is never activated (onlyLocaleProvider's per-render runtime is). Calling it throws "Attempted to call a translation function without setting a locale" during SSR/CSR. - Components:
import { useLingui } from "@lingui/react/macro"; const { t } = useLingui();thent`...`— context-bound, same message IDs as extract. (~741 files.) - JSX:
<Trans>from@lingui/react/macro— context-bound, safe. (~557 files.) - Route breadcrumbs:
handle.breadcrumb: msg\...`withmsgfrom@lingui/core/macro—msgonly builds aMessageDescriptor(no i18n call).apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsxresolves descriptors via the context runtime (i18n._(value)`). - If
t(fromuseLingui) is used insideuseMemo/useCallback, addtto the deps (e.g.assignments.tsxcolumns memo, dep[t]). - Never
import { t }from@lingui/core/macroin app code (currently zero such imports — only{ msg }is imported fromcore/macro). - Plurals:
<Plural value={n} one="# day" other="# days" />from@lingui/react/macroin JSX.plural()from@lingui/core/macronested inuseLingui().tis folded into thetmessage only when the component or hook is a function declaration or a plainconst X = () => …. Inside a component passed inline to a call —memo((props) => …), which is most ERP tables — Lingui 6.9.0 expands it into a call on the global@lingui/coreinstance instead, which throws at runtime for the reason above. Extract, typecheck and Biome do not catch it. There, build the string in a function-declaration hook (useReleasedJobsMessageinJobsTable.tsx,useBatchCountMessagesinBatchesTable.tsx) and call the hook from the component. Verify a new one by compiling the file (VitetransformRequest) and checking that no@lingui/coreimport appears.
Adding strings / locales
- String: wrap it with
<Trans>/useLingui().t/msg, then runpnpm lingui:extract(andpnpm translateto LLM-fill other locales). Commit the.pochanges;.mjsis regenerated at build. - Locale: add the code to BOTH
lingui.config.jslocalesANDsupportedLanguagesinpackages/locale/src/config.ts(pluslanguageNativeLabels), then extract/translate.
Gotchas
nl(Dutch).pofiles exist on disk underlocales/nl/butnlis not inlingui.config.jsorsupportedLanguages— it's orphaned; extract won't update it and the runtime can't select it.- Compiled
.mjsare gitignored — a fresh checkout has no catalogs until a build/compile runs; the server loader falls back to{}(English source strings) if missing.