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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: lingui import of t
Brad Barbindec4d62f5667
diff --git a/apps/erp/app/routes/x+/settings+/company.tsx b/apps/erp/app/routes/x+/settings+/company.tsxindex 88fa37e526..7943fb91c9 100644--- a/apps/erp/app/routes/x+/settings+/company.tsx+++ b/apps/erp/app/routes/x+/settings+/company.tsx@@ -17,8 +17,8 @@ import {TooltipTrigger,VStack} from "@carbon/react";-import { msg, t } from "@lingui/core/macro";-import { Trans } from "@lingui/react/macro";+import { msg } from "@lingui/core/macro";+import { Trans, useLingui } from "@lingui/react/macro";import { LuKeySquare } from "react-icons/lu";import type { ActionFunctionArgs } from "react-router";import { data } from "react-router";@@ -65,6 +65,7 @@ export async function action({ request }: ActionFunctionArgs) {}export default function Company() {+ const { t } = useLingui();const routeData = useRouteData<{ company: CompanyType }>(path.to.authenticatedRoot);diff --git a/llm/cache/i18n-lingui-system.md b/llm/cache/i18n-lingui-system.mdnew file mode 100644index 0000000000..3b94f82293--- /dev/null+++ b/llm/cache/i18n-lingui-system.md@@ -0,0 +1,23 @@+# i18n / Lingui System++## Architecture++- Lingui v5 with macros. Config at root `lingui.config.js`: locales en (source), es, de, it, ja, zh, fr, pl, pt, ru, hi; PO format; catalogs at `packages/locale/locales/{locale}/{erp,mes}` extracted from `apps/{erp,mes}/app`, `packages/react/src`, `packages/form/src` (excludes `*.server.*`, tests). PO origin refs/creation dates are stripped post-extract by `scripts/strip-po-headers.mjs` to reduce diff churn.+- **No `runtimeConfigModule`** is configured, so `t` from `@lingui/core/macro` compiles to `i18n._()` on the **global** singleton from `@lingui/core`.+- The global i18n singleton is **never activated** — there is no `i18n.activate()` call anywhere except inside `LocaleProvider`.+- `packages/locale/src/i18n.tsx` — `LocaleProvider` creates its own runtime per render via `setupI18n()`, loads the catalog, activates it, and provides it through `<I18nProvider>` (React context). This is the only working i18n instance.+- Server side: `apps/erp/app/services/lingui.server.ts` `loadLinguiCatalogForRequest()` lazily imports the compiled `erp.mjs` catalog for the resolved locale (via `import.meta.glob`); the root loader passes the catalog to `LocaleProvider`. It loads messages only — it does not (and must not) activate the global singleton.++## Critical pitfall (caused production SSR crashes)++Using the `t` backtick macro imported from `@lingui/core/macro` in render code throws+`"Lingui: Attempted to call a translation function without setting a locale"` during SSR+(and on the client), because it hits the never-activated global singleton.++**Correct patterns:**+- In components: `import { useLingui } from "@lingui/react/macro"; const { t } = useLingui();` then `t\`...\`` — context-bound, identical message IDs/extraction.+- `<Trans>` from `@lingui/react/macro` — context-bound, safe.+- Route `handle.breadcrumb: msg\`...\`` with `msg` from `@lingui/core/macro` — safe; `msg` only creates a MessageDescriptor (no i18n call). `Breadcrumb.tsx` resolves descriptors via the context `t`.+- If `t` is used inside `useMemo`/`useCallback`, include `t` in the dependency array (see `assignments.tsx` columns memo).++So: `msg` from core/macro is fine; **never import `t` from `@lingui/core/macro`** in app code.diff --git a/llm/tasks/todo.md b/llm/tasks/todo.mdindex 114056b890..00ca71b79c 100644--- a/llm/tasks/todo.md+++ b/llm/tasks/todo.md@@ -1,37 +1,40 @@-# Fix ERP CSV export to respect the current saved view+# Fix Lingui SSR crash ("Attempted to call a translation function without setting a locale")++## Root cause++19 ERP route files use the `t` macro from `@lingui/core/macro` at render time. That macro+compiles to `i18n._()` on the **global** i18n singleton from `@lingui/core`, which is never+activated anywhere (server or client) — only `LocaleProvider`'s context-scoped instance+(`packages/locale/src/i18n.tsx`) is activated. SSR on Vercel crashes when rendering any of+these routes (user hit it on /x/settings/company). `msg` descriptors in `handle` exports and+`<Trans>` components are unaffected (descriptor-only / context-bound).++## Fix++Replace render-time global `t` with the context-bound `t` from `useLingui()`+(`@lingui/react/macro`) — the pattern already used by ~dozens of components+(e.g. apps/erp/app/components/Breadcrumb.tsx).## Tasks-- [x] Update `Download.tsx`: extend props (columnAccessors, columnOrder, columnVisibility),- call store hooks in body, derive ordered+visible export columns, build label-keyed- rows with id→name substitution. Spawn subtasks to query the cache folder any time I- need to learn something about the codebase. NEVER update the cache with plans or- information about code that is not yet committed.-- [x] Update `TableHeader.tsx` line 335: pass the three props through to `<Download />`.- Spawn subtasks to query the cache folder any time I need to learn something about the- codebase. NEVER update the cache with plans or information about code that is not yet- committed.-- [x] Typecheck. Spawn subtasks to query the cache folder any time I need to learn something- about the codebase. NEVER update the cache with plans or information about code that is- not yet committed.-- [ ] Commit and push. Spawn subtasks to query the cache folder any time I need to learn- something about the codebase. NEVER update the cache with plans or information about- code that is not yet committed.+- [x] Convert batch 1: settings/company, settings/billing, settings/labels, settings/production, settings/quality (Spawn subtasks to query the cache folder any time I need to learn something about the codebase. NEVER update the cache with plans or information about code that is not yet committed.)+- [x] Convert batch 2: settings/sales, settings/purchasing, settings/inventory, settings/resources, quality/_index (same cache rule)+- [x] Convert batch 3: tool/$itemId, part/$itemId, issue/$id, traceability/_index, users/operators (same cache rule)+- [x] Convert batch 4: schedule/dates, schedule/operations, resources/assignments, resources/assignments.$trainingId (same cache rule)+- [x] Verify: no remaining render-time `t` from @lingui/core/macro in apps; spot-check diffs (same cache rule)## Review-- `Download.tsx`: added `columnAccessors` / `columnOrder` / `columnVisibility` props;- call `useItems/useSuppliers/usePeople/useCustomers` in the body to build id→name- Maps (memoized); derive the ordered, visible export columns (column id == accessor- key; synthetic columns dropped since they're absent from `columnAccessors`); the- click handler builds label-keyed rows so json2csv emits the view's labels in order,- substituting names for `itemId`/`supplierId`/`employeeId`/`customerId` with raw-value- fallback.-- `TableHeader.tsx`: passed the three already-available props to `<Download />`. No- change to `Table.tsx` or any interface.-- Types confirmed by inspection (`ListItem` has `id: string; name: string`; `~/stores`- import is an established pattern; `[email protected]` supports `emptyFieldValue`).- The full `tsgo` typecheck could NOT be run here — this environment has no installed- `node_modules`.-- Browser verification (custom view in Inventory) still needs to be run against a- running dev server, which isn't available in this container.+- The initial grep was over-broad: it flagged 19 files, but 18 of them already used the+ context-bound `const { t } = useLingui()` pattern (converted in an earlier migration) and+ only imported `msg` from core/macro. **Only `settings+/company.tsx` still imported `t`+ from `@lingui/core/macro`** — the one route the user reported.+- Fix applied (single file, apps/erp/app/routes/x+/settings+/company.tsx): import `msg`+ only from `@lingui/core/macro`, add `useLingui` to the `@lingui/react/macro` import, and+ add `const { t } = useLingui();` at the top of the `Company` component (its one `t` usage+ is the copy-button aria-label).+- Verified by grep: no file in `apps/` or `packages/` imports `t` from+ `@lingui/core/macro` anymore.+- Not run here: production SSR repro (needs a deploy/build); the failure mode is fully+ explained by the stack trace (`I18n._` on the never-activated global singleton during+ react-dom-server render).