Files
lunch/lib/use-kitchen-amount.ts
kai 10831c7f65
release / which version (push) Successful in 3s
release / olares chart · sanity (push) Successful in 4s
release / app (push) Successful in 1m15s
release / tag and release (push) Successful in 5s
26.11.50: ml und l bei jeder Zutat (#51)
2026-11-08 17:44:20 +00:00

30 lines
1.1 KiB
TypeScript

"use client";
import { useLocale, useTranslations } from "next-intl";
import { isOne } from "./ingredient-name";
import { formatKitchen, type BaseUnit, type DisplayUnit, type KitchenUnit } from "./units";
/** Was eine Zutat für die Mengenanzeige mitbringt (lib/dishes.ts, getDish). */
export type Measured = {
unit: BaseUnit;
displayUnit?: DisplayUnit | null;
packSize?: number | null;
};
/**
* Menge mit Küchenmaß in der Sprache der Person (26.11.39): „2 EL (30 ml)“,
* „400 g (1 Dose)“. Liefert Hauptteil und Klammer getrennt, damit Listen sie
* verschieden setzen können; text() fügt beides zusammen.
*/
export function useKitchenAmount() {
const locale = useLocale();
const tm = useTranslations("measure");
const word = (u: KitchenUnit, n: number) => tm(u, { n: isOne(n) ? 1 : 2 });
const parts = (i: Measured, qty: number) => formatKitchen(qty, i.unit, i.displayUnit, i.packSize, locale, word);
const text = (i: Measured, qty: number) => {
const p = parts(i, qty);
return p.extra ? `${p.main} (${p.extra})` : p.main;
};
return { parts, text };
}