@editora/translation-workflow
v1.0.1
Published
Native translation workflow plugin for Editora with segment locking, source-target view, and locale-aware validation
Maintainers
Readme
@editora/translation-workflow
[!IMPORTANT] Live Website: https://editora-ecosystem.netlify.app/
Storybook: https://editora-ecosystem-storybook.netlify.app/
@editora/translation-workflow adds localization QA workflows directly in the editor: segment locking, source-target preview, and per-locale validation.
Features
- Native plugin (no framework dependency)
- Works in React (Vite/CRA) and Web Components without modification
- Segment locking for finalized translations
- Source-target preview per segment
- Per-locale validation (placeholder/token integrity, untranslated checks, length-ratio checks)
- Realtime or on-demand validation
- Multi-instance-safe command targeting and toolbar active states
- Light/dark theme support
- Accessible panel (
role="dialog",listboxnavigation, ARIA labels, live region updates)
Install
npm install @editora/translation-workflowBasic Usage (React)
import { EditoraEditor } from '@editora/react';
import { TranslationWorkflowPlugin, HistoryPlugin } from '@editora/plugins';
export default function App() {
return (
<EditoraEditor
plugins={[
HistoryPlugin(),
TranslationWorkflowPlugin({
sourceLocale: 'en-US',
targetLocale: 'fr-FR',
enableRealtime: true,
}),
]}
/>
);
}Basic Usage (Web Component)
<editora-editor id="editor"></editora-editor>
<script>
const editor = document.getElementById('editor');
editor.setConfig({
plugins: 'history translation-workflow',
toolbar: {
items:
'undo redo | toggleTranslationWorkflowPanel runTranslationLocaleValidation toggleTranslationSegmentLock toggleTranslationRealtime',
},
});
</script>Accepted aliases: translationWorkflow, translation-workflow, translationworkflow.
Step-by-Step Scenario (Product Localization)
Scenario: your product release notes are authored in English and translated to French. You want to lock approved segments, validate placeholders, and prevent untranslated strings before handoff.
- Open panel:
Ctrl/Cmd + Alt + Shift + L. - Set locales: source
en-US, targetfr-FR. - Click
Capture Sourceonce when source text is finalized. - Translate content in the editor.
- Select completed segments and click
Lock Selected. - Run
Validate Localeor use shortcutCtrl/Cmd + Alt + Shift + V. - Fix reported issues:
- missing target content
- token mismatch (for example
{{name}},%ORDER_ID%,${count}) - untranslated segment (same as source)
- suspicious length ratio for target locale
- Re-run validation until no blocking issues remain.
Why it helps:
- Prevents placeholder breakage in localized builds.
- Keeps approved segments immutable during review.
- Catches common translation QA gaps before export.
Manual Verification Playbook (Real Use Case)
Use this as a deterministic QA run before production rollout.
Scenario A: Release Notes Localization Gate
- Start from this content:
<h2>Release Notes v4.8</h2>
<p>Welcome {{firstName}}! Your order ID is %ORDER_ID%.</p>
<p>Click <strong>Upgrade Now</strong> to activate premium analytics.</p>
<p>For support, contact [email protected] within 24 hours.</p>- Open Translation Workflow panel with
Ctrl/Cmd + Alt + Shift + L. - Click
Capture Source. - Replace the first paragraph with
Welcome to release notes.(remove both placeholders). - Click
Validate Locale(orCtrl/Cmd + Alt + Shift + V). - Verify at least one issue indicates placeholder/token mismatch.
- In the segment list, pick a segment and click
Lock Selected. - Confirm the segment has lock styling and cannot be edited.
- Click
Unlock Selectedon the same segment. - Confirm the segment is editable again and text can be updated.
- Fix all issues and re-run validation until the panel reports no blocking issues.
Expected output:
- Placeholder mismatch is surfaced after step 5.
- Lock state is preserved in panel and segment UI.
- Unlock restores editability for the segment.
- Final validation can reach zero issues after fixes.
Scenario B: Multi-Editor Isolation Check
- Render two editors on the same page, both with
TranslationWorkflowPlugin. - Open panel and enable realtime in Editor A only.
- Keep Editor B realtime off.
- Type translation changes in both editors.
Expected output:
- Toolbar active states (
toggleTranslationRealtime, panel toggle) remain isolated per editor. - Validation results and selected segment state do not leak across instances.
Scenario C: Locked Segment Integrity Check
- Lock a segment in panel.
- Try to mutate locked segment content using another command/plugin flow (formatting or external DOM mutation in devtools).
- Trigger validation again.
Expected output:
- Locked segment content is restored to its locked snapshot.
- Live region communicates that locked content is readonly.
Run Local E2E for this Scenario
cd e2e-local
npm test -- tests/translation-workflow.scenario.spec.tsThis test automates:
- source capture
- token mismatch detection
- lock -> unlock flow
- post-unlock editability check
Toolbar Commands
toggleTranslationWorkflowPanelopenTranslationWorkflowPanelrunTranslationLocaleValidationtoggleTranslationSegmentLocktoggleTranslationRealtimesetTranslationLocalescaptureTranslationSourceSnapshotsetTranslationWorkflowOptionsgetTranslationWorkflowState
Keyboard Shortcuts
Ctrl/Cmd + Alt + Shift + L-> toggle workflow panelCtrl/Cmd + Alt + Shift + V-> run locale validationCtrl/Cmd + Alt + Shift + K-> lock/unlock selected segment
Advanced Usage
1. Locale-specific validation rules
TranslationWorkflowPlugin({
sourceLocale: 'en-US',
targetLocale: 'ja-JP',
localeRules: [
{
locale: 'ja',
minLengthRatio: 0.45,
maxLengthRatio: 1.2,
requireDifferentFromSource: true,
preserveTokens: true,
},
],
});2. Programmatic segment locking in multi-editor pages
const execute = (window as any).executeEditorCommand;
const editorHost = document.querySelector('[data-editora-editor]');
(window as any).__editoraCommandEditorRoot = editorHost;
execute?.('toggleTranslationSegmentLock', { segmentId: 'translation-segment-8', locked: true });3. Runtime locale/profile update
(window as any).executeEditorCommand?.('setTranslationWorkflowOptions', {
sourceLocale: 'en-US',
targetLocale: 'de-DE',
enableRealtime: false,
labels: {
panelTitle: 'Localization QA',
validateText: 'Run L10n QA',
},
});4. Read runtime state
(window as any).executeEditorCommand?.('getTranslationWorkflowState', (state) => {
console.log(state.targetLocale, state.issues.length, state.lockedSegmentCount);
});Edge Cases Covered
- Multi-editor pages: explicit command context is consumed for safe targeting.
- Stale keyboard focus: shortcuts ignore stale selections outside editor/panel context.
- Locked segments: edit attempts are blocked with live-region feedback.
- Detached editors: panel/state cleanup on unmount/removal.
- Long sessions: realtime validation is debounced and bounded by
maxIssues/maxSegments. - Token consistency: placeholders are compared source vs target per segment.
- Duplicate segment IDs (from pasted content): plugin re-keys duplicates to avoid lock/source state collisions.
- Nested segment candidates (for example
td > p): plugin keeps leaf segments only to avoid double counting. - Locked segment integrity: external mutations are restored back to locked snapshot before QA state is refreshed.
