feat(menu): the menu in English and Greek (platform-v2 step 6.4, D-29)

- products.translations / categories.translations (Alembic 0033, core/menu_languages.py: el + en,
  name / description / quick options by their base name; catalog.translation). Empty = the text
  as typed; no machine translation (owner).
- In the manager's product editor ("In English" / "In Greek", quick extras), the category dialog,
  and a menu board's Language (signage MenuContent.language).
- Customer screens only: cloud snapshot names / descriptions per language (C-2), the menu tablet's
  EL / EN switch the names (localize), signage boards; tickets, KDS, counter, phones keep the base.
- Catalogue bundles carry translations; @xenia/access menuLanguages.js (a backend test compares).
- e2e: manager (the other language saved), menu tablet (EN / EL names), QR table (English on
  the menu, the base name on the kitchen's order, Greek page as typed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:47:03 +02:00
co-authored by Claude Opus 5.5
parent 5048f82a4c
commit e395d99704
32 changed files with 459 additions and 38 deletions
@@ -12,7 +12,7 @@ import { applyTheme, Dialog, getStoredTheme, Input } from '@xenia/ui'
import { Allergens } from '@xenia/access'
import client from '../../api/client'
import { useLiveEvent, useLiveEvents } from '../../device/context'
import { idle, languagesOf, search, sections } from './logic'
import { idle, languagesOf, localize, search, sections } from './logic'
const quiet = { xenia: { noOverride: true } }
const CACHE_KEY = 'xenia:menu-tablet:menu'
@@ -75,8 +75,9 @@ export default function MenuTabletApp() {
return () => { window.removeEventListener('pointerdown', touch); window.removeEventListener('keydown', touch); clearInterval(id) }
}, [cfg.idle_seconds, reset])
const groups = useMemo(() => sections(data, cfg.group !== false, language), [data, cfg.group, language])
const found = useMemo(() => search(data, q, language), [data, q, language])
const shown = useMemo(() => localize(data, language), [data, language]) // product names in the tablet's language (6.4)
const groups = useMemo(() => sections(shown, cfg.group !== false, language), [shown, cfg.group, language])
const found = useMemo(() => search(shown, q, language), [shown, q, language])
const goTo = id => scroller.current?.querySelector(`[data-section="${id}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'start' })
if (!data) return <main className="fixed inset-0 bg-canvas" data-testid="app-menu_tablet" />
+18 -3
View File
@@ -6,12 +6,27 @@ export function fold(text) {
return String(text ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().trim()
}
/** Does a product match a search? By its name in Greek or in Latin letters ("souvlaki"), or a tag. */
/** Does a product match a search? By its name (shown or as typed, plan step 6.4) in Greek or in
* Latin letters ("souvlaki"), or a tag. */
export function matches(product, query) {
const q = fold(query)
if (!q) return true
const name = fold(product.name)
return name.includes(q) || fold(latin(product.name)).includes(q) || (product.tags || []).some(t => fold(t).includes(q))
const names = [product.name, product.base_name].filter(Boolean)
return names.some(n => fold(n).includes(q) || fold(latin(n)).includes(q)) || (product.tags || []).some(t => fold(t).includes(q))
}
/**
* The menu in the tablet's language (plan step 6.4): each product's and category's `names` /
* `descriptions` for that language (the backend falls back to the text as typed); `base_name`
* keeps the name as typed for the search.
*/
export function localize(data, language) {
if (!data) return data
const products = Object.fromEntries(Object.entries(data.products || {}).map(([id, p]) => [id, {
...p, base_name: p.name, name: p.names?.[language] || p.name, description: p.descriptions?.[language] ?? p.description,
}]))
const categories = (data.categories || []).map(c => ({ ...c, name: c.names?.[language] || c.name }))
return { ...data, products, categories }
}
/** Every product once, A to Z (the ungrouped list and the search's results). */
+13 -1
View File
@@ -1,7 +1,7 @@
// The menu tablet's logic (plan step 5.7a).
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { allProducts, fold, idle, languagesOf, matches, search, sections } from '../src/apps/menu-tablet/logic.js'
import { allProducts, fold, idle, languagesOf, localize, matches, search, sections } from '../src/apps/menu-tablet/logic.js'
const data = {
categories: [{ id: 1, name: 'Grill', depth: 0, products: [2, 1] }, { id: 3, name: 'Pita', depth: 1, products: [1] }, { id: 4, name: 'Empty', depth: 0, products: [9] }],
@@ -34,3 +34,15 @@ test('back to the start after a while; the languages a guest can pick', () => {
assert.deepEqual(languagesOf({ languages: 'en' }), ['en'])
assert.deepEqual(languagesOf(undefined), ['el', 'en'])
})
test('the menu in the language of the tablet (6.4): names switch, the base name still finds it', () => {
const data = { products: { 1: { id: 1, name: 'Σουβλάκι', names: { el: 'Σουβλάκι', en: 'Pork skewer' }, description: 'Χοιρινό', descriptions: { el: 'Χοιρινό', en: 'Pork' } }, 2: { id: 2, name: 'Μπύρα' } },
categories: [{ id: 5, name: 'Ψητά', names: { el: 'Ψητά', en: 'Grill' }, products: [1, 2] }] }
const en = localize(data, 'en')
assert.equal(en.products[1].name, 'Pork skewer')
assert.equal(en.products[1].description, 'Pork')
assert.equal(en.products[2].name, 'Μπύρα') // not translated: as typed
assert.equal(en.categories[0].name, 'Grill')
assert.ok(matches(en.products[1], 'souvl') && matches(en.products[1], 'pork'))
assert.equal(localize(data, 'el').products[1].name, 'Σουβλάκι')
})