diff --git a/CLAUDE.md b/CLAUDE.md index 8e9bf53..aec431d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -182,6 +182,15 @@ Migration ein — Zutaten mit fester Kennung aus dem Schlüssel, nie gelöscht; Vorlagen ersetzt. `tests/seed.test.ts` prüft die Dateien. Ein Haushalt übernimmt Kopien (`lib/starter.ts`, `lib/stores.ts`). +## Zutatennamen bei Mengen + +- Stück-Zutaten haben im Seed beide Formen je Sprache (`forms: {de: {one, other}}`, + Spalte `ingredients.forms`, Migration 0008): „1 Zwiebel“, „½ Zitrone“, „3 + Knoblauchzehen“. Gewählt wird nur über `lib/ingredient-name.ts` (`labelFor`, + `ingredientLabel`; Einzahl bis einschließlich 1). Gewicht und Volumen behalten den + Listennamen. Eine neue Stück-Zutat braucht beide Formen in allen vier Sprachen — + `tests/ingredient-name.test.ts` wacht. + ## Gerichte (Arbeitspaket 4) - Seiten unter `app/(app)/gerichte/`: Pool (Kacheln, „Ausprobieren“), Hinzufügen, diff --git a/OlaresManifest.yaml b/OlaresManifest.yaml index 4b0a772..af38680 100644 --- a/OlaresManifest.yaml +++ b/OlaresManifest.yaml @@ -21,7 +21,7 @@ metadata: title: What's cooking? description: The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box. icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png - version: 26.11.14 + version: 26.11.15 categories: - Applications @@ -61,7 +61,7 @@ permission: appData: true spec: - versionName: '26.11.14' + versionName: '26.11.15' featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png promoteImage: diff --git a/components/cooking/cooking-mode.tsx b/components/cooking/cooking-mode.tsx index 63f0e19..9409148 100644 --- a/components/cooking/cooking-mode.tsx +++ b/components/cooking/cooking-mode.tsx @@ -6,11 +6,12 @@ import { useLocale, useTranslations } from "next-intl"; import { useEffect, useRef, useState } from "react"; import { Button } from "@/components/ui/button"; import { ErrorNotice } from "@/components/ui/notice"; +import { labelFor } from "@/lib/ingredient-name"; import { timerFromText } from "@/lib/timer"; import { formatQuantity, type BaseUnit } from "@/lib/units"; import { cn } from "@/lib/utils"; -type Ingredient = { ingredientId: string; name: string; qtyPerPortion: number; unit: BaseUnit; note: string | null }; +type Ingredient = { ingredientId: string; name: string; forms: { one: string; other: string } | null; qtyPerPortion: number; unit: BaseUnit; note: string | null }; type Step = { text: string; timerSeconds: number | null }; type Running = { step: number; endsAt: number | null; left: number; done: boolean }; @@ -206,7 +207,7 @@ export function CookingMode({ {checked ? : null} - {amount(i)} {i.name} + {amount(i)} {labelFor(i, i.qtyPerPortion * portions)} {i.note ? , {i.note} : null} diff --git a/components/dishes/portion-scaler.tsx b/components/dishes/portion-scaler.tsx index f70c6c0..23c5a04 100644 --- a/components/dishes/portion-scaler.tsx +++ b/components/dishes/portion-scaler.tsx @@ -4,9 +4,18 @@ import { Minus, Plus, Timer } from "lucide-react"; import { useLocale, useTranslations } from "next-intl"; import { useState } from "react"; import { Button } from "@/components/ui/button"; +import { labelFor } from "@/lib/ingredient-name"; import { formatQuantity, scale, type BaseUnit } from "@/lib/units"; -type Ingredient = { ingredientId: string; name: string; qtyPerPortion: number; unit: BaseUnit; note: string | null; isStaple: boolean }; +type Ingredient = { + ingredientId: string; + name: string; + forms: { one: string; other: string } | null; + qtyPerPortion: number; + unit: BaseUnit; + note: string | null; + isStaple: boolean; +}; type Step = { text: string; timerSeconds: number | null }; // Zutaten in der gewählten Portionszahl, darunter die Schritte. Die Mengen @@ -43,7 +52,7 @@ export function PortionScaler({ ingredients, steps, initialPortions }: { ingredi {f.unit ? ` ${f.unit}` : ""} - {i.name} + {labelFor(i, scale(i.qtyPerPortion, portions))} {i.note ? , {i.note} : null} {i.isStaple ? {t("staple")} : null} diff --git a/db/migrations/0008_ingredient_forms.sql b/db/migrations/0008_ingredient_forms.sql new file mode 100644 index 0000000..9aae006 --- /dev/null +++ b/db/migrations/0008_ingredient_forms.sql @@ -0,0 +1,4 @@ +-- Einzahl und Mehrzahl für Zutaten, die man in Stück zählt („1 Zwiebel“, +-- „3 Knoblauchzehen“). Je Sprache { "one": …, "other": … }; eingespielt aus +-- db/seed/ingredients.json (scripts/seed.mjs), gewählt in lib/ingredient-name.ts. +alter table ingredients add column forms jsonb not null default '{}'; diff --git a/db/seed/ingredients.json b/db/seed/ingredients.json index f94d18c..e4f3958 100644 --- a/db/seed/ingredients.json +++ b/db/seed/ingredients.json @@ -94,7 +94,25 @@ "cebolla" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Zwiebel", + "other": "Zwiebeln" + }, + "en": { + "one": "Onion", + "other": "Onions" + }, + "fr": { + "one": "Oignon", + "other": "Oignons" + }, + "es": { + "one": "Cebolla", + "other": "Cebollas" + } + } }, { "key": "red_onion", @@ -113,7 +131,25 @@ "cebolla roja" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Rote Zwiebel", + "other": "Rote Zwiebeln" + }, + "en": { + "one": "Red onion", + "other": "Red onions" + }, + "fr": { + "one": "Oignon rouge", + "other": "Oignons rouges" + }, + "es": { + "one": "Cebolla morada", + "other": "Cebollas moradas" + } + } }, { "key": "spring_onion", @@ -134,7 +170,25 @@ "cebollino tierno" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Frühlingszwiebel", + "other": "Frühlingszwiebeln" + }, + "en": { + "one": "Spring onion", + "other": "Spring onions" + }, + "fr": { + "one": "Oignon nouveau", + "other": "Oignons nouveaux" + }, + "es": { + "one": "Cebolleta", + "other": "Cebolletas" + } + } }, { "key": "shallot", @@ -153,7 +207,25 @@ "échalote" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Schalotte", + "other": "Schalotten" + }, + "en": { + "one": "Shallot", + "other": "Shallots" + }, + "fr": { + "one": "Échalote", + "other": "Échalotes" + }, + "es": { + "one": "Chalota", + "other": "Chalotas" + } + } }, { "key": "garlic", @@ -175,7 +247,25 @@ "ajo" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Knoblauchzehe", + "other": "Knoblauchzehen" + }, + "en": { + "one": "Garlic clove", + "other": "Garlic cloves" + }, + "fr": { + "one": "Gousse d'ail", + "other": "Gousses d'ail" + }, + "es": { + "one": "Diente de ajo", + "other": "Dientes de ajo" + } + } }, { "key": "leek", @@ -196,7 +286,25 @@ "puerros" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Stange Lauch", + "other": "Stangen Lauch" + }, + "en": { + "one": "Leek", + "other": "Leeks" + }, + "fr": { + "one": "Poireau", + "other": "Poireaux" + }, + "es": { + "one": "Puerro", + "other": "Puerros" + } + } }, { "key": "carrot", @@ -264,7 +372,25 @@ "rama de apio" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Stange Staudensellerie", + "other": "Stangen Staudensellerie" + }, + "en": { + "one": "Celery stick", + "other": "Celery sticks" + }, + "fr": { + "one": "Branche de céleri", + "other": "Branches de céleri" + }, + "es": { + "one": "Rama de apio", + "other": "Ramas de apio" + } + } }, { "key": "parsnip", @@ -326,7 +452,25 @@ "bouquet de légumes" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bund Suppengrün", + "other": "Bund Suppengrün" + }, + "en": { + "one": "Soup vegetables bundle", + "other": "Soup vegetables bundles" + }, + "fr": { + "one": "Bouquet de légumes pour pot-au-feu", + "other": "Bouquets de légumes pour pot-au-feu" + }, + "es": { + "one": "Manojo de verduras para caldo", + "other": "Manojos de verduras para caldo" + } + } }, { "key": "tomato", @@ -394,7 +538,25 @@ "cucumbers" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Salatgurke", + "other": "Salatgurken" + }, + "en": { + "one": "Cucumber", + "other": "Cucumbers" + }, + "fr": { + "one": "Concombre", + "other": "Concombres" + }, + "es": { + "one": "Pepino", + "other": "Pepinos" + } + } }, { "key": "bell_pepper_red", @@ -414,7 +576,25 @@ "capsicum" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Paprika rot", + "other": "Paprika rot" + }, + "en": { + "one": "Red pepper", + "other": "Red peppers" + }, + "fr": { + "one": "Poivron rouge", + "other": "Poivrons rouges" + }, + "es": { + "one": "Pimiento rojo", + "other": "Pimientos rojos" + } + } }, { "key": "bell_pepper_yellow", @@ -433,7 +613,25 @@ "yellow bell pepper" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Paprika gelb", + "other": "Paprika gelb" + }, + "en": { + "one": "Yellow pepper", + "other": "Yellow peppers" + }, + "fr": { + "one": "Poivron jaune", + "other": "Poivrons jaunes" + }, + "es": { + "one": "Pimiento amarillo", + "other": "Pimientos amarillos" + } + } }, { "key": "bell_pepper_green", @@ -453,7 +651,25 @@ "pimiento italiano" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Paprika grün", + "other": "Paprika grün" + }, + "en": { + "one": "Green pepper", + "other": "Green peppers" + }, + "fr": { + "one": "Poivron vert", + "other": "Poivrons verts" + }, + "es": { + "one": "Pimiento verde", + "other": "Pimientos verdes" + } + } }, { "key": "zucchini", @@ -472,7 +688,25 @@ "calabacines" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Zucchini", + "other": "Zucchini" + }, + "en": { + "one": "Courgette", + "other": "Courgettes" + }, + "fr": { + "one": "Courgette", + "other": "Courgettes" + }, + "es": { + "one": "Calabacín", + "other": "Calabacines" + } + } }, { "key": "eggplant", @@ -492,7 +726,25 @@ "berenjenas" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Aubergine", + "other": "Auberginen" + }, + "en": { + "one": "Aubergine", + "other": "Aubergines" + }, + "fr": { + "one": "Aubergine", + "other": "Aubergines" + }, + "es": { + "one": "Berenjena", + "other": "Berenjenas" + } + } }, { "key": "broccoli", @@ -528,7 +780,25 @@ "Karfiol" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Blumenkohl", + "other": "Blumenkohl" + }, + "en": { + "one": "Cauliflower", + "other": "Cauliflowers" + }, + "fr": { + "one": "Chou-fleur", + "other": "Choux-fleurs" + }, + "es": { + "one": "Coliflor", + "other": "Coliflores" + } + } }, { "key": "white_cabbage", @@ -624,7 +894,25 @@ "Kohlrübe" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Kohlrabi", + "other": "Kohlrabi" + }, + "en": { + "one": "Kohlrabi", + "other": "Kohlrabis" + }, + "fr": { + "one": "Chou-rave", + "other": "Choux-raves" + }, + "es": { + "one": "Colinabo", + "other": "Colinabos" + } + } }, { "key": "spinach", @@ -669,7 +957,25 @@ "salade verte" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Kopfsalat", + "other": "Köpfe Kopfsalat" + }, + "en": { + "one": "Lettuce", + "other": "Lettuces" + }, + "fr": { + "one": "Laitue", + "other": "Laitues" + }, + "es": { + "one": "Lechuga", + "other": "Lechugas" + } + } }, { "key": "iceberg_lettuce", @@ -687,7 +993,25 @@ "iceberg" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Eisbergsalat", + "other": "Köpfe Eisbergsalat" + }, + "en": { + "one": "Iceberg lettuce", + "other": "Iceberg lettuces" + }, + "fr": { + "one": "Laitue iceberg", + "other": "Laitues iceberg" + }, + "es": { + "one": "Lechuga iceberg", + "other": "Lechugas iceberg" + } + } }, { "key": "romaine", @@ -708,7 +1032,25 @@ "cogollos" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Romanasalat", + "other": "Köpfe Romanasalat" + }, + "en": { + "one": "Romaine lettuce", + "other": "Romaine lettuces" + }, + "fr": { + "one": "Laitue romaine", + "other": "Laitues romaines" + }, + "es": { + "one": "Lechuga romana", + "other": "Lechugas romanas" + } + } }, { "key": "lambs_lettuce", @@ -847,7 +1189,25 @@ "fennel bulb" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Fenchelknolle", + "other": "Fenchelknollen" + }, + "en": { + "one": "Fennel bulb", + "other": "Fennel bulbs" + }, + "fr": { + "one": "Bulbe de fenouil", + "other": "Bulbes de fenouil" + }, + "es": { + "one": "Bulbo de hinojo", + "other": "Bulbos de hinojo" + } + } }, { "key": "asparagus_white", @@ -911,7 +1271,25 @@ "rabanitos" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bund Radieschen", + "other": "Bund Radieschen" + }, + "en": { + "one": "Bunch of radishes", + "other": "Bunches of radishes" + }, + "fr": { + "one": "Botte de radis", + "other": "Bottes de radis" + }, + "es": { + "one": "Manojo de rábanos", + "other": "Manojos de rábanos" + } + } }, { "key": "chili_pepper", @@ -935,7 +1313,25 @@ "chile fresco" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Chilischote", + "other": "Chilischoten" + }, + "en": { + "one": "Chilli pepper", + "other": "Chilli peppers" + }, + "fr": { + "one": "Piment frais", + "other": "Piments frais" + }, + "es": { + "one": "Guindilla fresca", + "other": "Guindillas frescas" + } + } }, { "key": "ginger", @@ -977,7 +1373,25 @@ "col china" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Pak Choi", + "other": "Pak Choi" + }, + "en": { + "one": "Pak choi", + "other": "Pak choi" + }, + "fr": { + "one": "Pak-choï", + "other": "Pak-choïs" + }, + "es": { + "one": "Pak choi", + "other": "Pak chois" + } + } }, { "key": "bean_sprouts", @@ -1023,7 +1437,25 @@ "manzana" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Apfel", + "other": "Äpfel" + }, + "en": { + "one": "Apple", + "other": "Apples" + }, + "fr": { + "one": "Pomme", + "other": "Pommes" + }, + "es": { + "one": "Manzana", + "other": "Manzanas" + } + } }, { "key": "banana", @@ -1042,7 +1474,25 @@ "plátano" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Banane", + "other": "Bananen" + }, + "en": { + "one": "Banana", + "other": "Bananas" + }, + "fr": { + "one": "Banane", + "other": "Bananes" + }, + "es": { + "one": "Plátano", + "other": "Plátanos" + } + } }, { "key": "pear", @@ -1062,7 +1512,25 @@ "pera" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Birne", + "other": "Birnen" + }, + "en": { + "one": "Pear", + "other": "Pears" + }, + "fr": { + "one": "Poire", + "other": "Poires" + }, + "es": { + "one": "Pera", + "other": "Peras" + } + } }, { "key": "orange", @@ -1081,7 +1549,25 @@ "naranja" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Orange", + "other": "Orangen" + }, + "en": { + "one": "Orange", + "other": "Oranges" + }, + "fr": { + "one": "Orange", + "other": "Oranges" + }, + "es": { + "one": "Naranja", + "other": "Naranjas" + } + } }, { "key": "lemon", @@ -1102,7 +1588,25 @@ "limones" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Zitrone", + "other": "Zitronen" + }, + "en": { + "one": "Lemon", + "other": "Lemons" + }, + "fr": { + "one": "Citron", + "other": "Citrons" + }, + "es": { + "one": "Limón", + "other": "Limones" + } + } }, { "key": "lime", @@ -1121,7 +1625,25 @@ "citron vert bio" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Limette", + "other": "Limetten" + }, + "en": { + "one": "Lime", + "other": "Limes" + }, + "fr": { + "one": "Citron vert", + "other": "Citrons verts" + }, + "es": { + "one": "Lima", + "other": "Limas" + } + } }, { "key": "clementine", @@ -1143,7 +1665,25 @@ "clementinas" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Clementine", + "other": "Clementinen" + }, + "en": { + "one": "Clementine", + "other": "Clementines" + }, + "fr": { + "one": "Clémentine", + "other": "Clémentines" + }, + "es": { + "one": "Mandarina", + "other": "Mandarinas" + } + } }, { "key": "grapes", @@ -1251,7 +1791,25 @@ "Kiwis" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Kiwi", + "other": "Kiwis" + }, + "en": { + "one": "Kiwi fruit", + "other": "Kiwi fruits" + }, + "fr": { + "one": "Kiwi", + "other": "Kiwis" + }, + "es": { + "one": "Kiwi", + "other": "Kiwis" + } + } }, { "key": "pineapple", @@ -1269,7 +1827,25 @@ "ananas frais" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Ananas", + "other": "Ananas" + }, + "en": { + "one": "Pineapple", + "other": "Pineapples" + }, + "fr": { + "one": "Ananas", + "other": "Ananas" + }, + "es": { + "one": "Piña", + "other": "Piñas" + } + } }, { "key": "mango", @@ -1288,7 +1864,25 @@ "mangues" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Mango", + "other": "Mangos" + }, + "en": { + "one": "Mango", + "other": "Mangoes" + }, + "fr": { + "one": "Mangue", + "other": "Mangues" + }, + "es": { + "one": "Mango", + "other": "Mangos" + } + } }, { "key": "avocado", @@ -1308,7 +1902,25 @@ "aguacates" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Avocado", + "other": "Avocados" + }, + "en": { + "one": "Avocado", + "other": "Avocados" + }, + "fr": { + "one": "Avocat", + "other": "Avocats" + }, + "es": { + "one": "Aguacate", + "other": "Aguacates" + } + } }, { "key": "peach", @@ -1330,7 +1942,25 @@ "nectarinas" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Pfirsich", + "other": "Pfirsiche" + }, + "en": { + "one": "Peach", + "other": "Peaches" + }, + "fr": { + "one": "Pêche", + "other": "Pêches" + }, + "es": { + "one": "Melocotón", + "other": "Melocotones" + } + } }, { "key": "plums", @@ -1415,7 +2045,25 @@ "perejil fresco" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bund Petersilie", + "other": "Bund Petersilie" + }, + "en": { + "one": "Bunch of parsley", + "other": "Bunches of parsley" + }, + "fr": { + "one": "Bouquet de persil", + "other": "Bouquets de persil" + }, + "es": { + "one": "Manojo de perejil", + "other": "Manojos de perejil" + } + } }, { "key": "chives", @@ -1433,7 +2081,25 @@ "chive" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bund Schnittlauch", + "other": "Bund Schnittlauch" + }, + "en": { + "one": "Bunch of chives", + "other": "Bunches of chives" + }, + "fr": { + "one": "Bouquet de ciboulette", + "other": "Bouquets de ciboulette" + }, + "es": { + "one": "Manojo de cebollino", + "other": "Manojos de cebollino" + } + } }, { "key": "dill", @@ -1451,7 +2117,25 @@ "fresh dill" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bund Dill", + "other": "Bund Dill" + }, + "en": { + "one": "Bunch of dill", + "other": "Bunches of dill" + }, + "fr": { + "one": "Bouquet d'aneth", + "other": "Bouquets d'aneth" + }, + "es": { + "one": "Manojo de eneldo", + "other": "Manojos de eneldo" + } + } }, { "key": "basil", @@ -1471,7 +2155,25 @@ "albahaca fresca" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Topf Basilikum", + "other": "Töpfe Basilikum" + }, + "en": { + "one": "Pot of basil", + "other": "Pots of basil" + }, + "fr": { + "one": "Pot de basilic", + "other": "Pots de basilic" + }, + "es": { + "one": "Maceta de albahaca", + "other": "Macetas de albahaca" + } + } }, { "key": "coriander", @@ -1492,7 +2194,25 @@ "coriandre" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bund Koriander", + "other": "Bund Koriander" + }, + "en": { + "one": "Bunch of coriander", + "other": "Bunches of coriander" + }, + "fr": { + "one": "Bouquet de coriandre", + "other": "Bouquets de coriandre" + }, + "es": { + "one": "Manojo de cilantro", + "other": "Manojos de cilantro" + } + } }, { "key": "mint", @@ -1513,7 +2233,25 @@ "menta" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bund Minze", + "other": "Bund Minze" + }, + "en": { + "one": "Bunch of mint", + "other": "Bunches of mint" + }, + "fr": { + "one": "Bouquet de menthe", + "other": "Bouquets de menthe" + }, + "es": { + "one": "Manojo de hierbabuena", + "other": "Manojos de hierbabuena" + } + } }, { "key": "rosemary", @@ -1534,7 +2272,25 @@ "romero fresco" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Zweig Rosmarin", + "other": "Zweige Rosmarin" + }, + "en": { + "one": "Sprig of rosemary", + "other": "Sprigs of rosemary" + }, + "fr": { + "one": "Brin de romarin", + "other": "Brins de romarin" + }, + "es": { + "one": "Ramita de romero", + "other": "Ramitas de romero" + } + } }, { "key": "thyme", @@ -1555,7 +2311,25 @@ "tomillo fresco" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Zweig Thymian", + "other": "Zweige Thymian" + }, + "en": { + "one": "Sprig of thyme", + "other": "Sprigs of thyme" + }, + "fr": { + "one": "Brin de thym", + "other": "Brins de thym" + }, + "es": { + "one": "Ramita de tomillo", + "other": "Ramitas de tomillo" + } + } }, { "key": "sage", @@ -1574,7 +2348,25 @@ "sage leaves" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Salbeiblatt", + "other": "Salbeiblätter" + }, + "en": { + "one": "Sage leaf", + "other": "Sage leaves" + }, + "fr": { + "one": "Feuille de sauge", + "other": "Feuilles de sauge" + }, + "es": { + "one": "Hoja de salvia", + "other": "Hojas de salvia" + } + } }, { "key": "lemongrass", @@ -1594,7 +2386,25 @@ "limoncillo" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Stange Zitronengras", + "other": "Stangen Zitronengras" + }, + "en": { + "one": "Lemongrass stalk", + "other": "Lemongrass stalks" + }, + "fr": { + "one": "Tige de citronnelle", + "other": "Tiges de citronnelle" + }, + "es": { + "one": "Tallo de hierba limón", + "other": "Tallos de hierba limón" + } + } }, { "key": "bread", @@ -1696,7 +2506,25 @@ 6, 10 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Brötchen", + "other": "Brötchen" + }, + "en": { + "one": "Bread roll", + "other": "Bread rolls" + }, + "fr": { + "one": "Petit pain", + "other": "Petits pains" + }, + "es": { + "one": "Panecillo", + "other": "Panecillos" + } + } }, { "key": "baguette", @@ -1719,7 +2547,25 @@ 1, 2 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Baguette", + "other": "Baguettes" + }, + "en": { + "one": "Baguette", + "other": "Baguettes" + }, + "fr": { + "one": "Baguette", + "other": "Baguettes" + }, + "es": { + "one": "Barra de pan", + "other": "Barras de pan" + } + } }, { "key": "tortilla_wraps", @@ -1744,7 +2590,25 @@ 6, 8 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Tortilla-Wrap", + "other": "Tortilla-Wraps" + }, + "en": { + "one": "Tortilla wrap", + "other": "Tortilla wraps" + }, + "fr": { + "one": "Tortilla de blé", + "other": "Tortillas de blé" + }, + "es": { + "one": "Tortilla de trigo", + "other": "Tortillas de trigo" + } + } }, { "key": "burger_buns", @@ -1766,7 +2630,25 @@ 4, 6 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Burgerbrötchen", + "other": "Burgerbrötchen" + }, + "en": { + "one": "Burger bun", + "other": "Burger buns" + }, + "fr": { + "one": "Pain à burger", + "other": "Pains à burger" + }, + "es": { + "one": "Pan de hamburguesa", + "other": "Panes de hamburguesa" + } + } }, { "key": "pita_bread", @@ -1789,7 +2671,25 @@ 4, 6 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Fladenbrot", + "other": "Fladenbrote" + }, + "en": { + "one": "Pitta bread", + "other": "Pitta breads" + }, + "fr": { + "one": "Pain pita", + "other": "Pains pita" + }, + "es": { + "one": "Pan de pita", + "other": "Panes de pita" + } + } }, { "key": "ground_beef", @@ -2517,7 +3417,25 @@ 6, 10 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Wiener Würstchen", + "other": "Wiener Würstchen" + }, + "en": { + "one": "Frankfurter", + "other": "Frankfurters" + }, + "fr": { + "one": "Saucisse de Francfort", + "other": "Saucisses de Francfort" + }, + "es": { + "one": "Salchicha de Frankfurt", + "other": "Salchichas de Frankfurt" + } + } }, { "key": "bratwurst", @@ -2543,7 +3461,25 @@ 5, 6 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Bratwurst", + "other": "Bratwürste" + }, + "en": { + "one": "Bratwurst", + "other": "Bratwursts" + }, + "fr": { + "one": "Saucisse à griller", + "other": "Saucisses à griller" + }, + "es": { + "one": "Salchicha alemana", + "other": "Salchichas alemanas" + } + } }, { "key": "pork_sausages", @@ -2568,7 +3504,25 @@ 8, 12 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Schweinswürstchen", + "other": "Schweinswürstchen" + }, + "en": { + "one": "Pork sausage", + "other": "Pork sausages" + }, + "fr": { + "one": "Saucisse de porc", + "other": "Saucisses de porc" + }, + "es": { + "one": "Salchicha de cerdo", + "other": "Salchichas de cerdo" + } + } }, { "key": "smoked_sausage", @@ -2594,7 +3548,25 @@ 2, 4 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Mettende", + "other": "Mettenden" + }, + "en": { + "one": "Smoked sausage", + "other": "Smoked sausages" + }, + "fr": { + "one": "Saucisse fumée", + "other": "Saucisses fumées" + }, + "es": { + "one": "Salchicha ahumada", + "other": "Salchichas ahumadas" + } + } }, { "key": "liver_sausage", @@ -3501,7 +4473,25 @@ 6, 10 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Ei", + "other": "Eier" + }, + "en": { + "one": "Egg", + "other": "Eggs" + }, + "fr": { + "one": "Œuf", + "other": "Œufs" + }, + "es": { + "one": "Huevo", + "other": "Huevos" + } + } }, { "key": "tofu", @@ -3617,7 +4607,25 @@ 6, 8 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Maultasche", + "other": "Maultaschen" + }, + "en": { + "one": "Maultasche (Swabian ravioli)", + "other": "Maultaschen (Swabian ravioli)" + }, + "fr": { + "one": "Ravioli souabe", + "other": "Raviolis souabes" + }, + "es": { + "one": "Ravioli suabo", + "other": "Raviolis suabos" + } + } }, { "key": "spaetzle", @@ -3943,7 +4951,25 @@ 15, 30 ], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Fischstäbchen", + "other": "Fischstäbchen" + }, + "en": { + "one": "Fish finger", + "other": "Fish fingers" + }, + "fr": { + "one": "Bâtonnet de poisson", + "other": "Bâtonnets de poisson" + }, + "es": { + "one": "Palito de pescado", + "other": "Palitos de pescado" + } + } }, { "key": "frozen_fish_fillet", @@ -5386,7 +6412,25 @@ 8, 12 ], - "pantry": true + "pantry": true, + "forms": { + "de": { + "one": "Brühwürfel", + "other": "Brühwürfel" + }, + "en": { + "one": "Stock cube", + "other": "Stock cubes" + }, + "fr": { + "one": "Cube de bouillon", + "other": "Cubes de bouillon" + }, + "es": { + "one": "Pastilla de caldo", + "other": "Pastillas de caldo" + } + } }, { "key": "gravy", @@ -6228,7 +7272,25 @@ "laurel" ], "packs": [], - "pantry": true + "pantry": true, + "forms": { + "de": { + "one": "Lorbeerblatt", + "other": "Lorbeerblätter" + }, + "en": { + "one": "Bay leaf", + "other": "Bay leaves" + }, + "fr": { + "one": "Feuille de laurier", + "other": "Feuilles de laurier" + }, + "es": { + "one": "Hoja de laurel", + "other": "Hojas de laurel" + } + } }, { "key": "cloves", @@ -6248,7 +7310,25 @@ "clavo" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Gewürznelke", + "other": "Gewürznelken" + }, + "en": { + "one": "Clove", + "other": "Cloves" + }, + "fr": { + "one": "Clou de girofle", + "other": "Clous de girofle" + }, + "es": { + "one": "Clavo de olor", + "other": "Clavos de olor" + } + } }, { "key": "juniper_berries", @@ -6266,7 +7346,25 @@ "juniper" ], "packs": [], - "pantry": false + "pantry": false, + "forms": { + "de": { + "one": "Wacholderbeere", + "other": "Wacholderbeeren" + }, + "en": { + "one": "Juniper berry", + "other": "Juniper berries" + }, + "fr": { + "one": "Baie de genièvre", + "other": "Baies de genièvre" + }, + "es": { + "one": "Baya de enebro", + "other": "Bayas de enebro" + } + } }, { "key": "ground_ginger", @@ -7948,6 +9046,24 @@ 40, 80 ], - "pantry": true + "pantry": true, + "forms": { + "de": { + "one": "Beutel Schwarztee", + "other": "Beutel Schwarztee" + }, + "en": { + "one": "Black tea bag", + "other": "Black tea bags" + }, + "fr": { + "one": "Sachet de thé noir", + "other": "Sachets de thé noir" + }, + "es": { + "one": "Bolsita de té negro", + "other": "Bolsitas de té negro" + } + } } ] diff --git a/e2e/gerichte.spec.ts b/e2e/gerichte.spec.ts index 1674ea7..1f62d9a 100644 --- a/e2e/gerichte.spec.ts +++ b/e2e/gerichte.spec.ts @@ -30,10 +30,16 @@ test("a dish scales its ingredients with the portions", async ({ page }) => { await expect(page.getByRole("heading", { level: 1 })).toHaveText("Spaghetti Bolognese"); const spaghetti = page.locator("li", { hasText: "Spaghetti" }).first(); await expect(spaghetti).toContainText("250 g"); + // Stück in Einzahl und Mehrzahl, je nach Menge. + const garlic = page.locator("li", { hasText: "Knoblauch" }).first(); + await expect(page.locator("li", { hasText: "Zwiebel" }).first()).toContainText("½Zwiebel"); + await expect(garlic).toContainText("1Knoblauchzehe"); await page.getByRole("button", { name: "Eine Portion mehr" }).click(); await page.getByRole("button", { name: "Eine Portion mehr" }).click(); await expect(page.locator("output")).toHaveText("4 Portionen"); await expect(spaghetti).toContainText("500 g"); + await expect(garlic).toContainText("2Knoblauchzehen"); + await expect(page.locator("li", { hasText: "Zwiebel" }).first()).toContainText("1Zwiebel"); }); test("an own dish is created with searched ingredients, then edited", async ({ page }) => { @@ -52,8 +58,8 @@ test("an own dish is created with searched ingredients, then edited", async ({ p await page.getByRole("button", { name: "Speichern" }).click(); await expect(page.getByRole("heading", { level: 1 })).toHaveText("Gemüsecurry"); await expect(page.locator("main")).toContainText("vegetarisch"); - // 2 Zwiebeln für 4 Portionen → 1 für 2 Portionen. - await expect(page.locator("ul li", { hasText: "Zwiebeln" })).toContainText("1"); + // 2 Zwiebeln für 4 Portionen → 1 Zwiebel für 2 Portionen (Einzahl). + await expect(page.locator("ul li", { hasText: "Zwiebel" })).toContainText(/^1\s*Zwiebel$/); await expect(page.locator("ul li", { hasText: "Kokosmilch" })).toContainText("200 ml"); await page.getByRole("link", { name: "Bearbeiten" }).click(); diff --git a/lib/dishes.ts b/lib/dishes.ts index c319bef..2586be2 100644 --- a/lib/dishes.ts +++ b/lib/dishes.ts @@ -51,7 +51,16 @@ export type DishSummary = { export type DishDetail = DishSummary & { sourceUrl: string | null; - ingredients: { ingredientId: string; name: string; qtyPerPortion: number; unit: BaseUnit; note: string | null; isStaple: boolean }[]; + ingredients: { + ingredientId: string; + name: string; + // Einzahl/Mehrzahl bei Stück („1 Zwiebel“, „2 Zwiebeln“), lib/ingredient-name.ts + forms: { one: string; other: string } | null; + qtyPerPortion: number; + unit: BaseUnit; + note: string | null; + isStaple: boolean; + }[]; steps: { text: string; timerSeconds: number | null }[]; }; @@ -67,7 +76,7 @@ export async function getDish(client: PoolClient, id: string, locale: string): P const dish = (await client.query(`select ${summaryColumns}, source_url as "sourceUrl" from dishes where id = $1 and archived_at is null`, [id])) .rows[0]; if (!dish) return null; - const names = new Map((await allIngredients()).map((i) => [i.id, i.names[locale] ?? i.names.en ?? ""])); + const entries = new Map((await allIngredients()).map((i) => [i.id, i])); const ingredients = ( await client.query( "select ingredient_id, qty_per_portion, unit, note, is_staple from dish_ingredients where dish_id = $1 order by position", @@ -75,7 +84,8 @@ export async function getDish(client: PoolClient, id: string, locale: string): P ) ).rows.map((r) => ({ ingredientId: r.ingredient_id, - name: names.get(r.ingredient_id) ?? "", + name: entries.get(r.ingredient_id)?.names[locale] ?? entries.get(r.ingredient_id)?.names.en ?? "", + forms: entries.get(r.ingredient_id)?.forms?.[locale] ?? entries.get(r.ingredient_id)?.forms?.en ?? null, qtyPerPortion: Number(r.qty_per_portion), unit: r.unit, note: r.note, diff --git a/lib/ingredient-name.ts b/lib/ingredient-name.ts new file mode 100644 index 0000000..5e51262 --- /dev/null +++ b/lib/ingredient-name.ts @@ -0,0 +1,24 @@ +// Wie eine Zutat bei einer Menge heißt. Bei Stück zählt die Zahl: „1 Zwiebel“, +// „½ Zitrone“, aber „2 Zwiebeln“, „1½ Zitronen“. Gewicht und Volumen behalten den +// Listennamen („500 g Kartoffeln“). Die Formen kommen aus dem Seed (ingredients.forms). + +export type Forms = Partial>; + +export type Nameable = { names: Record; forms?: Forms | null; unit: "g" | "ml" | "piece" }; + +/** Einzahl bis einschließlich 1 — also auch für ½ und ¼. */ +export const isOne = (qty: number) => qty > 0 && qty <= 1 + 1e-9; + +/** Für Anzeigen, die Name und Formen schon in der Sprache haben (Gerichtsseite, Kochmodus). */ +export function labelFor(i: { name: string; forms: { one: string; other: string } | null; unit: string }, qty: number): string { + if (i.unit !== "piece" || !i.forms) return i.name; + return isOne(qty) ? i.forms.one : i.forms.other; +} + +export function ingredientLabel(entry: Nameable, locale: string, qty: number | null): string { + const list = entry.names[locale] ?? entry.names.en ?? ""; + if (entry.unit !== "piece" || qty === null) return list; + const f = entry.forms?.[locale] ?? entry.forms?.en; + if (!f) return list; + return isOne(qty) ? f.one : f.other; +} diff --git a/lib/ingredient-search.ts b/lib/ingredient-search.ts index 0fe7686..71939c6 100644 --- a/lib/ingredient-search.ts +++ b/lib/ingredient-search.ts @@ -9,6 +9,7 @@ export type IngredientEntry = { category: string; names: Record; synonyms: string[]; + forms?: Partial> | null; }; export function normalize(text: string): string { @@ -28,9 +29,12 @@ export function searchIngredients(list: IngredientEntry[], query: string, locale const scored: { entry: IngredientEntry; score: number }[] = []; for (const entry of list) { const name = normalize(entry.names[locale] ?? entry.names.en ?? ""); + const one = normalize(entry.forms?.[locale]?.one ?? ""); let score = 0; if (name === q) score = 100; + else if (one === q) score = 95; // „Ei“ findet „Eier“, „Apfel“ findet „Äpfel“ else if (name.startsWith(q)) score = 80; + else if (one.startsWith(q)) score = 75; else if (name.split(" ").some((w) => w.startsWith(q))) score = 60; else if (name.includes(q)) score = 40; else if (entry.synonyms.some((s) => normalize(s).startsWith(q))) score = 30; diff --git a/lib/ingredients.ts b/lib/ingredients.ts index 2ab7e8b..b6f6099 100644 --- a/lib/ingredients.ts +++ b/lib/ingredients.ts @@ -8,7 +8,7 @@ let cache: Promise | null = null; export function allIngredients(): Promise { cache ??= pool - .query("select id, key, default_unit as unit, category, names, synonyms from ingredients order by key") + .query("select id, key, default_unit as unit, category, names, synonyms, forms from ingredients order by key") .then((r) => r.rows as IngredientEntry[]) .catch((error) => { cache = null; diff --git a/lib/shopping.ts b/lib/shopping.ts index a71b54a..2328a5d 100644 --- a/lib/shopping.ts +++ b/lib/shopping.ts @@ -1,6 +1,7 @@ import "server-only"; import type { PoolClient } from "pg"; import { aggregate, withPacks, type PlanSlotInput } from "./aggregate"; +import { labelFor } from "./ingredient-name"; import type { Round } from "./rounds"; // Einkaufsliste einer Runde: aus dem Plan abgeglichen, abgehakt von allen, @@ -45,7 +46,8 @@ export async function syncList(client: PoolClient, householdId: string, round: R `select s.id as slot, d.title, s.portions, di.ingredient_id, di.qty_per_portion::float as q, di.unit, i.category, i.pack_sizes::float[] as packs, (i.pantry_default or exists (select 1 from pantry_staples p where p.ingredient_id = i.id)) as pantry, - coalesce(i.names ->> $2, i.names ->> 'de', i.key) as name + coalesce(i.names ->> $2, i.names ->> 'de', i.key) as name, + coalesce(i.forms -> $2, i.forms -> 'en') as form from slots s join dishes d on d.id = s.dish_id join dish_ingredients di on di.dish_id = d.id join ingredients i on i.id = di.ingredient_id @@ -56,11 +58,13 @@ export async function syncList(client: PoolClient, householdId: string, round: R ).rows; const bySlot = new Map(); const packs = new Map(); + const forms = new Map(); for (const r of rows) { const slot: PlanSlotInput = bySlot.get(r.slot) ?? { dishTitle: r.title, portions: r.portions, ingredients: [] }; slot.ingredients.push({ ingredientId: r.ingredient_id, name: r.name, unit: r.unit, qtyPerPortion: r.q, category: r.category, packs: r.packs, pantry: r.pantry }); bySlot.set(r.slot, slot); packs.set(r.ingredient_id, r.packs ?? []); + if (r.form) forms.set(r.ingredient_id, r.form); } const lines = withPacks(aggregate([...bySlot.values()], await defaultAisles(client)), (id) => packs.get(id) ?? []); for (const l of lines) { @@ -73,7 +77,7 @@ export async function syncList(client: PoolClient, householdId: string, round: R pack_count = excluded.pack_count, pack_size = excluded.pack_size, dishes = excluded.dishes, aisle_position = excluded.aisle_position, pantry_state = case when excluded.pantry_state is null then null else coalesce(shopping_items.pantry_state, 'ask') end`, - [householdId, round.id, l.ingredientId, l.name, l.qty, l.needed, l.unit, l.pack?.count ?? null, l.pack?.size ?? null, + [householdId, round.id, l.ingredientId, labelFor({ name: l.name, forms: forms.get(l.ingredientId) ?? null, unit: l.unit }, l.qty), l.qty, l.needed, l.unit, l.pack?.count ?? null, l.pack?.size ?? null, l.dishes, l.aislePosition, l.pantry ? "ask" : null], ); } diff --git a/olares/Chart.yaml b/olares/Chart.yaml index f1a9b7c..01f7abb 100644 --- a/olares/Chart.yaml +++ b/olares/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: lunch description: Was gibt's? — die Familie entscheidet gemeinsam, was es gibt; aus dem Plan entsteht die Einkaufsliste type: application -version: 26.11.14 # YY.M. wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen -appVersion: "26.11.14" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran +version: 26.11.15 # YY.M. wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen +appVersion: "26.11.15" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran diff --git a/olares/OlaresManifest.yaml b/olares/OlaresManifest.yaml index 4b0a772..af38680 100644 --- a/olares/OlaresManifest.yaml +++ b/olares/OlaresManifest.yaml @@ -21,7 +21,7 @@ metadata: title: What's cooking? description: The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box. icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png - version: 26.11.14 + version: 26.11.15 categories: - Applications @@ -61,7 +61,7 @@ permission: appData: true spec: - versionName: '26.11.14' + versionName: '26.11.15' featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png promoteImage: diff --git a/olares/markt/26.11.15.md b/olares/markt/26.11.15.md new file mode 100644 index 0000000..015d395 --- /dev/null +++ b/olares/markt/26.11.15.md @@ -0,0 +1,5 @@ +# One onion, two onions +v26.11.15: Ingredients counted in pieces now read naturally in every language: "1 onion", "½ lemon", "3 garlic cloves" — on the dish page as you change the portions, in cooking mode and on the shopping list. Searching for the singular ("egg", "apple") finds the ingredient too. + +## Deutsch +v26.11.15: Zutaten, die man in Stück zählt, lesen sich jetzt in jeder Sprache richtig: „1 Zwiebel“, „½ Zitrone“, „3 Knoblauchzehen“ — am Gericht beim Ändern der Portionen, im Kochmodus und auf der Einkaufsliste. Die Suche findet sie auch in der Einzahl („Ei“, „Apfel“). diff --git a/scripts/seed.mjs b/scripts/seed.mjs index 523677e..db93e5f 100644 --- a/scripts/seed.mjs +++ b/scripts/seed.mjs @@ -41,13 +41,13 @@ export async function seed(client) { await client.query("select set_config('app.maintenance', 'on', true)"); if (ingredients.length) { await client.query( - `insert into ingredients (id, key, category, default_unit, names, synonyms, freshness, pack_sizes, pantry_default) - select x.id, x.key, x.category, x.unit, x.names, x.synonyms, x.freshness, x.packs, x.pantry + `insert into ingredients (id, key, category, default_unit, names, synonyms, freshness, pack_sizes, pantry_default, forms) + select x.id, x.key, x.category, x.unit, x.names, x.synonyms, x.freshness, x.packs, x.pantry, coalesce(x.forms, '{}') from jsonb_to_recordset($1::jsonb) as x(id uuid, key text, category text, unit text, names jsonb, - synonyms text[], freshness smallint, packs numeric[], pantry boolean) + synonyms text[], freshness smallint, packs numeric[], pantry boolean, forms jsonb) on conflict (key) do update set category = excluded.category, default_unit = excluded.default_unit, names = excluded.names, synonyms = excluded.synonyms, freshness = excluded.freshness, - pack_sizes = excluded.pack_sizes, pantry_default = excluded.pantry_default`, + pack_sizes = excluded.pack_sizes, pantry_default = excluded.pantry_default, forms = excluded.forms`, [JSON.stringify(ingredients.map((i) => ({ ...i, id: idByKey.get(i.key) })))], ); } diff --git a/tests/ingredient-name.test.ts b/tests/ingredient-name.test.ts new file mode 100644 index 0000000..49b5de0 --- /dev/null +++ b/tests/ingredient-name.test.ts @@ -0,0 +1,31 @@ +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; +import { ingredientLabel, type Nameable } from "@/lib/ingredient-name"; + +const seed: (Nameable & { key: string })[] = JSON.parse(readFileSync("db/seed/ingredients.json", "utf8")); +const byKey = (k: string) => seed.find((i) => i.key === k)!; + +describe("ingredient names with amounts", () => { + it("uses the singular up to one piece and the plural above", () => { + expect(ingredientLabel(byKey("onion"), "de", 1)).toBe("Zwiebel"); + expect(ingredientLabel(byKey("onion"), "de", 0.5)).toBe("Zwiebel"); + expect(ingredientLabel(byKey("onion"), "de", 3)).toBe("Zwiebeln"); + expect(ingredientLabel(byKey("garlic"), "de", 3)).toBe("Knoblauchzehen"); + expect(ingredientLabel(byKey("egg"), "en", 1)).toBe("Egg"); + expect(ingredientLabel(byKey("egg"), "fr", 2)).toBe("Œufs"); + expect(ingredientLabel(byKey("lemon"), "es", 1.5)).toBe("Limones"); + }); + + it("keeps the list name for weight and volume, and without an amount", () => { + expect(ingredientLabel(byKey("potato"), "de", 500)).toBe("Kartoffeln"); + expect(ingredientLabel(byKey("onion"), "de", null)).toBe("Zwiebeln"); + }); + + it("every ingredient counted in pieces has both forms in all four languages", () => { + const missing = seed + .filter((i) => i.unit === "piece") + .filter((i) => ["de", "en", "fr", "es"].some((l) => !i.forms?.[l]?.one || !i.forms?.[l]?.other)) + .map((i) => i.key); + expect(missing).toEqual([]); + }); +});