feat(i18n): @xenia/i18n translations, language resolution and venue-time formatting
Platform-v2 step 2.4 (APPS_PLATFORM D-11, D-12, §7.2, §8): - i18next 26.7.2 + react-i18next 17.1.13 (exact); en/el locale files (common, dev); createI18n, I18nProvider, useLanguage, setUserLanguage (screen first, then PATCH /api/auth/me through an app-provided save) - resolveLanguage: user -> device -> venue -> en - useFormat(): dates/times always in the venue zone from bootstrap (24 h, DST-safe, business dates never shifted), relative times, money and numbers per language; parseNumber accepts a comma or a dot - scripts/check-i18n.mjs guard: keys missing in en, placeholder mismatches, dates formatted without the venue zone in new code (fails); missing el (warns) - @xenia/ui components read their texts from UiLabelsProvider; useUiLabels() supplies the translated set - dev-only /i18n-sample in the manager; ui.mjs e2e checks it with the browser in New York; unit tests in run-all; lockfile keeps both apps' versions - new pack rule CS-17 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -17,6 +17,7 @@ npm test # server rediscovery scan
|
||||
|
||||
cd ..
|
||||
npm test -w @xenia/ui # PIN rules + WCAG contrast of every token pair (light/dark × venue themes)
|
||||
npm test -w @xenia/i18n # venue-time formatting (DST), money/numbers, comma-or-dot parsing, language order, check-i18n guard
|
||||
```
|
||||
|
||||
**DB tests** (`local_backend/tests/conftest.py`) run the real FastAPI app against a throwaway SQLite database in a temp folder (never your dev or venue DB). Fixtures: `db` (session, rolled back after each test even if the code commits), `client` (TestClient with `get_db` overridden, license check open, no lifespan), `make_user(role=..., perms=...)` (password `password`, PIN `1234`), `login(user)` (auth headers). A test that uses any of them is marked `db` automatically.
|
||||
@@ -36,7 +37,7 @@ Or run one suite at a time:
|
||||
|---|---|---|---|
|
||||
| `node install.mjs` | `install.sh`: VPN-safe `HOST_IP` detection (simulated WireGuard/WiFi hosts); fresh install, upgrade, re-run; proxy config identical to `nginx-proxy/nginx.conf` | Docker | ~1 min |
|
||||
| `python license_e2e.py` | Offline licensing with a real cloud + site process: 400 days offline, tampered file, clock set back, expiry deferred to workday close, renewal, remote lock | Python deps of both backends | ~2 min |
|
||||
| `node ui.mjs` | `@xenia/ui` components on the dev-only gallery (`/ui-gallery`, manager Vite :5185): dialog focus/Escape/backdrop, sheet, toasts, field wiring, switch, InfoTip, PinPad, themes | Edge | ~30 s |
|
||||
| `node ui.mjs` | `@xenia/ui` components on the dev-only gallery (`/ui-gallery`, manager Vite :5185): dialog focus/Escape/backdrop, sheet, toasts, field wiring, switch, InfoTip, PinPad, themes; `@xenia/i18n` on `/i18n-sample` with the browser in New York: venue time, live language switch, el/en money and numbers, price input, translated component labels | Edge | ~40 s |
|
||||
| `node browser.mjs` | Waiter web modes (same-origin, plain HTTP by LAN IP, venue mode), install dialog + drawer entry (Android / iPhone / desktop / no APK) | Docker, Edge | ~2 min |
|
||||
| `node android.mjs basics` | Pairing, wrong address / other venue's QR, login + live WS, back button, restart, two venues, camera permission | Android emulator | ~5 min |
|
||||
| `node android.mjs rediscovery` | Server IP change (logged in / out), server down + manual search, cold start while offline | Android emulator | ~4 min |
|
||||
|
||||
@@ -9,10 +9,11 @@ const suites = [
|
||||
['unit: local_backend (pytest)', PYTHON, ['-m', 'pytest', 'tests', '-q'], BACKEND],
|
||||
['unit: waiter_pwa (node --test)', 'npm', ['test', '--silent'], WAITER],
|
||||
['unit: packages/ui (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/ui'], CS],
|
||||
['unit: packages/i18n (node --test + guard)', 'npm', ['test', '--silent', '-w', '@xenia/i18n'], CS],
|
||||
['install.sh', 'node', ['install.mjs'], E2E],
|
||||
['license (cloud + site)', PYTHON, ['license_e2e.py'], E2E],
|
||||
['browser', 'node', ['browser.mjs'], E2E],
|
||||
['ui (@xenia/ui gallery)', 'node', ['ui.mjs'], E2E],
|
||||
['ui (@xenia/ui + @xenia/i18n)', 'node', ['ui.mjs'], E2E],
|
||||
]
|
||||
if (!process.argv.includes('--no-android')) suites.push(['android (emulator)', 'node', ['android.mjs'], E2E])
|
||||
|
||||
|
||||
+54
-5
@@ -1,6 +1,9 @@
|
||||
// @xenia/ui suite (Playwright + Edge): the shared components' behaviour on the
|
||||
// gallery page (plan step 2.3). Starts the manager's Vite dev server (:5185), which
|
||||
// serves /ui-gallery in dev builds only. No backend needed.
|
||||
// Shared frontend packages (Playwright + Edge), on their dev-only pages served by the
|
||||
// manager's Vite dev server (:5185). No backend needed.
|
||||
// - @xenia/ui components on /ui-gallery (plan step 2.3)
|
||||
// - @xenia/i18n on /i18n-sample (2.4): live language switch, venue time on a device
|
||||
// in another zone (the browser runs in America/New_York), money/number formats,
|
||||
// comma-or-dot price input, translated component labels
|
||||
// node ui.mjs
|
||||
import { spawn } from 'node:child_process'
|
||||
import { openSync } from 'node:fs'
|
||||
@@ -17,7 +20,8 @@ const vite = spawn('npx', ['vite', '--port', String(PORT), '--strictPort'], {
|
||||
stdio: ['ignore', log, log],
|
||||
})
|
||||
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
||||
const r = reporter('ui: @xenia/ui components (gallery)')
|
||||
let r = reporter('ui: @xenia/ui components (gallery)')
|
||||
let failures = 0
|
||||
|
||||
try {
|
||||
await waitHttp(`http://localhost:${PORT}/`)
|
||||
@@ -122,8 +126,53 @@ try {
|
||||
r.check('theme: leaving the gallery restores <html>', await p.evaluate(() => !document.documentElement.hasAttribute('data-theme') && !document.documentElement.hasAttribute('data-venue-theme')))
|
||||
|
||||
r.check('no page or console errors', errs.length === 0, errs.slice(0, 3).join(' | '))
|
||||
failures += r.done()
|
||||
|
||||
// ── @xenia/i18n ──────────────────────────────────────────────────────────
|
||||
r = reporter('ui: @xenia/i18n (sample, device in New York)')
|
||||
const ctx = await browser.newContext({ timezoneId: 'America/New_York', locale: 'en-US', viewport: { width: 1100, height: 1000 } })
|
||||
const q = await ctx.newPage()
|
||||
const qerrs = []
|
||||
q.on('pageerror', e => qerrs.push('pageerror: ' + e.message))
|
||||
q.on('console', m => { if (m.type() !== 'error' && m.type() !== 'warning') return; if (!/Failed to load resource/i.test(m.text())) qerrs.push(m.text().slice(0, 200)) })
|
||||
const text = id => q.getByTestId(id).textContent()
|
||||
await q.goto(`http://localhost:${PORT}/i18n-sample`)
|
||||
await q.waitForSelector('[data-testid="title"]', { timeout: 60_000 })
|
||||
r.check('device really is in New York', (await text('device-zone')) === 'America/New_York', await text('device-zone'))
|
||||
r.check('venue zone = Athens (bootstrap default)', (await text('venue-zone')).startsWith('Europe/Athens'))
|
||||
r.check('10:00 UTC in July shows 13:00 venue time (NY would be 06:00)', (await text('fixed-time')) === '01/07/2026, 13:00', await text('fixed-time'))
|
||||
r.check('business date is not shifted', /Friday.*13.*November.*2026/.test(await text('business-date')), await text('business-date'))
|
||||
r.check('en: money €1,234.50', (await text('money')) === '€1,234.50', await text('money'))
|
||||
r.check('en: plural', (await text('plural')) === '3 items in the order')
|
||||
r.check('en: relative time', (await text('relative')) === '5 minutes ago', await text('relative'))
|
||||
await q.evaluate(() => { window.__noReload = true })
|
||||
await q.getByLabel('Language').selectOption('el')
|
||||
await q.waitForFunction(() => document.querySelector('[data-testid="title"]').textContent === 'Γλώσσες και μορφές', null, { timeout: 5000 }).catch(() => {})
|
||||
r.check('switch to Ελληνικά: texts change live, no reload',
|
||||
(await text('title')) === 'Γλώσσες και μορφές' && await q.evaluate(() => window.__noReload === true))
|
||||
r.check('<html lang> follows', await q.evaluate(() => document.documentElement.lang) === 'el')
|
||||
r.check('el: interpolation', (await text('greeting')) === 'Γεια σου, Maria!')
|
||||
r.check('el: money 1.234,50 €', (await text('money')).replace(/[\u00a0\u202f]/g, ' ') === '1.234,50 €', await text('money'))
|
||||
r.check('el: number 1.234,57', (await text('number')) === '1.234,57')
|
||||
r.check('el: relative time', (await text('relative')) === 'πριν από 5 λεπτά', await text('relative'))
|
||||
r.check('el: same venue time', (await text('fixed-time')) === '01/07/2026, 13:00')
|
||||
const input = q.getByTestId('price-input')
|
||||
for (const [typed, want] of [['3,50', '3,50 €'], ['3.50', '3,50 €'], ['1.234,5', '1.234,50 €'], ['abc', 'δεν είναι αριθμός']]) {
|
||||
await input.fill(typed)
|
||||
const hint = (await q.locator('.x-field__hint').textContent()).replace(/[\u00a0\u202f]/g, ' ')
|
||||
r.check(`price input "${typed}" → ${want}`, hint.endsWith(want), hint)
|
||||
}
|
||||
await q.getByRole('button', { name: 'Άνοιγμα παραθύρου' }).click()
|
||||
r.check('ui labels translated (dialog ×, (i), spinner)',
|
||||
await q.getByRole('dialog').getByRole('button', { name: 'Κλείσιμο' }).count() === 1
|
||||
&& await q.getByRole('button', { name: 'Περισσότερες πληροφορίες' }).count() === 1
|
||||
&& (await q.locator('.x-spinner .x-visually-hidden').textContent()) === 'Φόρτωση')
|
||||
await q.screenshot({ path: path.join(OUT, 'i18n-sample-el.png'), fullPage: true })
|
||||
r.check('no page errors or missing-key warnings', qerrs.length === 0, qerrs.slice(0, 3).join(' | '))
|
||||
failures += r.done()
|
||||
await ctx.close()
|
||||
} finally {
|
||||
await browser.close()
|
||||
killTree(vite)
|
||||
}
|
||||
process.exit(r.done() ? 1 : 0)
|
||||
process.exit(failures ? 1 : 0)
|
||||
|
||||
Reference in New Issue
Block a user