CodeSentry helps prevent code from being broken during browser translation. I created it because I was frustrated by how Deepl often broke code examples on programming blogs.
- Finds code blocks on web pages automatically
- Protects code using multiple methods:
- Adds
translate="no"attributes - Applies
notranslateclass - Uses Shadow DOM when needed (this one works best!)
- Converts elements to protected versions
- Adds
- Pattern detection for inline code in regular text
- Special rules for sites like GitHub, Stack Overflow
- Customizable settings for power users
- Exclude domains you don't want it to run on
The extension is pretty simple under the hood:
- It scans the page for code elements (
<pre>,<code>, etc.) - It applies various protection techniques to prevent translation
- It keeps watching as you browse (for single-page apps and dynamic content)
- If enabled, it also looks for code-like patterns in regular text (this can be CPU intensive)
- Clone this repo or download the zip
- Go to
chrome://extensions/in Chrome - Turn on "Developer mode" (top-right)
- Click "Load unpacked" and pick the folder
- You should see the CodeSentry icon in your toolbar
- Click the CodeSentry icon in your toolbar to see the current status
- Toggle the extension on/off as needed
- Visit a page with code and use a translation service - the code will be preserved
- Click the "Settings" button in the popup or right-click the extension icon and select "Options"
- Configure protection methods, elements to protect, and excluded domains
- Enable/disable advanced pattern detection
- Save your changes