Skip to content

feat(printing): add localized label support to compliance print templates #445

Closed

Description

@khaira777

Refs: #438
Depends on: #440
Can parallel with: D, E, F
Related: #372

Context

Country-pack compliance templates render through renderEscposLineTemplateV1 (main/printers/thermal.ts) using the escpos-line-template-v1 payload contract: width profiles, column definitions, header/totals/footer selectors, and author-supplied strings (taxRegistrationNumberLabel, grandTotalLabel, footer messages). Built-in fallbacks inside that renderer are hardcoded English; after #440, the resolver exists to localize them.

This issue adds safe, additive localization compatibility to the existing compliance renderer. It does NOT redesign the schema and does NOT make it FloCafe's future merchant/community template format — that is explicitly the semantic merchant model's role (#447). escpos-line-template-v1 remains a legacy/compliance-oriented contract.

Architectural Decisions Relevant to This Issue

  • Signed-pack trust chain is untouched: installed_print_templates rows remain denormalized children of Ed25519-verified country_pack_versions; install/activate/rollback/revocation flows unchanged.
  • Additive optional fields only → renderer version stays 1; existing payloads keep rendering byte-compatibly (unknown-field tolerance at render time is existing behavior).
  • Pack authors supply their own literal strings where they want custom copy; built-in fallbacks become localized via B's resolver using the receipt-language context already available at print time.
  • Any new public-facing identifiers use stable semantic names, never internal i18n keys (epic principle: internal keys are not public API).

Scope / What to do

  1. Extend the payload contract (documented + validated additively): optional labels?: { <semanticId>: string } map on the payload root, semantic ids drawn from a documented enumerated set mirroring B's catalog concepts (e.g., total, subtotal, invoice, taxIncluded, footerThanks). Size-cap the map (e.g., ≤ 64 entries, each ≤ 120 chars) in the install-time validator (validPluginPrintTemplate path) with clear rejection errors.
  2. Localize built-in fallbacks: title selection (TAX INVOICE/INVOICE), subtotal/discount/TOTAL labels, tax-included/footer defaults resolve through B's catalog using receipt language; author-supplied payload strings and labels overrides always win.
  3. Update the install-time validator + tests/tax-pack-management.test.ts fixtures for the optional field; verify older fixtures still pass unchanged.
  4. Document version behavior: same renderer version 1, additive optional field, fail-closed on structural misuse (non-object/oversized).

Compatibility / Migration

  • Old packs: zero change required; renders identically.
  • New packs may ship localized labels immediately.
  • No DB migration; no API route changes.

What NOT to do

  • Do NOT bump the renderer version or introduce a v2.
  • Do NOT expose internal i18n key names in the payload contract.
  • Do NOT migrate this renderer onto PrintDocument here (that remains a later, separate decision after I/J establish the merchant ecosystem).
  • Do NOT alter signature verification, activation, rollback, or revocation logic.
  • Do NOT turn this contract into the merchant template format.

Acceptance Criteria

  • Optional validated labels map supported end-to-end (install validation → render override).
  • Built-in fallback labels localized via canonical i18n when pack supplies none; EN output byte-equivalent to pre-change for default language.
  • Existing pack test fixtures render unchanged; new fixture covers localized overrides + size-limit rejection.
  • Documentation states explicitly that escpos-line-template-v1 is legacy/compliance-oriented, not the future merchant API (cross-link feat(printing): add versioned semantic merchant print template model #447).

Verification

npx ts-node --transpile-only -P tests/tsconfig.json tests/tax-pack-management.test.ts
npx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts
npm run build && npm run lint && npm run i18n:check

Documentation

Payload field table added to docs/tax-packs.md (or printers doc) including stability semantics of semantic ids.

Metadata

Metadata

Assignees

Labels

area:backendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions