Browser-Based Translation Implementation Guide¶
Overview¶
This document describes the experimental browser-based translation feature for the Copyright Compendium web viewer. The implementation uses the emerging Translation API (formerly known as the Chrome Translation API), which provides privacy-preserving, on-device machine translation.
Current Status¶
⚠️ EXPERIMENTAL FEATURE
The Translation API is currently in early development and only available in: - Chrome 120+ with experimental features enabled - Edge Canary builds with experimental features
Enabling the Translation API (for testing)¶
To test this feature in Chrome:
- Open Chrome and navigate to:
chrome://flags - Search for "Translation API"
- Enable the following flags:
#translation-api- Enable Translation API#enable-experimental-web-platform-features- Enable experimental features- Restart Chrome
- Visit the Compendium site and test the translation dropdown
Architecture¶
Components¶
- TranslationService Class (
script.js) - Manages browser translation API integration
- Checks for API availability
- Handles translation of DOM elements
-
Maintains translation state
-
UI Components (
index.html) - Language selector dropdown (12 languages)
- Translation disclaimer banner
- Browser compatibility notice
-
"View Original" link
-
Styling (
style.css) - USWDS-compliant design for translation controls
- Responsive layout for mobile/desktop
- Accessible color schemes and focus states
Supported Languages¶
The implementation supports translation to the following languages:
- Spanish (Español) -
es - Chinese (中文) -
zh - French (Français) -
fr - German (Deutsch) -
de - Japanese (日本語) -
ja - Korean (한국어) -
ko - Russian (Русский) -
ru - Arabic (العربية) -
ar - Portuguese (Português) -
pt - Italian (Italiano) -
it - Hindi (हिन्दी) -
hi - Vietnamese (Tiếng Việt) -
vi
Technical Implementation¶
Translation API Usage¶
The implementation uses the following API pattern (based on the new Translation API specification):
// Check API availability
const availability = await Translator.availability({
sourceLanguage: 'en',
targetLanguage: 'es'
});
// Create translator instance
const translator = await Translator.create({
sourceLanguage: 'en',
targetLanguage: 'es'
});
// Translate text
const translatedText = await translator.translate(originalText);
Translation Process¶
- User selects a target language from dropdown
- System checks if Translation API is available
- If available:
- Shows disclaimer banner
- Creates translator instance for language pair (en → target)
- Traverses DOM tree to find text nodes
- Translates each text node individually
- Updates DOM with translated content
- If not available:
- Shows browser compatibility notice
- Disables translation dropdown
Content Preservation¶
The implementation:
- Only translates text nodes (preserves HTML structure)
- Skips <script> and <style> elements
- Maintains hyperlinks and formatting
- Stores original content for restoration
User Experience¶
Disclaimer¶
When translation is active, a prominent warning banner appears:
⚠️ Experimental Translation: This is an automatically translated version and is not official. The translation may contain inaccuracies or errors. For authoritative information, please refer to the original English version.
Restoring Original Content¶
Users can return to the original English version by: 1. Selecting "English (Original)" from the dropdown 2. Clicking the "original English version" link in the disclaimer
Both actions reload the current chapter to ensure complete restoration.
Browser Compatibility¶
Supported Browsers (Future)¶
- Chrome 120+ (with flags enabled currently)
- Edge Canary (with flags enabled)
- Expected stable support in Chrome/Edge 2024-2025
Unsupported Browsers¶
For browsers without Translation API support, the implementation: - Shows an informational banner - Suggests using Chrome 120+ or browser's built-in translation - Disables the language selector gracefully
Fallback Options¶
Users in unsupported browsers can still translate using:
- Browser Built-in Translation
- Chrome: Right-click → "Translate to [language]"
- Edge: Similar right-click menu
-
Safari: Translation available in address bar
-
Third-party Extensions
- Google Translate extension
- Microsoft Translator
- Other translation extensions
Privacy and Performance¶
Privacy Benefits¶
The Translation API provides: - On-device processing - No text sent to servers - No data collection - Translation happens locally - No cookies or tracking - Pure client-side operation - Offline capability - Works without internet (after model download)
Performance Characteristics¶
- First translation: May be slow (model download)
- Subsequent translations: Fast (model cached)
- Memory usage: Moderate (translation models loaded in memory)
- Network usage: One-time model download per language
Future Enhancements¶
Planned Improvements¶
- Progressive Enhancement
- Detect Translation API availability at runtime
-
Gracefully degrade to external services if needed
-
Translation Persistence
- Remember user's language preference
- Auto-translate on page navigation
-
Store preference in localStorage
-
Enhanced UX
- Loading indicators during translation
- Progress bars for long documents
-
Translation confidence indicators
-
Additional Features
- Side-by-side view (original + translation)
- Inline terminology tooltips
- Translation quality feedback
Integration with Other Translation Services¶
If the Translation API is not available or suitable, the architecture allows for integration with:
- Google Cloud Translation API - Server-side translation
- Microsoft Translator - Enterprise translation service
- DeepL API - High-quality neural translation
- LibreTranslate - Open-source self-hosted option
Testing¶
Manual Testing Checklist¶
- [ ] Enable Translation API flags in Chrome
- [ ] Select each supported language
- [ ] Verify disclaimer appears
- [ ] Check translation quality
- [ ] Test "View Original" link
- [ ] Verify restoration to English
- [ ] Test in unsupported browser (Safari)
- [ ] Verify graceful degradation
- [ ] Check mobile responsive design
- [ ] Test keyboard navigation (accessibility)
Test Cases¶
- Happy Path
- Select Spanish → Content translates → Disclaimer shows
-
Select English → Content restores → Disclaimer hides
-
Edge Cases
- Rapid language switching
- Translation during chapter navigation
- Translation with open glossary tooltips
-
Translation with active search highlights
-
Error Handling
- Translation API unavailable
- Network error during model download
- Translation timeout for large content
Code Maintenance¶
Key Files¶
CompendiumUI/index.html- HTML structure for translation UICompendiumUI/script.js- TranslationService class and event handlersCompendiumUI/style.css- Translation UI stylingTRANSLATION_IMPLEMENTATION.md- This documentation
Updating Language List¶
To add/remove languages:
- Update
index.html- Add/remove<option>elements - Verify language code is supported by Translation API
- Test translation quality for new language
- Update this documentation
API Changes¶
Monitor the Translation API specification at: - https://github.com/WICG/translation-api - https://chromestatus.com/feature/5182950152642560
Deployment Notes¶
Production Considerations¶
- Feature Detection Required
- Always check
'translation' in selfbefore using -
Provide clear messaging for unsupported browsers
-
Error Handling
- Wrap all Translation API calls in try-catch
- Log errors for debugging
-
Gracefully degrade on failure
-
Performance Monitoring
- Track translation success/failure rates
- Monitor translation duration
- Alert on high error rates
Rollout Strategy¶
Phase 1: Experimental (Current) - Feature available in experimental branch - Requires manual flag enabling - Limited to testing/feedback
Phase 2: Early Access - Feature available in production with warning - Automatic detection of API availability - Opt-in for users with supported browsers
Phase 3: General Availability - Feature enabled by default when API is stable - Full browser support across Chrome/Edge - Comprehensive error handling and fallbacks
Support and Feedback¶
Known Limitations¶
- Translation quality varies by language pair
- Legal/technical terminology may be inaccurate
- Formatting may be affected in complex layouts
- Large documents may translate slowly
Reporting Issues¶
Users should be directed to report: - Translation accuracy issues → Copyright Office - Technical/UI issues → Development team - Browser compatibility issues → Browser vendor
Disclaimer Language¶
All translations must include:
This is an automatically translated version and is not official. The translation may contain inaccuracies or errors. For authoritative information, please refer to the original English version.
Accessibility¶
The translation feature includes:
- Keyboard Navigation - Full keyboard control of language selector
- Screen Reader Support - Proper ARIA labels and announcements
- High Contrast - Follows USWDS color standards
- Focus Indicators - Clear visual focus states
- Semantic HTML - Proper heading hierarchy and landmarks
Conclusion¶
This implementation provides a foundation for browser-based translation of the Copyright Compendium while maintaining:
- Privacy - All processing on-device
- Accuracy - Clear disclaimers about non-official status
- Accessibility - WCAG 2.1 AA compliance
- Compatibility - Graceful degradation for unsupported browsers
- Maintainability - Clean separation of concerns
As the Translation API matures and gains broader browser support, this feature will provide multilingual access to copyright information while preserving the authority and integrity of the original English content.