-
Notifications
You must be signed in to change notification settings - Fork 234
feat: add Google Translate integration #2079
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,27 @@ const config: Config = { | |||||||||||||||||
| defaultLocale: DEFAULT_LOCALE, | ||||||||||||||||||
| locales: ["en", "es"], | ||||||||||||||||||
| }, | ||||||||||||||||||
| scripts: [ | ||||||||||||||||||
| 'https://buttons.github.io/buttons.js', | ||||||||||||||||||
| 'https://use.fontawesome.com/221fd444f5.js', | ||||||||||||||||||
| 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit', | ||||||||||||||||||
| ], | ||||||||||||||||||
| plugins: [ | ||||||||||||||||||
| () => ({ | ||||||||||||||||||
| name: 'google-translate-init', | ||||||||||||||||||
| injectHtmlTags() { | ||||||||||||||||||
| return { | ||||||||||||||||||
| headTags: [ | ||||||||||||||||||
| { | ||||||||||||||||||
| tagName: 'script', | ||||||||||||||||||
| innerHTML: ` | ||||||||||||||||||
| function googleTranslateElementInit() {} | ||||||||||||||||||
|
||||||||||||||||||
| function googleTranslateElementInit() {} | |
| function googleTranslateElementInit() { | |
| new google.translate.TranslateElement({ | |
| pageLanguage: 'en', | |
| includedLanguages: 'en,es', | |
| layout: google.translate.TranslateElement.InlineLayout.SIMPLE | |
| }, 'google_translate_element'); | |
| } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using inline styles (style="display:inline-block" and style="vertical-align: text-bottom") is not a best practice in modern web development and makes styling inconsistent and harder to maintain.
Consider:
- Moving these styles to a CSS/SCSS file
- Using CSS classes instead of inline styles
- Following the existing styling patterns in the Docusaurus theme
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This inline HTML is extremely long and difficult to maintain. The onclick handler contains a hardcoded list of 100+ language codes, making it fragile and hard to update.
Consider:
- Moving this logic to a separate JavaScript file or React component
- Storing the language list in a configuration variable
- Using a more maintainable approach with proper event handlers instead of inline onclick
Example refactor:
const TRANSLATE_LANGUAGES = 'af,sq,am,en,fa,ar,...';
// Then reference this in a cleaner HTML structure or component
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class attribute contains "navbar__link false" which includes a literal "false" string. This appears to be a mistake - it looks like this should either be a conditional class or just "navbar__link".
If you're not using a conditional here, remove the "false" string:
<a class="navbar__link" href="#" ...>
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The translate link is missing essential accessibility attributes. The link has no accessible label for screen readers to announce what the button does.
Add an aria-label attribute:
<a class="navbar__link" href="#" aria-label="Translate page" onclick="...">
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onclick handler creates a new TranslateElement instance every time the link is clicked, which could lead to multiple widgets being initialized and potential memory leaks or unexpected behavior.
Consider tracking whether the element has already been initialized:
onclick="if (!window.googleTranslateInitialized) { new google.translate.TranslateElement({...}, 'google_translate_element'); window.googleTranslateInitialized = true; } return false;"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Loading external scripts without Subresource Integrity (SRI) hashes could pose a security risk if the third-party sources are compromised. While this is common practice for well-known CDNs like GitHub buttons and Font Awesome, consider adding SRI hashes for additional security or using a Content Security Policy (CSP) to restrict script sources.
This is particularly relevant for production deployments.