Repository navigation
Description
Refs: #372
Depends on: #375
Can parallel with: #376, #378, #379, #380
Context
Migrate all Point of Sale (POS) UI components, modals, cart panels, and browser receipt printing from legacy useI18n() to useTranslations() from use-intl.
Global Component Migration Rules
- Use
const t = useTranslations('namespace')fromuse-intlin React components. - In non-React contexts (e.g.
web-print.ts), usecreateTranslatorfromuse-intl/corewith loaded messages from the shared loader, or receive a typed translator from the caller. - Access keys via namespaced identifiers (e.g.
useTranslations('pos')->t('checkout')). - Use compile-time type-safe keys verified against
AppConfig. - Eliminate template-literal dynamic key construction; use exhaustively typed lookup mappings.
- Do NOT remove the compatibility adapter or legacy hook in this PR. Issue refactor(i18n): remove legacy custom i18n implementation #381 owns final removal.
- Do NOT alter translation wording or POS business logic.
Files to Migrate (16 files total)
POS Page & Components (15 files)
frontend/src/app/(dashboard)/pos/page.tsxfrontend/src/components/pos/AddonModal.tsxfrontend/src/components/pos/CartPanel.tsxfrontend/src/components/pos/CustomerSearch.tsxfrontend/src/components/pos/DietaryBadge.tsxfrontend/src/components/pos/EditCustomerModal.tsxfrontend/src/components/pos/PaymentModal.tsxfrontend/src/components/pos/PosTopbar.tsxfrontend/src/components/pos/PrepaidCheckoutModal.tsxfrontend/src/components/pos/PrinterStatus.tsxfrontend/src/components/pos/ProductGrid.tsxfrontend/src/components/pos/SplitCheckModal.tsxfrontend/src/components/pos/TableCheckoutModal.tsxfrontend/src/components/pos/TablePickerModal.tsxfrontend/src/components/pos/TaxBreakdown.tsx
Non-React Browser Receipt Printing (1 file)
frontend/src/lib/printer/web-print.ts
Non-React Translator Pattern for web-print.ts
web-print.ts is a standalone non-React utility that generates HTML for the browser print window. It must not call React hooks or use the legacy t(key, lang) global lookup.
Migrate web-print.ts using the official createTranslator from use-intl/core:
import { createTranslator } from 'use-intl/core';
import { loadLocaleMessages } from '@/lib/i18n/loader';
import { LANGUAGES, type Language } from '@/lib/i18n/languages';
export async function getReceiptTranslator(lang: Language) {
const messages = await loadLocaleMessages(lang);
const locale = LANGUAGES[lang]?.locale ?? 'en';
return createTranslator({ locale, messages });
}Alternatively, pass a typed translator or pre-translated receipt label dictionary directly from the calling React POS component.
Dynamic Key Handling in POS Components
1. DietaryBadge.tsx
Currently calls t(tagLabel(tag)) where tagLabel dynamically returns translation keys or unlocalized fallback strings.
Replace with an exhaustively typed mapping for known tags:
type KnownDietaryTag =
| 'veg'
| 'vegan'
| 'egg'
| 'non_veg'
| 'spicy'
| 'contains_nuts'
| 'gluten_free'
| 'dairy_free'
| 'new_arrival'
| 'bestseller'
| 'organic'
| 'fragrance_free'
| 'limited';
const DIETARY_TAG_KEYS = {
veg: 'tagVeg',
vegan: 'tagVegan',
egg: 'tagEgg',
non_veg: 'tagNonVeg',
spicy: 'tagSpicy',
contains_nuts: 'tagContainsNuts',
gluten_free: 'tagGlutenFree',
dairy_free: 'tagDairyFree',
new_arrival: 'tagNewArrival',
bestseller: 'tagBestseller',
organic: 'tagOrganic',
fragrance_free: 'tagFragranceFree',
limited: 'tagLimited',
} as const satisfies Record<KnownDietaryTag, string>;For known tags, translate via t(DIETARY_TAG_KEYS[canonical]). For unknown/custom tags, render the formatted tag name directly without calling t() with arbitrary runtime strings. Do not invent uncoordinated fallback keys.
2. PrepaidCheckoutModal.tsx
Currently uses a type-asserted template literal:
t(`pos.orderTypeSuffix_${cart.orderType}` as ...)Replace with a typed lookup mapping:
type OrderType = 'dine_in' | 'takeaway' | 'delivery' | 'online';
const ORDER_TYPE_SUFFIX_KEYS = {
dine_in: 'orderTypeSuffix_dine_in',
takeaway: 'orderTypeSuffix_takeaway',
delivery: 'orderTypeSuffix_delivery',
online: 'orderTypeSuffix_online',
} as const satisfies Record<OrderType, string>;What NOT to do
- Do NOT remove
frontend/src/hooks/useI18n.tsor the compatibility bridge infrontend/src/lib/i18n.ts. - Do NOT use React hooks inside
web-print.ts. - Do NOT change any translation content or wording.
- Do NOT alter cart calculation, payment, or order submission logic.
Acceptance Criteria
- All 16 files (1 page, 14 POS components, 1 print helper) migrated to
useTranslations()/createTranslator. -
web-print.tsusescreateTranslatoror passed translator without React hook violations or legacy globalt(). - No unchecked template-literal translation calls remain.
-
DietaryBadge.tsxhandles known and custom tags without unchecked translation calls. - Compatibility bridge remains operational for unmigrated batches.
Verification
npm run lint
npm run build:frontend
npm test
npm run test:rtl-dashboard-pos-common
npm run test:receipt-printing
Activity
refactor(i18n): migrate POS components and web-print to use-intl (#400)
khaira777 commentedon Aug 19, 2026
Migrated and merged via #400.
All 16 in-scope files moved from the legacy
useI18n()/t()flat-key API touseTranslations()/createTranslator:pos/page.tsx, AddonModal, CartPanel, CustomerSearch, DietaryBadge, EditCustomerModal, PaymentModal, PosTopbar, PrepaidCheckoutModal, PrinterStatus, ProductGrid, SplitCheckModal, TableCheckoutModal, TablePickerModal, TaxBreakdown)web-print.ts(non-React):createTranslatorfromuse-intl/corewith cached messages, keepinggenerateBillHtml/printWebBillsynchronousDynamic keys replaced with exhaustively typed lookup mappings:
KnownDietaryTag+DIETARY_TAG_KEYS(custom tags render the canonical name;tagLabel()kept for the still-unmigrated products page in 5E)OrderType+ORDER_TYPE_SUFFIX_KEYSBUILT_IN_PAYMENT_KEYSwhilePAYMENT_METHODS.labelKeystays dotted for the dashboard batch (5C)sendBillViaFlo: typedwhatsapp.sendadapter (shared with the unmigrated orders page)No wording, logic, or behavior changes; no new dependencies or migrations. The legacy compatibility bridge remains in place for later batches (#381 owns final removal).
Verification: lint, frontend typecheck, static export build, and the translations / rtl-dashboard-pos-common / locale-chunks / receipt-printing / browser-receipts suites all green.