|
| 1 | +# Translation Error Comments |
| 2 | + |
| 3 | +This feature adds HTML comments to help translators understand why their translations fall back to English on the production site. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +When translation errors occur (Liquid syntax errors, YAML frontmatter issues, unknown variables), the system previously fell back to English content silently. Now, HTML comments are added to provide debugging information for translators. |
| 8 | + |
| 9 | +## How It Works |
| 10 | + |
| 11 | +When a translation fails, an HTML comment is automatically added before the fallback English content: |
| 12 | + |
| 13 | +```html |
| 14 | +<!-- TRANSLATION_FALLBACK prop=title type=ParseError file=/content/article.md line=5 col=12 msg="Unknown tag 'badtag'" --> |
| 15 | +<h1>Getting started with GitHub</h1> |
| 16 | +``` |
| 17 | + |
| 18 | +## Comment Format |
| 19 | + |
| 20 | +Comments include the following information: |
| 21 | + |
| 22 | +- `TRANSLATION_FALLBACK` - Searchable tag to identify fallback comments |
| 23 | +- `prop=<property>` - Which property failed (title, intro, markdown, etc.) |
| 24 | +- `type=<errorType>` - Type of error (ParseError, RenderError, TokenizationError, etc.) |
| 25 | +- `file=<filepath>` - File where the error occurred (when available) |
| 26 | +- `line=<number>` - Line number of the error (when available) |
| 27 | +- `col=<number>` - Column number of the error (when available) |
| 28 | +- `msg="<message>"` - Sanitized error message with debugging hints |
| 29 | + |
| 30 | +## Error Types |
| 31 | + |
| 32 | +### Liquid Errors |
| 33 | +- **ParseError**: Syntax errors in Liquid tags (malformed brackets, unknown tags) |
| 34 | +- **RenderError**: Runtime errors (unknown variables, missing data) |
| 35 | +- **TokenizationError**: Issues parsing Liquid tokens |
| 36 | + |
| 37 | +### Other Errors |
| 38 | +- **TitleFromAutotitleError**: AUTOTITLE link resolution failures |
| 39 | +- **EmptyTitleError**: Content becomes empty after rendering |
| 40 | + |
| 41 | +## Translator Workflow |
| 42 | + |
| 43 | +### Finding Translation Issues |
| 44 | + |
| 45 | +1. **View page source** in your browser (Ctrl+U or Cmd+Option+U) |
| 46 | +2. **Search for "TRANSLATION_FALLBACK"** (Ctrl+F or Cmd+F) |
| 47 | +3. **Review the error information** to understand what went wrong |
| 48 | + |
| 49 | +### Example Debugging Session |
| 50 | + |
| 51 | +If you see this comment: |
| 52 | +```html |
| 53 | +<!-- TRANSLATION_FALLBACK prop=intro type=RenderError file=/content/copilot/getting-started.md line=15 col=8 msg="Unknown variable 'variables.product.prodname_copilot_short'" --> |
| 54 | +``` |
| 55 | + |
| 56 | +This tells you: |
| 57 | +- The `intro` property failed to render |
| 58 | +- It's a `RenderError` (runtime issue, not syntax) |
| 59 | +- The error is in `/content/copilot/getting-started.md` at line 15, column 8 |
| 60 | +- There's an unknown variable reference that needs to be fixed |
| 61 | + |
| 62 | +### Browser Console Helper |
| 63 | + |
| 64 | +You can also use this JavaScript snippet in the browser console to extract all fallback information: |
| 65 | + |
| 66 | +```javascript |
| 67 | +// Extract all translation fallback comments from the page |
| 68 | +const comments = document.documentElement.outerHTML.match(/<!-- TRANSLATION_FALLBACK[^>]+ -->/g) || [] |
| 69 | +console.log('Translation fallbacks found:', comments.length) |
| 70 | +comments.forEach((comment, i) => { |
| 71 | + console.log(`${i + 1}:`, comment) |
| 72 | +}) |
| 73 | +``` |
| 74 | + |
| 75 | +## Implementation Details |
| 76 | + |
| 77 | +### When Comments Are Added |
| 78 | + |
| 79 | +Comments are added when: |
| 80 | +- The page language is not English (`currentLanguage !== 'en'`) |
| 81 | +- A translation error occurs that can be fallen back to English |
| 82 | +- The output is HTML content (not plain text) |
| 83 | + |
| 84 | +### When Comments Are NOT Added |
| 85 | + |
| 86 | +Comments are skipped for: |
| 87 | +- English content (no fallback needed) |
| 88 | +- Text-only rendering (to avoid breaking plain text output) |
| 89 | +- Non-fallbackable errors (these throw and stop rendering) |
| 90 | + |
| 91 | +### Error Message Sanitization |
| 92 | + |
| 93 | +Error messages are cleaned up for security and readability: |
| 94 | +- Limited to 200 characters maximum |
| 95 | +- Double quotes escaped to single quotes |
| 96 | +- Newlines converted to spaces |
| 97 | +- Multiple whitespace collapsed |
| 98 | + |
| 99 | +### Performance Impact |
| 100 | + |
| 101 | +- Minimal overhead: only adds HTML comments when errors occur |
| 102 | +- Comment generation: ~1-5ms per error |
| 103 | +- HTML size increase: ~100-200 bytes per comment |
| 104 | +- No impact on successful translation rendering |
| 105 | + |
| 106 | +## Code Implementation |
| 107 | + |
| 108 | +The feature is implemented in `src/languages/lib/render-with-fallback.js`: |
| 109 | + |
| 110 | +- `createTranslationFallbackComment()` - Generates the HTML comment |
| 111 | +- Enhanced `renderContentWithFallback()` - Adds comments for page properties |
| 112 | +- Enhanced `executeWithFallback()` - Adds comments for general content |
| 113 | + |
| 114 | +### Key Functions |
| 115 | + |
| 116 | +```javascript |
| 117 | +// Main rendering function with comment support |
| 118 | +export async function renderContentWithFallback(page, property, context, options) |
| 119 | + |
| 120 | +// General fallback function with comment support |
| 121 | +export async function executeWithFallback(context, callable, fallback) |
| 122 | +``` |
| 123 | + |
| 124 | +## Examples |
| 125 | + |
| 126 | +### Liquid Syntax Error |
| 127 | +```html |
| 128 | +<!-- TRANSLATION_FALLBACK prop=title type=ParseError file=/content/actions/index.md line=1 col=15 msg="Unexpected token '}'" --> |
| 129 | +<h1>GitHub Actions</h1> |
| 130 | +``` |
| 131 | +
|
| 132 | +### Unknown Variable |
| 133 | +```html |
| 134 | +<!-- TRANSLATION_FALLBACK prop=intro type=RenderError file=/content/copilot/intro.md line=3 col=8 msg="Unknown variable 'variables.product.bad_name'" --> |
| 135 | +<p>GitHub Copilot helps you code faster and with confidence.</p> |
| 136 | +``` |
| 137 | +
|
| 138 | +### AUTOTITLE Error |
| 139 | +```html |
| 140 | +<!-- TRANSLATION_FALLBACK prop=markdown type=TitleFromAutotitleError msg="Could not find target page for [AUTOTITLE] link" --> |
| 141 | +<p>For more information, see <a href="/getting-started">Getting started</a>.</p> |
| 142 | +``` |
| 143 | +
|
| 144 | +### Missing File Reference |
| 145 | +```html |
| 146 | +<!-- TRANSLATION_FALLBACK prop=intro type=RenderError file=/content/article.md line=5 col=12 msg="No such file or directory" --> |
| 147 | +<p>Welcome to GitHub documentation.</p> |
| 148 | +``` |
| 149 | +
|
| 150 | +## Troubleshooting |
| 151 | +
|
| 152 | +### Common Issues |
| 153 | +
|
| 154 | +**Q: I don't see any TRANSLATION_FALLBACK comments** |
| 155 | +A: This means your translations are working correctly! Comments only appear when errors occur. |
| 156 | + |
| 157 | +**Q: Comments appear in the wrong language** |
| 158 | +A: Comments are only added for non-English pages. Check that you're viewing a translated version of the page. |
| 159 | +
|
| 160 | +**Q: The error message is truncated** |
| 161 | +A: Messages are limited to 200 characters for readability. The truncation ensures comments don't become too large. |
| 162 | + |
| 163 | +**Q: File paths show as relative paths** |
| 164 | +A: File paths are shown as they exist in the repository structure for easy navigation. |
| 165 | + |
| 166 | +### Getting Help |
| 167 | + |
| 168 | +If you need assistance interpreting error messages or fixing translation issues: |
| 169 | + |
| 170 | +1. Note the error type and message from the comment |
| 171 | +2. Check the file and line number mentioned |
| 172 | +3. Compare with the working English version |
| 173 | +4. Reach out to the docs engineering team with specific error details |
| 174 | + |
| 175 | +## Technical Notes |
| 176 | + |
| 177 | +### Browser Compatibility |
| 178 | +HTML comments are supported by all browsers and are invisible to end users. |
| 179 | + |
| 180 | +### Security Considerations |
| 181 | +- No sensitive file paths or internal data exposed |
| 182 | +- Error messages are sanitized and length-limited |
| 183 | +- Only translation-related debugging information included |
| 184 | + |
| 185 | +### Monitoring |
| 186 | +Translation fallback frequency can be monitored by tracking comment generation in logs or analytics. |
| 187 | + |
| 188 | +This feature helps translation teams identify and fix issues more efficiently while maintaining the reliability of the docs site for all users. |
0 commit comments