Skip to content

refactor(i18n): migrate POS components and web-print to use-intl - #400

Merged
khaira777 merged 1 commit into
mainfrom
chore/377-i18n-pos-migration-5b
Aug 19, 2026
Merged

khaira777 merged 1 commit into
mainfrom
chore/377-i18n-pos-migration-5b

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Migrate the POS page, its 14 components, and the web-print helper from the legacy useI18n()/t() flat-key API to use-intl useTranslations()/createTranslator, completing Phase 3 batch 5B (issue #377) of the i18n migration epic (#372).

Scope is exactly 16 files: pos/page.tsx plus the 14 POS components (AddonModal, CartPanel, CustomerSearch, DietaryBadge, EditCustomerModal, PaymentModal, PosTopbar, PrepaidCheckoutModal, PrinterStatus, ProductGrid, SplitCheckModal, TableCheckoutModal, TablePickerModal, TaxBreakdown) and lib/printer/web-print.ts.

Key decisions: React components use useTranslations(namespace) with typed leaf keys; multi-namespace files split into t / tCommon / tSupport / tOrders / tWhatsappSend as needed. DietaryBadge uses a typed KnownDietaryTag plus DIETARY_TAG_KEYS map for known tags while custom tags render the canonical name directly, and its existing tagLabel() helper must keep returning dotted keys because the unmigrated products page (batch 5E) still consumes it. PrepaidCheckoutModal uses a typed OrderType plus ORDER_TYPE_SUFFIX_KEYS map to replace the pos.orderTypeSuffix template-literal cast. Payment-method labels: PAYMENT_METHODS.labelKey stays dotted (dashboard batch 5C still consumes it), so both payment modals use a local typed BUILT_IN_PAYMENT_KEYS map. PaymentModal sendBillViaFlo is shared with the unmigrated orders page and still takes a dotted-key callback, bridged with a typed whatsapp.send adapter rather than reintroducing legacy t(). web-print.ts (non-React) uses createTranslator from use-intl/core with cached messages, keeping generateBillHtml/printWebBill synchronous so the receipt-printing and browser-receipts tests stay intact.

Constraints: no wording, logic, or behavior changes beyond the mechanical i18n API migration; no new dependencies, migrations, or schema changes; the legacy useI18n bridge must remain for other unmigrated batches (its removal is owned by #381); PaymentModal recently gained a dynamic currency-unit adapter (#387) whose behavior must be preserved.

What Changed

  • Migrated the POS page and 14 POS components from the legacy useI18n flat-key API to useTranslations with scoped namespace lookups.
  • Added typed leaf-key maps for dynamic translation keys (DIETARY_TAG_KEYS, ORDER_TYPE_SUFFIX_KEYS, and BUILT_IN_PAYMENT_KEYS) while preserving compatibility interfaces for unmigrated modules.
  • Converted web-print.ts to createTranslator from use-intl/core backed by cached locale messages for synchronous receipt label translation.

Risk Assessment

✅ Low: The mechanical migration of POS components and web-print to use-intl is clean, type-safe, preserves backward-compatibility bridges, and introduces no regressions or missing translation keys.

Testing

Validated Phase 3 Batch 5B i18n migration across all 16 scoped files: translation integrity checks confirmed 100% key and ICU parity without untranslated leaves; Next.js frontend export compiled successfully; browser web receipt generation verified synchronous translations in EN, ES, PT, and Persian RTL; Playwright e2e validated rendered POS UI in both English LTR and Persian RTL; and currency/payment split test suites passed with zero failures. Captured rendered UI screenshots and receipt HTML/PNG evidence in the designated evidence directory.

  • Evidence: POS Screen English LTR UI (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/pos-ltr-en.png)
  • Evidence: POS Screen Persian RTL UI (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/pos-rtl-fa.png)
  • Evidence: Persian RTL Web Receipt (Rial & Persian Digits) (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/01_persian_receipt_rial_persian_digits.png)
Evidence: Persian RTL Web Receipt HTML (Rial)
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
  <meta charset="utf-8">
  <title>رسید # BILL-IR-0089</title>
  <style>
    
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body { font-family: -apple-system, 'Segoe UI', Tahoma, 'Noto Naskh Arabic', 'Helvetica Neue', Arial, sans-serif; font-size: 12px; line-height: 1.4; color: #333; }
    .bill-container { max-width: 100%; margin: 0 auto; }
    .reprint-banner { text-align: center; font-size: 22px; font-weight: bold; letter-spacing: 2px; color: #c00; border: 3px solid #c00; padding: 6px; margin-bottom: 15px; }
    .header { text-align: center; margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid #ccc; }
    .header h1 { font-size: 24px; margin-bottom: 5px; }
    .bill-details { margin-bottom: 15px; }
    .bill-details table { width: 100%; }
    .items-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
    .items-table th, .items-table td { padding: 8px; border-bottom: 1px solid #eee; text-align: start; }
    .items-table th { background: #f5f5f5; font-weight: bold; }
    .tax-table, .payments-table { width: 50%; margin-inline-start: 50%; border-collapse: collapse; margin-bottom: 15px; }
    .tax-table th, .tax-table td, .payments-table th, .payments-table td { padding: 6px 8px; }
    .tax-table th, .payments-table th { background: #f9f9f9; text-align: start; }
    .totals-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
    .totals-table td { padding: 6px 8px; }
    .total-row { border-top: 2px solid #333; font-size: 16px; }
    .footer { text-align: center; margin-top: 30px; padding-top: 15px; border-top: 1px solid #ccc; }
    .powered-by { font-size: 10px; margin-top: 8px; color: #555; }
    .text-end { text-align: end !important; }
    .num { unicode-bidi: isolate; white-space: nowrap; }
    .ltr { direction: ltr; unicode-bidi: isolate; }
    .text-muted { color: #666; }
    .text-italic { font-style: italic; color: #888; }
  
        .bill-container { padding: 10px; max-width: 80mm; font-size: 11px; }
        .header h1 { font-size: 16px; }
      
    @media print {
      .no-print { display: none !important; }
      body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    }
  </style>
</head>
<body>
  <div class="bill-container">
    
    <!-- Header -->
    <div class="header">
      <h1>کافه کتاب تهران (Tehran Book Cafe)</h1>
      <p>تهران، خیابان انقلاب، پلاک ۱۲</p>
      <p>تلفن: <span class="ltr" dir="ltr">+98 21 6644 1234</span></p>
      <p>کد اقتصادی: <span class="ltr" dir="ltr">411123456789</span></p>
    </div>

    <!-- Bill Details -->
    <div class="bill-details">
      <table>
        <tr>
          <td><strong>رسید #</strong> <span class="ltr" dir="ltr">BILL-IR-0089</span></td>
          <td class="text-end"><strong>تاریخ</strong> ۲۶ مرداد ۱۴۰۵، ۱۸:۰۰</td>
        </tr>
        <tr><td><strong>میز</strong> میز ۱۲ (Table 12)</td><td></td></tr>
        <tr><td><strong>مشتری</strong> رضا حسینی (Reza Hosseini)</td><td></td></tr>
        <tr><td><strong>شماره مشتری</strong> <span class="ltr" dir="ltr">+98 912 345 6789</span></td><td></td></tr>
      </table>
    </div>

    <!-- Items Table -->
    <table class="items-table">
      <thead>
        <tr>
          <th>اقلام</th>
          <th class="text-end">تعداد</th>
          <th class="text-end">نرخ</th>
          <th class="text-end">مبلغ</th>
        </tr>
      </thead>
      <tbody>
        
          <tr>
            <td>
              چای زعفرانی (Saffron Tea)
              <br><small class="text-muted">+ هل اضافه</small>
              <br><small class="text-italic">کم شیرین</small>
            </td>
            <td class="text-end num">۲</td>
            <td class="text-end num">‎ریال ۳۰۰٬۰۰۰</td>
            <td class="text-end num">‎ریال ۶۶۰٬۰۰۰</td>
          </tr>
        
          <tr>
            <td>
              باقلوا یزدی (Baklava)
              
              
            </td>
            <td class="text-end num">۱</td>
            <td class="text-end num">‎ریال ۳۰۰٬۰۰۰</td>
            <td class="text-end num">‎ریال ۳۳۰٬۰۰۰</td>
          </tr>
        
      </tbody>
    </table>

    <!-- Tax Breakdown -->
    
    <table class="tax-table">
      <thead>
        <tr><th colspan="2">جزئیات مالیات</th></tr>
      </thead>
      <tbody>
        
          <tr><td>ارزش افزوده (VAT) @10%</td><td class="text-end num">‎ریال ۹۰٬۰۰۰</td></tr>
        
      </tbody>
    </table>
    

    <!-- Totals -->
    <table class="totals-table">
      <tr><td>جمع جزء</td><td class="text-end num">‎ریال ۹۰۰٬۰۰۰</td></tr>
      
      <tr><td>مالیات کل</td><td class="text-end num">‎ریال ۹۰٬۰۰۰</td></tr>
      
      
      <tr class="total-row"><td><strong>جمع کل</strong></td><td class="text-end num"><strong>‎ریال ۹۹۰٬۰۰۰</strong></td></tr>
    </table>

    <!-- Payments -->
    
    <table class="payments-table">
      <thead>
        <tr><th colspan="2">پرداخت‌ها</th></tr>
      </thead>
      <tbody>
        
          <tr><td>کارت</td><td class="text-end num">‎ریال ۹۹۰٬۰۰۰</td></tr>
        
      </tbody>
    </table>
    

    <!-- Footer -->
    <div class="footer">
      <p>از بازدید شما سپاسگزاریم!</p>
      <p>مالیات در صورت اعمال، شامل شده است</p>
      <p class="powered-by">Powered by FloPOS<br>https://flopos.com</p>
    </div>
  </div>

  <div class="no-print" style="text-align:center;margin-top:20px;">
    <button onclick="window.print()" style="padding:10px 20px;font-size:16px;cursor:pointer;">چاپ رسید</button>
  </div>
</body>
</html>
  
- Evidence: Persian RTL Web Receipt (Toman & Persian Digits) (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/02_persian_receipt_toman_persian_digits.png) - Evidence: Persian RTL Web Receipt (Toman Short & Latin Digits) (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/03_persian_receipt_toman_short_latin_digits.png) - Evidence: English Baseline Web Receipt (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/05_english_receipt_baseline.png) - Evidence: Spanish Reprint Web Receipt (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/06_spanish_receipt_reprint.png) - Evidence: Portuguese Brazil Web Receipt (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS/07_portuguese_receipt_brazil.png)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • npm run test:translations
  • npm run test:locale-chunks
  • npm run test:rtl-dashboard-pos-common
  • npm run test:receipt-printing
  • npm run test:bills-print-api
  • npm run test:currency
  • npm run test:payment-methods-split
  • npm run build:frontend
  • npm run build
  • npx ts-node --transpile-only -P tests/tsconfig.json tests/browser-receipts.test.ts
  • cd frontend && EVIDENCE_DIR=/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0D3DF5HBETVQHFX32CEADPS npx playwright test e2e/rtl-dashboard-pos-common.spec.ts
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Phase 3 batch 5B (issue #377). Replace the legacy useI18n()/t() flat-key API with useTranslations()/createTranslator across the POS page, its 14 components, and the web-print helper. Typed leaf-key maps handle the two dynamic-key cases (dietary tags, order-type suffixes); payment-method labels use a local BUILT_IN_PAYMENT_KEYS map while PAYMENT_METHODS.labelKey stays dotted for the unmigrated dashboard; web-print keeps its synchronous API via createTranslator with cached messages. No wording, logic, or behavior changes; the legacy bridge remains for later batches.
@khaira777
khaira777 merged commit 9313b81 into main Aug 19, 2026
12 checks passed
@khaira777
khaira777 deleted the chore/377-i18n-pos-migration-5b branch August 19, 2026 13:41
@khaira777 khaira777 self-assigned this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant