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:
2026-11-13 19:51:11 +02:00
co-authored by Claude Opus 5.5
parent 3580f2815c
commit dbb8d5f0f4
38 changed files with 1206 additions and 48 deletions
+74
View File
@@ -0,0 +1,74 @@
// Formatting in the venue's zone. The test process may run in any zone: force a far one
// so a formatter that used the device zone would fail.
process.env.TZ = 'America/New_York'
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { createFormatters, toDate } from '../src/format.js'
const el = createFormatters({ language: 'el', timeZone: 'Europe/Athens', currency: 'EUR' })
const en = createFormatters({ language: 'en', timeZone: 'Europe/Athens', currency: 'EUR' })
const nbsp = s => s.replace(/[\u00a0\u202f]/g, ' ')
test('times are venue time, not device time (summer UTC+3, winter UTC+2)', () => {
assert.equal(new Date('2026-07-01T10:00:00Z').getHours(), 6, 'the process really runs in New York')
assert.equal(el.formatTime('2026-07-01T10:00:00Z'), '13:00')
assert.equal(el.formatTime('2026-01-15T10:00:00Z'), '12:00')
assert.equal(en.formatTime('2026-07-01T22:30:00Z'), '01:30')
})
test('the venue day, across midnight', () => {
assert.equal(el.formatDate('2026-07-01T22:30:00Z'), '02/07/2026')
assert.equal(el.venueDateKey('2026-07-01T22:30:00Z'), '2026-07-02')
assert.equal(el.venueDateKey('2026-07-01T20:59:00Z'), '2026-07-01')
})
test('DST changes in Athens (§7.3)', () => {
// 25 Oct 2026, 04:00 local happens twice: 00:59Z is 03:59 EEST, 01:00Z is 03:00 EET
assert.equal(el.formatTime('2026-10-25T00:59:00Z'), '03:59')
assert.equal(el.formatTime('2026-10-25T01:00:00Z'), '03:00')
// 29 Mar 2026, 03:00 local is skipped: 00:59Z is 02:59 EET, 01:00Z is 04:00 EEST
assert.equal(el.formatTime('2026-03-29T00:59:00Z'), '02:59')
assert.equal(el.formatTime('2026-03-29T01:00:00Z'), '04:00')
})
test('business dates (YYYY-MM-DD) are never shifted', () => {
const ny = createFormatters({ language: 'en', timeZone: 'America/Los_Angeles' })
assert.equal(ny.formatDate('2026-11-13'), '13/11/2026')
assert.equal(el.formatDate('2026-11-13'), '13/11/2026')
assert.match(el.formatDate('2026-11-13', 'dateLong'), /Παρασκευή.*13.*Νοεμβρίου.*2026/)
assert.match(en.formatDate('2026-11-13', 'dateLong'), /Friday.*13.*November.*2026/)
})
test('backend strings without an offset are UTC', () => {
assert.equal(toDate('2026-07-01 10:00:00.123456').toISOString(), '2026-07-01T10:00:00.123Z')
assert.equal(toDate('2026-07-01T10:00:00').toISOString(), '2026-07-01T10:00:00.000Z')
assert.equal(toDate('2026-07-01T13:00:00+03:00').toISOString(), '2026-07-01T10:00:00.000Z')
assert.equal(toDate('nonsense'), null)
assert.equal(el.formatDateTime(null), '')
})
test('date-time styles use a 24-hour clock in both languages', () => {
assert.equal(el.formatDateTime('2026-07-01T16:05:00Z'), '01/07/2026, 19:05')
assert.equal(en.formatDateTime('2026-07-01T16:05:00Z'), '01/07/2026, 19:05')
assert.equal(en.formatTime('2026-07-01T16:05:09Z', 'timeSeconds'), '19:05:09')
})
test('money and numbers per language', () => {
assert.equal(nbsp(el.formatMoney(1234.5)), '1.234,50 €')
assert.equal(en.formatMoney(1234.5), '€1,234.50')
assert.equal(nbsp(el.formatMoney(-3)), '-3,00 €')
assert.equal(el.formatMoney(null), '')
assert.equal(el.formatNumber(1234.567), '1.234,57')
assert.equal(en.formatNumber(2.5, { decimals: 2 }), '2.50')
assert.equal(nbsp(el.formatPercent(0.235)), '23,5%')
})
test('relative times', () => {
const now = Date.parse('2026-07-01T10:00:00Z')
assert.equal(en.formatRelative('2026-07-01T09:55:00Z', now), '5 minutes ago')
assert.equal(el.formatRelative('2026-07-01T09:55:00Z', now), 'πριν από 5 λεπτά')
assert.equal(en.formatRelative('2026-07-01T09:59:40Z', now), 'now')
assert.equal(en.formatRelative('2026-06-30T10:00:00Z', now), 'yesterday')
assert.equal(en.formatRelative('2026-07-01T12:00:00Z', now), 'in 2 hours')
assert.equal(en.formatRelative('2026-04-01T10:00:00Z', now), '01/04/2026')
})