Repository navigation
Description
Refs: #438
Depends on: #439 (parity harness)
Can parallel with: C (kernel) after A merges
Related: #372, #377, #382, #196
Context
Backend thermal renderers (main/printers/thermal.ts) hardcode ~45 English strings ("Subtotal", "TOTAL", "Invoice #", "KITCHEN ORDER TICKET", payment names, points labels, test-page text), and frontend ESC-POS encoders add ~30 more. Only web-print.ts resolves labels through canonical i18n. An audit identified 58 translatable concepts: 19 reusable existing keys, 9 reuse-with-rename, 30 new keys — the mapping table is embedded below and is part of this issue's contract.
FloCafe's Electron main process cannot import the frontend i18n loaders, but locale JSON files must remain the only translation source (epic principle). The chosen mechanism is a generated derived view: a build script extracts the needed label subtree from canonical messages into a committed TypeScript module under main/print/, with CI drift validation. Ordinary builds consume it; they never regenerate tracked files silently (epic principle on build determinism).
Architectural Decisions Relevant to This Issue
- Locale JSONs are the single translation source; the generated file is explicitly a derived view, regenerated only via an explicit npm command and verified by CI.
- Languages are never hardcoded as unions in print code: the generated dictionary is keyed by language code strings validated against the generated key set; typing tightens when the shared kernel (refactor(printing): add shared print kernel, language policy, and receipt language settings #441) lands.
- Test-page policy (decided): human-facing test-page sentences are translated like any other print surface; technical literals stay verbatim — protocol names (
ESC/POS), encodings/codepages (UTF-8,CP1256), raw byte/hex output, IP/port values, printer model identifiers, capability IDs. - Branding constants (
Powered by FloPOS, URL) are never translated. - Currency symbol ASCII fallback and Persian-digit suppression remain formatting concerns (existing helpers), not translations.
- Payment-method labels: port
web-print.ts'spos.methodCash/methodCard/methodWalletmapping into backend resolution; unknown methods keep current capitalize-fallback. - KOT order types resolve via existing
orders.dineIn/takeaway/deliveryfamily instead of uppercasing raw enums.
Scope / What to do
- Add the
print.*message namespace to all four committed locale files (en,fa,es,pt) for genuinely-new concepts (~30 keys): invoice/bill title variants, time, short customer/number prefixes, address/call/note prefixes, TOTAL casing, thank-you variants, points earned/balance/redeemed, KOT title/banner/station/type/no-pending/end, HSN, subtotal-excl-tax, rates-inclusive note, human-facing test-page lines. Reuse existing keys for the other concepts by listing them in the generator's borrowed-keys manifest rather than duplicating them. - Generator
scripts/generate-print-labels.cjs: reads canonical messages, extractsprint.*+ borrowed keys per language, emits committedmain/print/print-labels.generated.tsexporting a typed record plus a resolverprintLabel(lang, conceptId)with safe English fallback. Include a header "GENERATED FILE — edit messages, then runnpm run generate:print-labels". - npm wiring:
generate:print-labelsscript; extend thei18n:checkpipeline with a drift step (regenerate in temp, diff against committed file, fail on drift).npm run buildconsumes the committed file without rewriting it. - Thread an optional
language?: stringparameter throughprepareReceipt,formatReceipt,formatClassicReceipt,formatCompactReceipt,formatKOT,buildTestPage(default'en'). Routes (main/routes/printers.ts) pass the tenant's existinglanguagesetting where available so backend prints become localized immediately without new settings UI (full policy arrives with refactor(printing): add shared print kernel, language policy, and receipt language settings #441). - Replace every audited hardcoded occurrence in
thermal.ts(classic, compact, KOT, plugin built-in fallbacks such as TAX INVOICE/TOTAL/footer defaults, test page human-facing lines) with resolver calls. Keep author-supplied plugin payload fields (e.g.,totals.grandTotalLabel) authoritative over defaults.
Audit mapping (contract — implement exactly this split)
| Concept | Existing key to reuse |
|---|---|
| Bill#/Date/Table/Customer/CustomerNo/Ph | receipt.billNumber, receipt.date, pos.tableLabel, pos.customer, receipt.customerNo, receipt.phone |
| Item/Qty/Rate/Amount/Amt | receipt.item, receipt.qty, receipt.rate, receipt.amount, printTest.amt |
| Subtotal/Discount/Tax/Delivery | pos.subtotal, pos.discount, pos.tax, pos.delivery |
| Total Tax / Service Charge / Tax Details / Payments | receipt.totalTax, receipt.serviceCharge, receipt.taxDetails, receipt.payments |
| Thank you (long) / tax included | receipt.thankYou, receipt.taxIncluded |
| REPRINT | receipt.reprint (render adds \*\* … \*\*) |
New print.* keys (complete list this issue owns): taxInvoiceTitle, invoiceTitle, invoiceNumber, time, customerShort, numberShort, address, call, note, phoneLong, subtotalExclTax, serviceChargeShort, grandTotal, thankYouShort, thankYouVisitAgain, pleaseComeAgain, ratesInclusiveNote, pointsEarned, pointsBalance, pointsRedeemed, kot.title, kot.banner, kot.station, kot.type, kot.noPendingItems, kot.end, hsn, test.title, test.networkUsb, test.columns, test.wrapHint, test.success.
Compatibility / Migration
- Generated file is additive; no persisted settings change; API request/response shapes unchanged except optional
languageinput. - English output must be semantically identical (parity harness from #A stays green); minor whitespace normalization at call sites is allowed where the audit flagged drift (e.g.,
Bill #123vsBill #: 123).
What NOT to do
- Do NOT create a second translation catalog or copy translations by hand into the generated file.
- Do NOT make
npm run buildregenerate tracked sources (constraint: builds never dirty the repo). - Do NOT translate branding, currency symbols, or technical test-page literals.
- Do NOT change
escpos-line-template-v1's payload schema (that is feat(printing): add localized label support to compliance print templates #445). - Do NOT touch frontend encoders or
web-print.tsrendering behavior (refactor(printing): add shared print kernel, language policy, and receipt language settings #441/refactor(printing): migrate browser and WebUSB printing to semantic print model #444 territory) beyond importing nothing new there. - Do NOT introduce bilingual/direction logic here.
Acceptance Criteria
- All 58 audited concepts resolve via
printLabel; zero user-visible hardcoded English remains in migrated backend paths except documented exemptions (branding, technical literals). -
main/print/print-labels.generated.tscommitted; regeneration produces byte-identical output (idempotency test). - Drift check fails CI when messages and generated view diverge; ordinary
npm run buildleaves git status clean. - Backend receipt/KOT/test-page honor tenant
languagesetting for label selection with English fallback. - Payment methods localize via existing method keys with capitalize fallback; KOT order type uses translated order-type keys.
- Parity harness (#A) green in English across widths 32/42/48; new tests assert fa/es label selection unit-level.
Verification
npm run generate:print-labels && git status --short # clean after regen
npm run i18n:check
npx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts
npx ts-node --transpile-only -P tests/tsconfig.json tests/print-parity.test.ts
npx ts-node --transpile-only -P tests/tsconfig.json tests/bills-print-api.test.ts
npm run buildDocumentation
Document the derived-view rule (edit messages → run generator → commit) in docs/i18n.md or a new docs/printing-labels.md section; full architecture docs belong to #449.
Activity
feat(printing): localized labels for escpos-line-template-v1 complian…
chore: update pull request (FreeOpenSourcePOS#453)
docs(printing): document multilingual print architecture and template…
docs(printing): document multilingual print architecture and template…
docs: document multilingual print architecture and contribution workf…