v148 · AI · JavaScript
Safety Harness
12 edge-case tests: API availability, unsupported language pairs, same-source-target, empty input, very long text, concurrent translations, model download trigger, same-text consistency, and graceful fallback paths.
Checking Translator API…
12Total
0Pass
0Fail
0Warn
Ready.
Test suite
// Defensive Translator usage
async function safeTranslate(text, from, to) {
if (!window.Translator) return { error: 'not-supported' };
if (!text?.trim()) return { error: 'empty-input' };
if (from === to) return { result: text }; // no-op
const avail = await Translator.availability({ sourceLanguage: from, targetLanguage: to });
if (avail === 'no') return { error: 'pair-unavailable' };
try {
const t = await Translator.create({ sourceLanguage: from, targetLanguage: to });
return { result: await t.translate(text) };
} catch (e) {
return { error: 'inference-error', message: e.message };
}
}
see also
- Language Pair Explorer — availability matrix
- Local-First Workflow — realistic app flows
- Quality Control Panel — latency benchmarks
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗