-
Notifications
You must be signed in to change notification settings - Fork 1
Add i18n support for Turkish and English #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: saracmert <5950989+saracmert@users.noreply.github.com>
| const key = el.getAttribute('data-i18n-html'); | ||
| const url = el.getAttribute('data-i18n-url'); | ||
| if (url) { | ||
| el.innerHTML = i18n.getMessage(key, url); |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix the problem, we should prevent untrusted data from being injected directly into the DOM as HTML. When setting innerHTML, any content should be properly sanitized or encoded. Since the current codebase leverages Chrome extension APIs and maintains a simple translation layer, the single best fix is to ensure that any data going to el.innerHTML is properly escaped. This can be done by replacing assignment to el.innerHTML with assignment to el.textContent, blocking all HTML interpretation, unless the intent is to inject trusted HTML (which, for translations, is rare and discouraged).
If rich HTML content must be supported, a robust sanitizer such as DOMPurify should be used. However, since CodeQL flagged unescaped meta-characters, the simple fix is to use el.textContent wherever possible.
Specifically, in src/i18n.js, lines 55 and 57 should be changed from assigning to el.innerHTML to assigning to el.textContent.
If the feature relies on translation strings containing actual HTML (e.g., for formatting), a sanitizer needs to be applied to the translation result before using innerHTML. If not, use textContent.
No new imports are needed unless we decide to use a sanitizer. For a plain security fix, use textContent in place of innerHTML.
-
Copy modified line R55 -
Copy modified line R57
| @@ -52,9 +52,9 @@ | ||
| const key = el.getAttribute('data-i18n-html'); | ||
| const url = el.getAttribute('data-i18n-url'); | ||
| if (url) { | ||
| el.innerHTML = i18n.getMessage(key, url); | ||
| el.textContent = i18n.getMessage(key, url); | ||
| } else { | ||
| el.innerHTML = i18n.getMessage(key); | ||
| el.textContent = i18n.getMessage(key); | ||
| } | ||
| }); | ||
| } |
| if (url) { | ||
| el.innerHTML = i18n.getMessage(key, url); | ||
| } else { | ||
| el.innerHTML = i18n.getMessage(key); |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Co-authored-by: saracmert <5950989+saracmert@users.noreply.github.com>
Implements Chrome extension i18n infrastructure for Turkish (default) and English with 55 translation keys covering all UI text, error messages, and Jira issue descriptions.
Implementation
Locale files (
_locales/{tr,en}/messages.json)__MSG_keyName__pattern in manifestHelper module (
i18n.js)Language switching
HTML integration
Background service
Screenshot
Side-by-side view shows Turkish (left) and English (right) translations across all UI elements.
Files Modified
manifest.json- i18n refs (__MSG_extName__),default_locale: "tr"popup.html/js,options.html/js- data-i18n attributes, language selectorbackground.js- i18n for errors and Jira content (ADF format)Translation coverage includes extension metadata, all UI elements, error messages, and dynamically generated Jira issue descriptions.
Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.