feat: staff apps show the menu in the reader's language (plan 6R.L)

The waiters' phones and the counter show categories, products and every
choice (quick options, extras and sub-choices, preferences, shared sets,
ingredients, groups) in the signed-in person's language, falling back to
the stored text. Display only: carts, lines, tickets and the kitchen keep
the venue's text (ids, sub-choices by stored name). In the venue's own
language nothing changes.

- @xenia/access: menuText / useMenuText (mt, mt.choice, mt.line, mt.matches)
- /api/pos/menu carries translations for products, categories and choices
- shared ProductDialog takes a text() prop (the counter passes useMenuText)
- search finds a product by its name in any language (counter, waiter)
- waiter: useMenuNames for sent lines; picker, drawer, cart, summary,
  table lines, quantity / price history, favourites setup
- counter: categories, cards, dialog, cart lines, table lines, payment rows
- tests: access menuText, ordering search, test_pos per-language,
  e2e waiter.mjs and terminal.mjs 6R.L blocks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 20:18:10 +02:00
co-authored by Claude Opus 5.5
parent f107deca8c
commit 0840247768
29 changed files with 518 additions and 123 deletions
+30 -22
View File
@@ -1,5 +1,5 @@
import { useState, useEffect, useRef } from 'react'
import { useCan } from '@xenia/access'
import { useCan, useMenuText } from '@xenia/access'
import useWaiterFavoritesStore from '../store/waiterFavoritesStore'
import { assetUrl } from '../config/server'
import { money } from '../i18n'
@@ -155,6 +155,7 @@ function Row({ selected, onClick, children, right, left, style = {} }) {
function QuickOptionRow({ opt, quickState, setQuickState, compact }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const qty = quickState[opt.id] || 0
const selected = qty > 0
const toggleSingle = () => setQuickState(s => ({ ...s, [opt.id]: selected ? 0 : 1 }))
@@ -176,7 +177,7 @@ function QuickOptionRow({ opt, quickState, setQuickState, compact }) {
</div>
) : null}
>
<div style={{ fontSize: compact ? 13 : 15, fontWeight: 500, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{opt.name}</div>
<div style={{ fontSize: compact ? 13 : 15, fontWeight: 500, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{mt(opt)}</div>
{opt.price > 0 && <div style={{ fontSize: 12, color: 'var(--muted)', marginTop: 2 }}>+{money(opt.price)}{opt.allow_multiple ? ` ${t('drawer.each')}` : ''}</div>}
</Row>
)
@@ -186,6 +187,7 @@ function QuickOptionRow({ opt, quickState, setQuickState, compact }) {
function ExtraOptionRow({ opt, extrasState, setExtrasState, expandedExtra, setExpandedExtra, compact }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const sel = extrasState[opt.id]
const selected = !!sel
const open = expandedExtra === opt.id
@@ -249,7 +251,7 @@ function ExtraOptionRow({ opt, extrasState, setExtrasState, expandedExtra, setEx
}
style={compact ? { minHeight: 48 } : {}}
>
<div style={{ fontSize: compact ? 13 : 15, fontWeight: 500, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{opt.name}</div>
<div style={{ fontSize: compact ? 13 : 15, fontWeight: 500, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{mt(opt)}</div>
<div style={{ fontSize: 12, color: 'var(--muted)', marginTop: 2 }}>
{(opt.extra_cost ?? 0) !== 0 ? `+${money(opt.extra_cost)}` : t('drawer.included')}
{subLabel && <span style={{ color: 'var(--x-warning)', fontWeight: 600 }}> · {subLabel}</span>}
@@ -272,7 +274,7 @@ function ExtraOptionRow({ opt, extrasState, setExtrasState, expandedExtra, setEx
left={<RadioDot selected={isSel} />}
style={sub.is_compact ? { minHeight: 44 } : {}}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div style={{ fontSize: sub.is_compact ? 12 : 14, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{sub.name}</div>
<div style={{ fontSize: sub.is_compact ? 12 : 14, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{mt(sub)}</div>
{(sub.extra_cost ?? 0) !== 0 && <div style={{ fontSize: 12, color: 'var(--muted)', flexShrink: 0, marginLeft: 6 }}>+{money(sub.extra_cost)}</div>}
</div>
</Row>
@@ -309,7 +311,7 @@ function ExtraOptionRow({ opt, extrasState, setExtrasState, expandedExtra, setEx
style={sub.is_compact ? { minHeight: 44 } : {}}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', minWidth: 0 }}>
<div style={{ fontSize: sub.is_compact ? 12 : 14, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{sub.name}
{mt(sub)}
{subQty > 1 && <span style={{ color: 'var(--muted)', marginLeft: 6, fontSize: 12, fontVariantNumeric: 'tabular-nums' }}>×{subQty}</span>}
</div>
{(sub.extra_cost ?? 0) !== 0 && <div style={{ fontSize: 12, color: 'var(--muted)', flexShrink: 0, marginLeft: 6 }}>+{money(sub.extra_cost)}{sub.allow_multiple ? ` ${t('drawer.each')}` : ''}</div>}
@@ -328,6 +330,7 @@ function ExtraOptionRow({ opt, extrasState, setExtrasState, expandedExtra, setEx
function IngredientRow({ ing, removedState, setRemovedState, compact }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const removed = !!removedState[ing.id]
return (
<Row selected={false}
@@ -346,7 +349,7 @@ function IngredientRow({ ing, removedState, setRemovedState, compact }) {
{removed ? t('drawer.removed') : t('drawer.remove')}
</div>
}>
<div style={{ fontSize: compact ? 13 : 15, fontWeight: 500, color: removed ? 'var(--muted)' : 'var(--text)', textDecoration: removed ? 'line-through' : 'none', transition: 'all 120ms', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{ing.name}</div>
<div style={{ fontSize: compact ? 13 : 15, fontWeight: 500, color: removed ? 'var(--muted)' : 'var(--text)', textDecoration: removed ? 'line-through' : 'none', transition: 'all 120ms', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{mt(ing)}</div>
</Row>
)
}
@@ -355,6 +358,7 @@ function IngredientRow({ ing, removedState, setRemovedState, compact }) {
function PrefSetBlock({ ps, prefs, setPrefs, subChoices, setSubChoices, sharedSubs, setSharedSubs }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const selChoice = prefs[ps.id] ?? null
const complete = selChoice != null
&& !(selChoice.sub_choices?.length > 0 && subChoices[selChoice.id] == null)
@@ -374,7 +378,7 @@ function PrefSetBlock({ ps, prefs, setPrefs, subChoices, setSubChoices, sharedSu
return (
<div>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8, padding: '0 2px 10px' }}>
<div style={{ fontSize: 14, fontWeight: 700, color: complete ? 'var(--text)' : 'var(--x-danger)' }}>{ps.name}</div>
<div style={{ fontSize: 14, fontWeight: 700, color: complete ? 'var(--text)' : 'var(--x-danger)' }}>{mt(ps)}</div>
{!complete && <div style={{ fontSize: 11, fontWeight: 700, color: 'var(--x-danger)', textTransform: 'uppercase', letterSpacing: 0.6 }}>{t('drawer.required')}</div>}
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
@@ -388,7 +392,7 @@ function PrefSetBlock({ ps, prefs, setPrefs, subChoices, setSubChoices, sharedSu
<Row selected={isSel} onClick={() => selectPref(ch)} left={<RadioDot selected={isSel} />}
style={ch.is_compact ? { minHeight: 48 } : {}}
right={(ch.extra_cost ?? 0) !== 0 ? <div style={{ fontSize: ch.is_compact ? 12 : 14, fontWeight: 500, color: 'var(--muted)', flexShrink: 0 }}>{ch.extra_cost > 0 ? '+' : ''}{money(ch.extra_cost)}</div> : null}>
<div style={{ fontSize: ch.is_compact ? 13 : 15, fontWeight: 500, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{ch.name}</div>
<div style={{ fontSize: ch.is_compact ? 13 : 15, fontWeight: 500, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{mt(ch)}</div>
</Row>
{isSel && hasSubs && (
@@ -401,7 +405,7 @@ function PrefSetBlock({ ps, prefs, setPrefs, subChoices, setSubChoices, sharedSu
<Row selected={subSel} onClick={() => setSubChoices(s => ({ ...s, [ch.id]: sub }))} left={<RadioDot selected={subSel} />}
style={sub.is_compact ? { minHeight: 44 } : {}}
right={(sub.extra_cost ?? 0) !== 0 ? <div style={{ fontSize: 12, color: 'var(--muted)', flexShrink: 0 }}>+{money(sub.extra_cost)}</div> : null}>
<div style={{ fontSize: sub.is_compact ? 12 : 14, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{sub.name}</div>
<div style={{ fontSize: sub.is_compact ? 12 : 14, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{mt(sub)}</div>
</Row>
</div>
)
@@ -414,7 +418,7 @@ function PrefSetBlock({ ps, prefs, setPrefs, subChoices, setSubChoices, sharedSu
{showShared && (
<div style={{ marginTop: 4, marginLeft: 8, paddingLeft: 14, borderLeft: '2px solid rgb(var(--x-warning-rgb) / 0.3)', width: '100%' }}>
<div style={{ fontSize: 11, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.6, padding: '4px 2px 6px' }}>{ps.shared_subset.name}</div>
<div style={{ fontSize: 11, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.6, padding: '4px 2px 6px' }}>{mt(ps.shared_subset)}</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
{ps.shared_subset.choices.map((sub, si) => {
const subSel = sharedSubs[ps.id]?.name === sub.name
@@ -423,7 +427,7 @@ function PrefSetBlock({ ps, prefs, setPrefs, subChoices, setSubChoices, sharedSu
<Row selected={subSel} onClick={() => setSharedSubs(s => ({ ...s, [ps.id]: sub }))} left={<RadioDot selected={subSel} />}
style={sub.is_compact ? { minHeight: 44 } : {}}
right={(sub.extra_cost ?? 0) !== 0 ? <div style={{ fontSize: 12, color: 'var(--muted)', flexShrink: 0 }}>+{money(sub.extra_cost)}</div> : null}>
<div style={{ fontSize: sub.is_compact ? 12 : 14, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{sub.name}</div>
<div style={{ fontSize: sub.is_compact ? 12 : 14, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{mt(sub)}</div>
</Row>
</div>
)
@@ -549,6 +553,7 @@ function partitionByGroup(items, modifierGroups) {
function ExtrasTab({ product, extrasState, setExtrasState, expandedExtra, setExpandedExtra }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const extraGroups = (product.modifier_groups || []).filter(g => g.modifier_type === 'option')
const [collapsedGroups, setCollapsedGroups] = useState(() => Object.fromEntries(extraGroups.map(g => [g.id, true])))
const options = product.options || []
@@ -579,7 +584,7 @@ function ExtrasTab({ product, extrasState, setExtrasState, expandedExtra, setExp
const isCollapsed = collapsedGroups[group.id] ?? true
return (
<div key={group.id} style={{ marginBottom: 12 }}>
<PWAGroupHeader name={group.name} collapsed={isCollapsed} onToggle={() => toggleGroup(group.id)} colorIdx={gi} />
<PWAGroupHeader name={mt(group)} collapsed={isCollapsed} onToggle={() => toggleGroup(group.id)} colorIdx={gi} />
{!isCollapsed && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
{items.map(renderOption)}
@@ -596,6 +601,7 @@ function ExtrasTab({ product, extrasState, setExtrasState, expandedExtra, setExp
function IngredientsTab({ product, removedState, setRemovedState }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const ingGroups = (product.modifier_groups || []).filter(g => g.modifier_type === 'ingredient')
const [collapsedGroups, setCollapsedGroups] = useState(() => Object.fromEntries(ingGroups.map(g => [g.id, true])))
const ingredients = product.ingredients || []
@@ -626,7 +632,7 @@ function IngredientsTab({ product, removedState, setRemovedState }) {
const isCollapsed = collapsedGroups[group.id] ?? true
return (
<div key={group.id} style={{ marginBottom: 12 }}>
<PWAGroupHeader name={group.name} collapsed={isCollapsed} onToggle={() => toggleGroup(group.id)} colorIdx={gi} />
<PWAGroupHeader name={mt(group)} collapsed={isCollapsed} onToggle={() => toggleGroup(group.id)} colorIdx={gi} />
{!isCollapsed && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
{items.map(renderIng)}
@@ -643,6 +649,7 @@ function IngredientsTab({ product, removedState, setRemovedState }) {
function PrefsTab({ product, prefs, setPrefs, subChoices, setSubChoices, sharedSubs, setSharedSubs }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const prefGroups = (product.modifier_groups || []).filter(g => g.modifier_type === 'preference')
const [collapsedGroups, setCollapsedGroups] = useState(() => Object.fromEntries(prefGroups.map(g => [g.id, true])))
const preferenceSets = product.preference_sets || []
@@ -675,7 +682,7 @@ function PrefsTab({ product, prefs, setPrefs, subChoices, setSubChoices, sharedS
const isCollapsed = collapsedGroups[group.id] ?? true
return (
<div key={group.id} style={{ marginBottom: 16 }}>
<PWAGroupHeader name={group.name} collapsed={isCollapsed} onToggle={() => toggleGroup(group.id)} colorIdx={gi} />
<PWAGroupHeader name={mt(group)} collapsed={isCollapsed} onToggle={() => toggleGroup(group.id)} colorIdx={gi} />
{!isCollapsed && (
<div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
{items.map(renderPrefSet)}
@@ -1071,6 +1078,7 @@ const FALLBACK_QUICK_NOTES = ['drawer.notes.noSalt', 'drawer.notes.quick', 'draw
export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialState, courses, quickNotes }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const itemFavorites = useWaiterFavoritesStore(s => s.itemFavorites)
// A price set before sending needs the key itself (plan 4.3); the manager-approval path for
// it comes with server-priced orders (4.4). After sending, the item's actions offer it.
@@ -1208,8 +1216,8 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
&& (!sharedSub || sharedSub.name === defaultSharedSub?.name)
if (isFullyDefault) { price += delta; return }
const value = `${choice.name}${inlineSub ? ` · ${inlineSub.name}` : ''}${sharedSub ? ` · ${sharedSub.name}` : ''}`
lines.push({ group: 'prefs', label: ps.name, value, qty: 1, price: delta, detail: null })
const value = `${mt(choice)}${inlineSub ? ` · ${mt(inlineSub)}` : ''}${sharedSub ? ` · ${mt(sharedSub)}` : ''}`
lines.push({ group: 'prefs', label: mt(ps), value, qty: 1, price: delta, detail: null })
price += delta
})
@@ -1217,7 +1225,7 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
const q = quickState[opt.id] || 0
if (q === 0) return
const linePrice = opt.price * q
lines.push({ group: 'quick', label: opt.name, qty: q, price: linePrice, detail: null })
lines.push({ group: 'quick', label: mt(opt), qty: q, price: linePrice, detail: null })
price += linePrice
})
@@ -1231,19 +1239,19 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
if (!subQty || subQty < 1) return
const sub = opt.sub_choices.find(s => s.name === subName)
const linePrice = ((opt.extra_cost ?? 0) + (sub?.extra_cost ?? 0)) * subQty
lines.push({ group: 'extras', label: opt.name, qty: subQty, price: linePrice, subName, detail: null })
lines.push({ group: 'extras', label: mt(opt), qty: subQty, price: linePrice, subName: sub ? mt(sub) : subName, detail: null })
price += linePrice
})
} else {
const sub = opt.sub_choices?.find(s => s.name === sel.subName)
const linePrice = ((opt.extra_cost ?? 0) + (sub?.extra_cost ?? 0)) * sel.qty
lines.push({ group: 'extras', label: opt.name, qty: sel.qty, price: linePrice, subName: sub?.name ?? null, detail: null })
lines.push({ group: 'extras', label: mt(opt), qty: sel.qty, price: linePrice, subName: sub ? mt(sub) : null, detail: null })
price += linePrice
}
})
ingredients.forEach(ing => {
if (removedState[ing.id]) lines.push({ group: 'removed', label: ing.name, qty: 1, price: 0, detail: null })
if (removedState[ing.id]) lines.push({ group: 'removed', label: mt(ing), qty: 1, price: 0, detail: null })
})
return { summaryLines: lines, totalPrice: (price + priceAdj) * qty }
@@ -1449,7 +1457,7 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
style={{ width: 48, height: 48, borderRadius: 12, objectFit: 'cover', flexShrink: 0 }} />
)}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontSize: 18, fontWeight: 700, color: 'var(--text)', lineHeight: 1.2 }}>{product.name}</div>
<div style={{ fontSize: 18, fontWeight: 700, color: 'var(--text)', lineHeight: 1.2 }}>{mt(product)}</div>
<div style={{ fontSize: 13, color: priceAdj !== 0 ? 'var(--x-warning)' : 'var(--muted)', marginTop: 2 }}>
{priceAdj !== 0
? <><span style={{ textDecoration: 'line-through', opacity: 0.5 }}>{money(product.base_price)}</span> → {money(product.base_price + priceAdj)}</>
@@ -1471,7 +1479,7 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
const isAlert = (tb.id === 'prefs' && prefsTabAlert) || (tb.id === 'favorites' && favTabAlert)
const tabColor = isAlert ? 'var(--x-danger)' : active ? 'var(--x-warning)' : 'var(--muted)'
return (
<button key={tb.id} ref={el => { tabButtonRefs.current[tb.id] = el }} onClick={() => setActiveTab(tb.id)} style={{
<button key={tb.id} ref={el => { tabButtonRefs.current[tb.id] = el }} onClick={() => setActiveTab(tb.id)} data-testid={`drawer-tab-${tb.id}`} style={{
padding: '12px 6px',
background: 'none', border: 'none',
borderBottom: `2px solid ${active ? 'var(--x-warning)' : isAlert ? 'var(--x-danger)' : 'transparent'}`,