2154512e54
Recipe cards, the recipe detail page, and meal planner still rendered raw
"{n} servings"/"{n}m cook"/"{n} srv" text and untranslated difficulty labels
outside the earlier i18n pass. Also wires the user's locale into AI features
that previously always answered in English regardless of app language:
recipe chat, ingredient substitution, recipe ideas, and generate-from-idea.
The recipe-language picker in the AI generate dialog now defaults to the
user's locale instead of always defaulting to English.
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { generateObject } from "ai";
|
|
import { z } from "zod";
|
|
import { resolveModel, type AiConfig } from "../factory";
|
|
|
|
const SubstitutionsSchema = z.object({
|
|
substitutions: z.array(z.object({
|
|
name: z.string(),
|
|
ratio: z.string(),
|
|
note: z.string(),
|
|
flavorImpact: z.enum(["minimal", "moderate", "significant"]),
|
|
})),
|
|
});
|
|
|
|
export type Substitution = z.infer<typeof SubstitutionsSchema>["substitutions"][number];
|
|
|
|
const LANG: Record<string, string> = { en: "English", fr: "French" };
|
|
|
|
export async function substituteIngredient(
|
|
ingredient: string,
|
|
recipeContext: string,
|
|
config?: AiConfig,
|
|
locale?: string
|
|
): Promise<Substitution[]> {
|
|
const model = resolveModel(config);
|
|
const lang = LANG[locale ?? "en"] ?? "English";
|
|
|
|
const { object } = await generateObject({
|
|
model,
|
|
schema: SubstitutionsSchema,
|
|
system:
|
|
`You are a professional chef specializing in ingredient substitutions. Provide practical, commonly available substitutes. For each substitute: name what to use, the ratio (e.g. '1:1', '3/4 the amount'), and a brief note on technique adjustments. Rate the flavor impact honestly. Respond in ${lang}.`,
|
|
prompt: `Suggest 3-4 substitutes for "${ingredient}" in this recipe context: ${recipeContext}`,
|
|
});
|
|
|
|
return object.substitutions;
|
|
}
|