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:
+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