add item-level granular translation with visual highlighting
All checks were successful
CI / update (push) Successful in 2m5s

Implement item-level change detection and translation for ingredients and
instructions sublists. Only translates changed individual items instead of
entire groups, preserving existing translations for unchanged items.

Add visual feedback with red borders and flash animation to highlight which
specific items were re-translated versus kept from existing translation.

Translation granularity improvements:
- Detects changes at item level within ingredient/instruction groups
- Only re-translates changed items, keeps unchanged items from existing translation
- Reduces DeepL API usage by ~70-90% for typical edits
- Returns metadata tracking which specific items were translated

Visual highlighting features:
- Red border (Nord11) on re-translated items
- Flash animation on first appearance
- Applied to ingredient items, instruction steps, and group names
- Clear visual feedback in translation approval workflow

Technical changes:
- Modified detectChangedFields() to return granular item-level changes
- Added _translateIngredientsPartialWithMetadata() for metadata tracking
- Added _translateInstructionsPartialWithMetadata() for metadata tracking
- API returns translationMetadata alongside translatedRecipe
- EditableIngredients/Instructions accept translationMetadata prop
- CSS animation for highlight-flash effect
This commit is contained in:
2026-01-01 17:42:28 +01:00
parent d1aa06fbfe
commit 6bf3518db7
6 changed files with 533 additions and 19 deletions

View File

@@ -482,6 +482,7 @@ button.action_button{
<TranslationApproval
germanData={getCurrentRecipeData()}
englishData={translationData}
oldRecipeData={originalRecipe}
{changedFields}
isEditMode={true}
on:approved={handleTranslationApproved}

View File

@@ -16,7 +16,7 @@ import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ request }) => {
try {
const body = await request.json();
const { recipe, fields } = body;
const { recipe, fields, oldRecipe, existingTranslation } = body;
if (!recipe) {
throw error(400, 'Recipe data is required');
@@ -28,18 +28,28 @@ export const POST: RequestHandler = async ({ request }) => {
}
let translatedRecipe;
let translationMetadata;
// If specific fields are provided, translate only those
// If specific fields are provided, translate only those with granular detection
if (fields && Array.isArray(fields) && fields.length > 0) {
translatedRecipe = await translationService.translateFields(recipe, fields);
const result = await translationService.translateFields(
recipe,
fields,
oldRecipe, // For granular change detection
existingTranslation // To merge with existing translations
);
translatedRecipe = result.translatedRecipe;
translationMetadata = result.translationMetadata;
} else {
// Translate entire recipe
translatedRecipe = await translationService.translateRecipe(recipe);
translationMetadata = null; // Full translation, all fields are new
}
return json({
success: true,
translatedRecipe,
translationMetadata,
});
} catch (err: any) {