feat(i18n): localize all translate components (spec 028)

P0 — Wired i18n to 4 previously-unlocalized surfaces:
- BulkReplaceModal (~25 strings → translate.bulk_replace.*)
- CorrectionCell (~20 strings → translate.corrections.cell_*)
- TermCorrectionPopup (~30 strings → translate.term_correction.*)
- history/+page.svelte (~50 strings → translate.history.*)

P1 — Added 85+ keys to en.json + ru.json (identical structures):
- 11 previously-missing keys (common.close, config.status, etc.)
- bulk_replace.*, corrections.*, term_correction.*, history.*, dictionaries.*

P2 — Dictionary detail page: import form, filter-by-language, context display
P3 — Russian hardcoded strings in job config replaced with i18n

Tests: 280 pass, build succeeds
This commit is contained in:
2026-05-15 09:00:33 +03:00
parent 77d55c8e69
commit 30d7f3f725
10 changed files with 636 additions and 258 deletions

View File

@@ -15,6 +15,7 @@
<script>
import { addToast } from '$lib/toasts.js';
import { bulkFindReplace, bulkReplacePreview } from '$lib/api/translate.js';
import { t, _ } from '$lib/i18n';
/** @type {{ show: boolean, runId: string, targetLanguages: string[], onClose: () => void, onApplied?: (count: number) => void }} */
let {
@@ -58,11 +59,11 @@
/** Preview affected records */
async function handlePreview() {
if (!findPattern.trim()) {
addToast('Please enter a find pattern', 'warning');
addToast(_('translate.bulk_replace.find_pattern_required'), 'warning');
return;
}
if (!targetLanguage) {
addToast('Please select a target language', 'warning');
addToast(_('translate.bulk_replace.target_language_required'), 'warning');
return;
}
uxState = 'previewing';
@@ -78,7 +79,7 @@
applyCount = affectedRecords.length;
uxState = 'previewing';
} catch (err) {
errorMessage = err?.message || 'Failed to preview replacements';
errorMessage = err?.message || _('translate.bulk_replace.preview_failed');
uxState = 'preview_error';
addToast(errorMessage, 'error');
}
@@ -110,9 +111,9 @@
const changed = result?.changed || result?.affected || applyCount;
uxState = 'applied';
onApplied(changed);
addToast(`Bulk replace applied to ${changed} records`, 'success');
addToast(_('translate.bulk_replace.applied_toast').replace('{count}', changed), 'success');
} catch (err) {
errorMessage = err?.message || 'Failed to apply bulk replace';
errorMessage = err?.message || _('translate.bulk_replace.apply_failed');
uxState = 'apply_error';
addToast(errorMessage, 'error');
}
@@ -146,15 +147,15 @@
onclick={(e) => e.stopPropagation()}
role="dialog"
aria-modal="true"
aria-label="Bulk Find & Replace"
aria-label={$t.translate?.bulk_replace?.title}
>
<!-- Header -->
<div class="flex items-center justify-between px-6 py-4 border-b border-gray-200 flex-shrink-0">
<h2 class="text-lg font-semibold text-gray-900">Bulk Find & Replace</h2>
<h2 class="text-lg font-semibold text-gray-900">{$t.translate?.bulk_replace?.title}</h2>
<button
onclick={handleClose}
class="p-1 text-gray-400 hover:text-gray-600 rounded-lg hover:bg-gray-100 transition-colors"
aria-label="Close"
aria-label={$t.translate?.bulk_replace?.close}
>
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
@@ -169,12 +170,12 @@
{#if uxState === 'configuring' || uxState === 'previewing' || uxState === 'preview_error'}
<!-- Find Pattern -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Find pattern</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.bulk_replace?.find_pattern}</label>
<div class="flex gap-2">
<input
type="text"
bind:value={findPattern}
placeholder="Enter text or regex pattern..."
placeholder={$t.translate?.bulk_replace?.find_placeholder}
class="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
onkeydown={(e) => e.key === 'Enter' && handlePreview()}
/>
@@ -185,18 +186,18 @@
class="rounded"
/>
<span class="text-gray-600 font-mono text-xs">.*</span>
<span class="text-gray-600 text-xs">Regex</span>
<span class="text-gray-600 text-xs">{$t.translate?.bulk_replace?.regex}</span>
</label>
</div>
</div>
<!-- Replacement Text -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Replace with</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.bulk_replace?.replace_with}</label>
<input
type="text"
bind:value={replacementText}
placeholder="Replacement text..."
placeholder={$t.translate?.bulk_replace?.replace_placeholder}
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
onkeydown={(e) => e.key === 'Enter' && handlePreview()}
/>
@@ -204,12 +205,12 @@
<!-- Target Language -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Target language</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.bulk_replace?.target_language}</label>
<select
bind:value={targetLanguage}
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
>
<option value="">Select language...</option>
<option value="">{$t.translate?.bulk_replace?.select_language}</option>
{#each targetLanguages as lang}
<option value={lang}>{lang}</option>
{/each}
@@ -222,7 +223,7 @@
disabled={!findPattern.trim() || !targetLanguage}
class="w-full px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 transition-colors text-sm font-medium"
>
Preview Affected Rows
{$t.translate?.bulk_replace?.preview_affected}
</button>
{/if}
@@ -238,22 +239,22 @@
<div>
<div class="flex items-center justify-between mb-2">
<h3 class="text-sm font-medium text-gray-700">
Preview: {affectedRecords.length} affected record{affectedRecords.length !== 1 ? 's' : ''}
{$t.translate?.bulk_replace?.preview_count.replace('{count}', affectedRecords.length)}
</h3>
<button
onclick={handleShowConfirm}
class="px-4 py-1.5 bg-amber-600 text-white rounded-lg hover:bg-amber-700 transition-colors text-sm font-medium"
>
Apply Changes
{$t.translate?.bulk_replace?.apply_changes}
</button>
</div>
<div class="max-h-60 overflow-y-auto border border-gray-200 rounded-lg">
<table class="min-w-full divide-y divide-gray-200 text-xs">
<thead class="bg-gray-50 sticky top-0">
<tr>
<th class="px-3 py-2 text-left font-medium text-gray-500 uppercase">#</th>
<th class="px-3 py-2 text-left font-medium text-gray-500 uppercase">Before</th>
<th class="px-3 py-2 text-left font-medium text-gray-500 uppercase">After</th>
<th class="px-3 py-2 text-left font-medium text-gray-500 uppercase">{$t.translate?.bulk_replace?.table_number}</th>
<th class="px-3 py-2 text-left font-medium text-gray-500 uppercase">{$t.translate?.bulk_replace?.table_before}</th>
<th class="px-3 py-2 text-left font-medium text-gray-500 uppercase">{$t.translate?.bulk_replace?.table_after}</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@@ -268,7 +269,7 @@
</table>
{#if affectedRecords.length > 100}
<div class="px-3 py-2 text-xs text-gray-400 bg-gray-50 border-t border-gray-200">
Showing first 100 of {affectedRecords.length} records. Apply to see all changes.
{$t.translate?.bulk_replace?.showing_first.replace('{shown}', 100).replace('{total}', affectedRecords.length)}
</div>
{/if}
</div>
@@ -277,8 +278,8 @@
{#if uxState === 'previewing' && affectedRecords.length === 0}
<div class="bg-gray-50 border border-gray-200 rounded-lg p-6 text-center">
<p class="text-sm text-gray-500">No matching records found.</p>
<p class="text-xs text-gray-400 mt-1">Try a different pattern or target language.</p>
<p class="text-sm text-gray-500">{$t.translate?.bulk_replace?.no_matching}</p>
<p class="text-xs text-gray-400 mt-1">{$t.translate?.bulk_replace?.no_matching_hint}</p>
</div>
{/if}
@@ -291,23 +292,22 @@
</svg>
<div class="flex-1">
<p class="text-sm font-medium text-amber-800">
Apply {applyCount} replacement{applyCount !== 1 ? 's' : ''}?
{$t.translate?.bulk_replace?.confirm_title.replace('{count}', applyCount)}
</p>
<p class="text-xs text-amber-700 mt-1">
This will modify the translated values in {targetLanguage}.
This action cannot be undone.
{$t.translate?.bulk_replace?.confirm_body.replace('{language}', targetLanguage)}
</p>
<!-- Submit to Dictionary checkbox -->
<div class="mt-3 space-y-2">
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer">
<input type="checkbox" bind:checked={submitToDict} class="rounded" />
<span>Submit changed terms to dictionary</span>
<span>{$t.translate?.bulk_replace?.submit_to_dict}</span>
</label>
{#if submitToDict}
<textarea
bind:value={usageNotes}
placeholder="Usage notes (applied to all submitted entries)..."
placeholder={$t.translate?.bulk_replace?.usage_notes_placeholder}
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
rows="2"
></textarea>
@@ -319,13 +319,13 @@
onclick={handleCancelConfirm}
class="px-3 py-1.5 text-sm border border-gray-300 text-gray-700 rounded-lg hover:bg-white transition-colors"
>
Cancel
{$t.translate?.bulk_replace?.cancel}
</button>
<button
onclick={handleApply}
class="px-3 py-1.5 text-sm bg-amber-600 text-white rounded-lg hover:bg-amber-700 transition-colors"
>
Apply {applyCount} Change{applyCount !== 1 ? 's' : ''}
{$t.translate?.bulk_replace?.apply_count.replace('{count}', applyCount)}
</button>
</div>
</div>
@@ -337,7 +337,7 @@
{#if uxState === 'applying'}
<div class="flex items-center justify-center gap-3 py-8">
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-amber-600" />
<span class="text-sm text-gray-600">Applying bulk replace...</span>
<span class="text-sm text-gray-600">{$t.translate?.bulk_replace?.applying}</span>
</div>
{/if}
@@ -347,13 +347,13 @@
<svg class="w-12 h-12 text-green-500 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<p class="text-sm font-medium text-green-800">Bulk replace complete</p>
<p class="text-xs text-green-600 mt-1">{applyCount} record{applyCount !== 1 ? 's were' : ' was'} updated</p>
<p class="text-sm font-medium text-green-800">{$t.translate?.bulk_replace?.applied_title}</p>
<p class="text-xs text-green-600 mt-1">{$t.translate?.bulk_replace?.applied_body.replace('{count}', applyCount)}</p>
<button
onclick={handleClose}
class="mt-4 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors text-sm"
>
Done
{$t.translate?.bulk_replace?.done}
</button>
</div>
{/if}
@@ -367,13 +367,13 @@
onclick={handleShowConfirm}
class="px-3 py-1.5 text-sm bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors"
>
Retry
{$t.translate?.bulk_replace?.retry}
</button>
<button
onclick={handleClose}
class="px-3 py-1.5 text-sm border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors"
>
Cancel
{$t.translate?.bulk_replace?.cancel}
</button>
</div>
</div>
@@ -387,7 +387,7 @@
onclick={handleClose}
class="px-4 py-2 text-sm text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors"
>
Close
{$t.translate?.bulk_replace?.close}
</button>
</div>
</div>

View File

@@ -15,6 +15,7 @@
<script>
import { addToast } from '$lib/toasts.js';
import { inlineEditCorrection, submitCorrectionToDict, dictionaryApi } from '$lib/api/translate.js';
import { t, _ } from '$lib/i18n';
/** @type {{ value: string, recordId: string, languageCode: string, runId: string, sourceLanguage?: string, contextData?: object|null, usageNotes?: string, onSave?: (newValue: string) => void }} */
let {
@@ -76,9 +77,9 @@
displayValue = newValue;
uxState = 'saved';
onSave(newValue);
addToast('Correction saved', 'success');
addToast(_('translate.corrections.cell_save_success'), 'success');
} catch (err) {
errorMessage = err?.message || 'Failed to save correction';
errorMessage = err?.message || _('translate.corrections.cell_save_failed');
uxState = 'error';
addToast(errorMessage, 'error');
}
@@ -97,14 +98,14 @@
selectedDictId = dictionaries[0].id;
}
} catch (err) {
addToast('Failed to load dictionaries', 'error');
addToast(_('translate.corrections.cell_dict_load_failed'), 'error');
}
}
/** @returns {Promise<void>} */
async function handleDictSubmit() {
if (!selectedDictId) {
addToast('Please select a dictionary', 'warning');
addToast(_('translate.corrections.cell_select_dict_warning'), 'warning');
return;
}
uxState = 'submitting_to_dict';
@@ -116,10 +117,10 @@
dictionary_id: selectedDictId
});
uxState = 'dict_submitted';
addToast('Dictionary entry created', 'success');
addToast(_('translate.corrections.cell_dict_submit_success'), 'success');
dictPopupOpen = false;
} catch (err) {
addToast(err?.message || 'Failed to submit to dictionary', 'error');
addToast(err?.message || _('translate.corrections.cell_dict_submit_failed'), 'error');
uxState = 'saved';
}
}
@@ -166,14 +167,14 @@
<button
onclick={saveEdit}
class="px-2 py-0.5 text-xs bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors"
title="Save"
title={$t.translate?.corrections?.cell_save}
>
</button>
<button
onclick={cancelEditing}
class="px-2 py-0.5 text-xs border border-gray-300 text-gray-600 rounded hover:bg-gray-50 transition-colors"
title="Cancel"
title={$t.translate?.corrections?.cell_cancel}
>
</button>
@@ -184,21 +185,21 @@
{:else if uxState === 'saving'}
<div class="flex items-center gap-2 px-2 py-1">
<div class="animate-spin rounded-full h-3 w-3 border-b-2 border-blue-600" />
<span class="text-xs text-gray-500">Saving...</span>
<span class="text-xs text-gray-500">{$t.translate?.corrections?.cell_saving}</span>
</div>
<!-- Saved mode: show value + Dictionary submit button -->
{:else if uxState === 'saved'}
<div class="flex items-center gap-2">
<span class="text-sm text-gray-700">{displayValue}</span>
<span class="text-xs text-green-600" title="Saved" aria-label="Edited" role="img">📝</span>
<span class="text-xs text-green-600" title={$t.translate?.corrections?.cell_save_success} aria-label={$t.translate?.corrections?.cell_save_success} role="img">📝</span>
<button
onclick={openDictPopup}
class="ml-1 px-1.5 py-0.5 text-xs bg-amber-100 text-amber-700 rounded hover:bg-amber-200 transition-colors"
title="Submit to Dictionary"
aria-label="Submit to Dictionary"
title={$t.translate?.corrections?.cell_submit_to_dict}
aria-label={$t.translate?.corrections?.cell_submit_to_dict}
>
📕 Dictionary
📕 {$t.translate?.corrections?.cell_submit_to_dict}
</button>
</div>
@@ -206,14 +207,14 @@
{:else if uxState === 'submitting_to_dict'}
<div class="flex items-center gap-2 px-2 py-1">
<div class="animate-spin rounded-full h-3 w-3 border-b-2 border-amber-600" />
<span class="text-xs text-amber-600">Submitting to dictionary...</span>
<span class="text-xs text-amber-600">{$t.translate?.corrections?.cell_submitting}</span>
</div>
<!-- Dictionary submitted mode -->
{:else if uxState === 'dict_submitted'}
<div class="flex items-center gap-2">
<span class="text-sm text-gray-700">{displayValue}</span>
<span class="text-xs text-green-600 font-medium" title="Saved to dictionary" aria-label="Submitted to dictionary" role="img">✅ Dictionary ✓</span>
<span class="text-xs text-green-600 font-medium" title={$t.translate?.corrections?.cell_dict_submitted} aria-label={$t.translate?.corrections?.cell_dict_submitted} role="img">{$t.translate?.corrections?.cell_submitted_badge}</span>
</div>
<!-- Error mode -->
@@ -225,7 +226,7 @@
onclick={startEditing}
class="px-2 py-0.5 text-xs bg-red-100 text-red-700 rounded hover:bg-red-200 transition-colors self-start"
>
Retry
{$t.translate?.corrections?.cell_retry}
</button>
</div>
{/if}
@@ -237,24 +238,24 @@
onclick={handleCloseDictPopup}
>
<div class="bg-white rounded-lg shadow-xl p-6 w-full max-w-lg mx-4 max-h-[80vh] overflow-y-auto" onclick={(e) => e.stopPropagation()}>
<h3 class="text-sm font-semibold text-gray-900 mb-4">Submit to Dictionary</h3>
<h3 class="text-sm font-semibold text-gray-900 mb-4">{$t.translate?.corrections?.cell_submit_to_dict}</h3>
<div class="space-y-3">
{#if sourceLanguage}
<div class="text-xs text-gray-500">
<span class="font-medium">Language pair:</span> {sourceLanguage}{languageCode}
<span class="font-medium">{$t.translate?.corrections?.cell_language_pair}</span> {sourceLanguage}{languageCode}
</div>
{/if}
<div>
<label class="block text-xs font-medium text-gray-700 mb-1">Corrected value</label>
<label class="block text-xs font-medium text-gray-700 mb-1">{$t.translate?.corrections?.cell_corrected_value}</label>
<div class="px-3 py-2 bg-gray-50 border border-gray-200 rounded text-sm">{editValue}</div>
</div>
<div>
<label class="block text-xs font-medium text-gray-700 mb-1">Dictionary</label>
<label class="block text-xs font-medium text-gray-700 mb-1">{$t.translate?.corrections?.dictionary}</label>
<select
bind:value={selectedDictId}
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
>
<option value="">Select dictionary...</option>
<option value="">{$t.translate?.corrections?.cell_select_dictionary}</option>
{#each dictionaries as dict}
<option value={dict.id}>{dict.name}</option>
{/each}
@@ -265,12 +266,12 @@
{#if editableContextData || contextEditMode}
<div class="border border-gray-200 rounded-lg p-3 bg-gray-50">
<div class="flex items-center justify-between mb-2">
<span class="text-xs font-medium text-gray-700">Context Data</span>
<span class="text-xs font-medium text-gray-700">{$t.translate?.corrections?.cell_context_data}</span>
<button
onclick={() => { contextEditMode = !contextEditMode; if (!contextEditMode) editableContextData = contextData ? JSON.parse(JSON.stringify(contextData)) : null; }}
class="text-xs text-blue-600 hover:text-blue-700"
>
{contextEditMode ? 'Cancel Edit' : 'Edit'}
{contextEditMode ? $t.translate?.corrections?.cell_cancel_edit : $t.translate?.corrections?.cell_edit}
</button>
</div>
{#if contextEditMode}
@@ -278,7 +279,7 @@
bind:value={editableContextData}
class="w-full px-2 py-1.5 border border-gray-300 rounded text-xs font-mono"
rows="3"
placeholder="Enter context data as JSON..."
placeholder={$t.translate?.corrections?.cell_context_json_placeholder}
></textarea>
{:else if typeof editableContextData === 'object' && editableContextData !== null}
<div class="text-xs text-gray-600 space-y-1">
@@ -287,19 +288,19 @@
{/each}
</div>
{:else}
<p class="text-xs text-gray-400 italic">No context data captured</p>
<p class="text-xs text-gray-400 italic">{$t.translate?.corrections?.cell_no_context_data}</p>
{/if}
</div>
{/if}
<!-- Usage Notes Section (T128) -->
<div>
<label class="block text-xs font-medium text-gray-700 mb-1">Usage Notes</label>
<label class="block text-xs font-medium text-gray-700 mb-1">{$t.translate?.corrections?.cell_usage_notes}</label>
<textarea
bind:value={editableUsageNotes}
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
rows="2"
placeholder="Optional notes about when/how this translation should be used..."
placeholder={$t.translate?.corrections?.cell_usage_notes_placeholder}
></textarea>
</div>
@@ -308,14 +309,14 @@
onclick={cancelDictSubmit}
class="px-3 py-1.5 text-xs text-gray-700 bg-gray-100 rounded hover:bg-gray-200 transition-colors"
>
Cancel
{$t.translate?.corrections?.cell_cancel}
</button>
<button
onclick={handleDictSubmit}
disabled={!selectedDictId}
class="px-3 py-1.5 text-xs text-white bg-amber-600 rounded hover:bg-amber-700 disabled:opacity-50 transition-colors"
>
Submit
{$t.translate?.corrections?.cell_submit}
</button>
</div>
</div>

View File

@@ -20,6 +20,7 @@
*/
import { addToast } from '$lib/toasts.js';
import { submitCorrection, dictionaryApi } from '$lib/api/translate.js';
import { t, _ } from '$lib/i18n';
let {
sourceTerm = '',
@@ -77,7 +78,7 @@
}
uxState = dictionaries.length > 0 ? 'editing' : 'selecting';
} catch (err) {
addToast('Failed to load dictionaries', 'error');
addToast(_('translate.term_correction.dict_load_failed'), 'error');
uxState = 'editing';
}
}
@@ -107,11 +108,11 @@
} else if (result.action === 'created' || result.action === 'updated') {
submitResult = result;
uxState = 'submitted';
addToast(result.message || 'Correction submitted', 'success');
addToast(result.message || _('translate.term_correction.submit_success'), 'success');
onSubmitted(result);
}
} catch (err) {
addToast(err?.message || 'Failed to submit correction', 'error');
addToast(err?.message || _('translate.term_correction.submit_failed'), 'error');
uxState = 'editing';
}
}
@@ -128,17 +129,17 @@
});
submitResult = result;
uxState = 'submitted';
addToast(result.message || 'Correction overwritten', 'success');
addToast(result.message || _('translate.term_correction.overwrite_success'), 'success');
onSubmitted(result);
} catch (err) {
addToast(err?.message || 'Failed to overwrite', 'error');
addToast(err?.message || _('translate.term_correction.overwrite_failed'), 'error');
uxState = 'conflict_detected';
}
}
function handleConflictKeep() {
uxState = 'submitted';
addToast('Existing entry kept', 'info');
addToast(_('translate.term_correction.keep_success'), 'info');
onSubmitted({ action: 'kept' });
}
@@ -153,7 +154,7 @@
<div class="bg-white rounded-lg shadow-xl p-6 w-full max-w-md mx-4" onclick={(e) => e.stopPropagation()}>
<!-- Header -->
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-semibold text-gray-900">Submit Term Correction</h3>
<h3 class="text-lg font-semibold text-gray-900">{$t.translate?.term_correction?.title}</h3>
<button onclick={handleClose} class="text-gray-400 hover:text-gray-600">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
@@ -163,14 +164,14 @@
<!-- Selecting state -->
{#if uxState === 'selecting'}
<p class="text-sm text-gray-500">Loading dictionaries...</p>
<p class="text-sm text-gray-500">{$t.translate?.term_correction?.loading_dictionaries}</p>
<!-- Editing state -->
{:else if uxState === 'editing'}
<div class="space-y-4">
{#if sourceLanguage || targetLanguage}
<div class="bg-blue-50 border border-blue-200 rounded-lg px-3 py-2 text-xs text-blue-700">
<span class="font-medium">Language pair:</span> {sourceLanguage || 'detected'}{targetLanguage || languageCode}
<span class="font-medium">{$t.translate?.term_correction?.language_pair}</span> {sourceLanguage || $t.translate?.term_correction?.detected}{targetLanguage || languageCode}
</div>
{/if}
@@ -182,13 +183,13 @@
>
<span class="flex items-center gap-1.5">
<span>📋</span>
<span>Context from source row</span>
<span>{$t.translate?.term_correction?.context_from_source}</span>
{#if contextData}
<span class="inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full"
class:bg-blue-100:text-blue-700={!hasEditedContext}
class:bg-green-100:text-green-700={hasEditedContext}
>
{hasEditedContext ? '✏️ Edited' : '🤖 Auto'}
{hasEditedContext ? '✏️ ' + $t.translate?.term_correction?.edited_badge : '🤖 ' + $t.translate?.term_correction?.auto_badge}
</span>
{/if}
</span>
@@ -210,7 +211,7 @@
}}
class="text-[11px] px-2 py-1 rounded border border-gray-300 text-gray-600 hover:bg-gray-50"
>
Edit context
{$t.translate?.term_correction?.edit_context}
</button>
<button
onclick={() => {
@@ -219,11 +220,11 @@
}}
class="text-[11px] px-2 py-1 rounded border border-red-200 text-red-600 hover:bg-red-50"
>
Remove context
{$t.translate?.term_correction?.remove_context}
</button>
</div>
{:else}
<p class="text-[11px] text-gray-400 italic">No context data available</p>
<p class="text-[11px] text-gray-400 italic">{$t.translate?.term_correction?.no_context}</p>
<button
onclick={() => {
contextData = JSON.parse(JSON.stringify(initialContextData));
@@ -232,7 +233,7 @@
}}
class="text-[11px] px-2 py-1 rounded border border-gray-300 text-gray-600 hover:bg-gray-50"
>
Restore context
{$t.translate?.term_correction?.restore_context}
</button>
{/if}
</div>
@@ -242,48 +243,48 @@
<!-- Usage notes -->
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">
📝 Usage notes (optional)
📝 {$t.translate?.term_correction?.usage_notes}
</label>
<textarea
bind:value={contextUsageNotes}
placeholder="Describe when this term mapping should be used..."
placeholder={$t.translate?.term_correction?.usage_notes_placeholder}
rows="2"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-xs focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none"
></textarea>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Source Term</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.term_correction?.source_term}</label>
<input type="text" readonly value={sourceTerm} class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Incorrect Target</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.term_correction?.incorrect_target}</label>
<input type="text" readonly value={incorrectTarget} class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Source Language</label>
<input type="text" readonly value={sourceLanguage || 'Auto-detected'} class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm font-mono" />
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.term_correction?.source_language}</label>
<input type="text" readonly value={sourceLanguage || $t.translate?.term_correction?.auto_detected} class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm font-mono" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Target Language</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.term_correction?.target_language}</label>
<input type="text" readonly value={targetLanguage || '—'} class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm font-mono" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Corrected Target</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.term_correction?.corrected_target}</label>
<input
type="text"
bind:value={correctedTarget}
placeholder="Enter corrected translation..."
placeholder={$t.translate?.term_correction?.corrected_placeholder}
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
/>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Dictionary</label>
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.translate?.term_correction?.dictionary}</label>
<select
bind:value={selectedDictId}
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
>
<option value="">Select dictionary...</option>
<option value="">{$t.translate?.term_correction?.select_dictionary}</option>
{#each dictionaries as dict}
<option value={dict.id}>{dict.name} ({dict.source_dialect} {dict.target_dialect})</option>
{/each}
@@ -291,14 +292,14 @@
</div>
<div class="flex justify-end gap-2 pt-2">
<button onclick={handleClose} class="px-4 py-2 text-sm text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">
Cancel
{$t.translate?.term_correction?.cancel}
</button>
<button
onclick={handleSubmit}
disabled={!selectedDictId || !correctedTarget.trim()}
class="px-4 py-2 text-sm text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50"
>
Submit Correction
{$t.translate?.term_correction?.submit_correction}
</button>
</div>
</div>
@@ -307,25 +308,24 @@
{:else if uxState === 'submitting'}
<div class="text-center py-6">
<div class="animate-spin w-8 h-8 border-2 border-blue-600 border-t-transparent rounded-full mx-auto mb-3"></div>
<p class="text-sm text-gray-500">Submitting correction...</p>
<p class="text-sm text-gray-500">{$t.translate?.term_correction?.submitting}</p>
</div>
<!-- Conflict state -->
{:else if uxState === 'conflict_detected'}
<div class="space-y-4">
<div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4">
<p class="text-sm font-medium text-yellow-800">Conflict Detected</p>
<p class="text-sm font-medium text-yellow-800">{$t.translate?.term_correction?.conflict_detected}</p>
<p class="text-xs text-yellow-600 mt-1">
"{conflictInfo?.source_term}" already exists in this dictionary
with target "{conflictInfo?.existing_target_term}".
{$t.translate?.term_correction?.conflict_description.replace('{source}', conflictInfo?.source_term || '').replace('{existing}', conflictInfo?.existing_target_term || '')}
</p>
</div>
<div class="flex justify-end gap-2">
<button onclick={handleConflictKeep} class="px-4 py-2 text-sm text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">
Keep Existing
{$t.translate?.term_correction?.keep_existing}
</button>
<button onclick={handleConflictOverwrite} class="px-4 py-2 text-sm text-white bg-yellow-600 rounded-lg hover:bg-yellow-700">
Overwrite
{$t.translate?.term_correction?.overwrite}
</button>
</div>
</div>
@@ -336,10 +336,10 @@
<svg class="w-12 h-12 text-green-500 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
</svg>
<p class="text-sm font-medium text-gray-900">Correction Submitted</p>
<p class="text-sm font-medium text-gray-900">{$t.translate?.term_correction?.submitted}</p>
<p class="text-xs text-gray-500 mt-1">{submitResult?.message || ''}</p>
<button onclick={handleClose} class="mt-4 px-4 py-2 text-sm text-white bg-blue-600 rounded-lg hover:bg-blue-700">
Close
{$t.translate?.term_correction?.close}
</button>
</div>
{/if}

View File

@@ -49,30 +49,30 @@ describe('BulkReplaceModal Component', () => {
it('has find pattern input with regex toggle', () => {
const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(source).toContain('Find pattern');
expect(source).toContain('bulk_replace?.find_pattern');
expect(source).toContain('findPattern');
expect(source).toContain('isRegex');
expect(source).toContain('Regex');
expect(source).toContain('bulk_replace?.regex');
});
it('has replacement text input', () => {
const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(source).toContain('Replace with');
expect(source).toContain('bulk_replace?.replace_with');
expect(source).toContain('replacementText');
});
it('has target language selector', () => {
const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(source).toContain('Target language');
expect(source).toContain('bulk_replace?.target_language');
expect(source).toContain('targetLanguage');
});
it('has preview table showing before/after values', () => {
const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(source).toContain('Preview:');
expect(source).toContain('Before');
expect(source).toContain('After');
expect(source).toContain('Apply Changes');
expect(source).toContain('bulk_replace?.preview_count');
expect(source).toContain('bulk_replace?.table_before');
expect(source).toContain('bulk_replace?.table_after');
expect(source).toContain('bulk_replace?.apply_changes');
});
it('has confirmation dialog with submit-to-dictionary checkbox', () => {

View File

@@ -55,10 +55,10 @@ describe('CorrectionCell Component', () => {
it('has dictionary popup with context display section', () => {
const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(source).toContain('Submit to Dictionary');
expect(source).toContain('Language pair');
expect(source).toContain('Context Data');
expect(source).toContain('Usage Notes');
expect(source).toContain('corrections?.cell_submit_to_dict');
expect(source).toContain('corrections?.cell_language_pair');
expect(source).toContain('corrections?.cell_context_data');
expect(source).toContain('corrections?.cell_usage_notes');
});
it('implements view, editing, saving, saved, error UX states', () => {
@@ -74,10 +74,10 @@ describe('CorrectionCell Component', () => {
expect(source).toContain('animate-spin');
// Saved mode
expect(source).toContain("uxState === 'saved'");
expect(source).toContain('Submit to Dictionary');
expect(source).toContain('corrections?.cell_submit_to_dict');
// Error mode
expect(source).toContain("uxState === 'error'");
expect(source).toContain('Retry');
expect(source).toContain('corrections?.cell_retry');
});
// --- T133: Context UI in CorrectionCell ---
@@ -94,8 +94,8 @@ describe('CorrectionCell Component', () => {
const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');
// contextEditMode toggles a textarea for JSON editing
expect(source).toContain('contextEditMode');
expect(source).toContain('Enter context data as JSON...');
expect(source).toContain('Cancel Edit');
expect(source).toContain('corrections?.cell_context_json_placeholder');
expect(source).toContain('corrections?.cell_cancel_edit');
});
it('supports context removal with keep_context=false (T133)', () => {
@@ -104,15 +104,15 @@ describe('CorrectionCell Component', () => {
expect(source).toContain('contextEditMode');
expect(source).toContain('editableContextData = contextData ? JSON.parse');
// The Edit/Cancel toggle button resets context data
expect(source).toContain('Cancel Edit');
expect(source).toContain('corrections?.cell_cancel_edit');
});
it('shows usage notes textarea in popup (T133)', () => {
const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');
// Usage Notes textarea is bound to editableUsageNotes
expect(source).toContain('bind:value={editableUsageNotes}');
expect(source).toContain('Usage Notes');
expect(source).toContain('Optional notes about when/how this translation should be used');
expect(source).toContain('corrections?.cell_usage_notes');
expect(source).toContain('corrections?.cell_usage_notes_placeholder');
});
it('contains context_source awareness in submit flow (T133)', () => {