feat(products): every menu text per language, the editor's language picker, service item dialog

- Alembic 0042: a `translations` column on every choice (groups, quick options,
  extras, ingredients, preference sets and choices; sub-choices and shared
  sub-sets in their JSON); the texts typed so far become the text in their
  language (Greek letters → el, else the venue's); the product's old quick map
  moves onto the quick options. API, catalogue bundle and the cloud's quick
  option names carry them; names are checked before anything is replaced.
- Editor: a language picker beside the close button (Default = the venue's
  language, plus every menu language) drives every name and description, left
  and right; an empty language shows what is used instead as its placeholder.
  The shown name is the venue language's, else any (never mixed).
- Choices: one name field; the shared controls at one height (heart red when on,
  several / compact… chips coloured when on, delete red on hover); "+ Preference"
  at the right end of the tab strip; preference groups made inside a preference.
- Categories: the shared dropdown to add one; the category dialog per language.
- The service item switch is gone: "New service item" opens its own small dialog.
- UI: Dialog headerEnd; a toned toggle keeps its colour while pressed.
- Tests: backend (choice names, migration 0042), access, editor logic, e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 18:21:50 +02:00
co-authored by Claude Opus 5.5
parent 301502965c
commit 15413dea1b
30 changed files with 853 additions and 313 deletions
@@ -0,0 +1,123 @@
"""Every menu text per language (owner 2026-11-21, core/menu_languages.py).
- Every choice gets its own `translations` {language: text}: choice groups, quick options,
extras, ingredients, preference sets and their choices (sub-choices and a set's shared
sub-set keep theirs inside their JSON).
- The texts typed so far had no language: they become the text **in their language**: Greek
letters → "el", else the venue's language (`venue.language`, default "en"). A language that
already had a translation keeps it.
- The product's old `"quick": {"<quick option's name>": "…"}` translations move onto the quick
options.
Revision ID: 0042_menu_texts_per_language
Revises: 0041_floor_item_color
Create Date: 2026-11-21 12:00:00
"""
import json
import re
from alembic import op
import sqlalchemy as sa
revision = '0042_menu_texts_per_language'
down_revision = '0041_floor_item_color'
branch_labels = None
depends_on = None
CHOICE_TABLES = ('product_modifier_groups', 'product_quick_options', 'product_options', 'product_ingredients',
'product_preference_sets', 'product_preference_choices')
GREEK = re.compile('[Ͱ-Ͽἀ-῿]')
LANGS = ('el', 'en')
def _load(v):
if not v:
return {}
try:
d = json.loads(v)
except ValueError:
return {}
return d if isinstance(d, (dict, list)) else {}
def _dump(d):
return json.dumps(d, ensure_ascii=False) if d else None
def upgrade() -> None:
for table in CHOICE_TABLES:
with op.batch_alter_table(table, schema=None) as batch_op:
batch_op.add_column(sa.Column('translations', sa.Text(), nullable=True))
bind = op.get_bind()
row = bind.execute(sa.text("SELECT value FROM pos_settings WHERE key = 'venue.language'")).first()
venue = (row[0] if row else None) or 'en'
venue = venue if venue in LANGS else 'en'
def lang_of(text):
return 'el' if GREEK.search(text or '') else venue
def names(text, current=None):
out = dict(current or {})
if (text or '').strip():
out.setdefault(lang_of(text), text.strip())
return out
def subs(raw):
"""Sub-choices (a JSON list of dicts) with their names per language."""
data = _load(raw)
if not isinstance(data, list) or not data:
return raw
for s in data:
if isinstance(s, dict):
s['translations'] = names(s.get('name'), s.get('translations') if isinstance(s.get('translations'), dict) else None)
return json.dumps(data, ensure_ascii=False)
# products: name / description in their language; the quick options' translations move out
quick_moved = {}
for pid, name, desc, tr in bind.execute(sa.text("SELECT id, name, description, translations FROM products")).fetchall():
data = _load(tr)
data = data if isinstance(data, dict) else {}
for lang, fields in list(data.items()):
if not isinstance(fields, dict):
data.pop(lang)
continue
for base, text in (fields.pop('quick', None) or {}).items():
quick_moved.setdefault(pid, {}).setdefault(base, {})[lang] = text
for field, text in (('name', name), ('description', desc)):
if (text or '').strip():
data.setdefault(lang_of(text), {}).setdefault(field, text.strip())
data = {k: v for k, v in data.items() if v}
bind.execute(sa.text("UPDATE products SET translations = :t WHERE id = :id"), {'t': _dump(data), 'id': pid})
for cid, name, tr in bind.execute(sa.text("SELECT id, name, translations FROM categories")).fetchall():
data = _load(tr)
data = data if isinstance(data, dict) else {}
if (name or '').strip():
data.setdefault(lang_of(name), {}).setdefault('name', name.strip())
bind.execute(sa.text("UPDATE categories SET translations = :t WHERE id = :id"), {'t': _dump(data), 'id': cid})
for qid, pid, name in bind.execute(sa.text("SELECT id, product_id, name FROM product_quick_options")).fetchall():
bind.execute(sa.text("UPDATE product_quick_options SET translations = :t WHERE id = :id"),
{'t': _dump(names(name, quick_moved.get(pid, {}).get(name))), 'id': qid})
for table in ('product_modifier_groups', 'product_ingredients'):
for rid, name in bind.execute(sa.text(f"SELECT id, name FROM {table}")).fetchall():
bind.execute(sa.text(f"UPDATE {table} SET translations = :t WHERE id = :id"), {'t': _dump(names(name)), 'id': rid})
for table in ('product_options', 'product_preference_choices'):
for rid, name, sub in bind.execute(sa.text(f"SELECT id, name, sub_choices FROM {table}")).fetchall():
bind.execute(sa.text(f"UPDATE {table} SET translations = :t, sub_choices = :s WHERE id = :id"),
{'t': _dump(names(name)), 's': subs(sub), 'id': rid})
for rid, name, shared in bind.execute(sa.text("SELECT id, name, shared_subset FROM product_preference_sets")).fetchall():
data = _load(shared)
if isinstance(data, dict) and data:
data['translations'] = names(data.get('name'))
data['choices'] = json.loads(subs(json.dumps(data.get('choices') or [])) or '[]')
shared = json.dumps(data, ensure_ascii=False)
bind.execute(sa.text("UPDATE product_preference_sets SET translations = :t, shared_subset = :s WHERE id = :id"),
{'t': _dump(names(name)), 's': shared, 'id': rid})
def downgrade() -> None:
for table in CHOICE_TABLES:
with op.batch_alter_table(table, schema=None) as batch_op:
batch_op.drop_column('translations')