Skip to content

Conversation

@kaankacar
Copy link
Collaborator

This PR adds a Google Translate widget to the navbar, allowing users to translate the documentation into various languages.

@kaankacar kaankacar requested review from ElliotFriend and removed request for ElliotFriend December 5, 2025 16:05
@stellar-jenkins
Copy link

Copy link
Contributor

@ElliotFriend ElliotFriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is really promising! Thank you!!! 🎉

I've added a couple notes throughout the PR changes.

Wondering if we might be able to adjust the spacing on these elements to make things a little nicer?

Image

Also, I'm seeing some strange behavior where the button doesn't appear to work in the following scenarios:

  • On mobile, the button in the "hamburger menu" doesn't seem to do anything
  • If the translation button is clicked and then "dismissed" (either closed outright, or if you navigate to some page without selecting a language), the button won't do anything if it's clicked again (unless you refresh the page)

Some of these comments may just be "it's weird" kinds of things that we'll have to just live with and/or fix in the future.

plugins: [
() => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd love if we could have this as a defined plugin in its own file. i'm thinking similar to how we have this route-export-plugin defined

Comment on lines 231 to 236
/* Fix for Google Translate making headers invisible */
html.translated-ltr .hash-link,
html.translated-rtl .hash-link {
opacity: 1 !important;
visibility: visible !important;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this may not be making it all the way through the docusaurus build process. i'm still seeing some invisible headers

Image

…eaders

- Remove unnecessary scripts (buttons.github.io, fontawesome)
- Extract google-translate-init plugin to src/google-translate-plugin.js
- Move navbar HTML to GOOGLE_TRANSLATE_ELEMENT constant in config/constants.ts
- Fix invisible headers by marking hash-links with notranslate class
- Add MutationObserver for SPA navigation support
- Update CSS with visibility fallback rules
@kaankacar
Copy link
Collaborator Author

Thank you for the detailed review feedback @ElliotFriend! I've addressed all the points you raised:

Changes made:

  • Removed buttons.github.io/buttons.js and fontawesome scripts from docusaurus.config.ts
  • Extracted plugin to separate file: Created src/google-translate-plugin.js following the pattern used in src/route-export-plugin.js
  • Cleaned up navbar HTML: Moved the inline HTML string to a GOOGLE_TRANSLATE_ELEMENT constant in /config/constants.ts
  • Fixed invisible headers bug: This was very tricky. The reason is when Google Translate processes the page, it wraps text nodes in tags. Google Translate was treating the header text and the anchor link as a single translation unit, causing parts of the header text to be merged into the anchor link. As a solution, I added JavaScript in the plugin to mark all .hash-link elements with notranslate class and translate="no" attribute, telling Google Translate to ignore anchor links.

Regarding the spacing adjustments: the "Select Language" dropdown and "Powered by Google Translate" text are injected by Google Translate itself. I could hide the "Powered by Google" text via CSS for a cleaner look or adjust the spacing/width of the dropdown. Let me know what you'd prefer!

@stellar-jenkins
Copy link

@stellar-jenkins
Copy link

@stellar-jenkins
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants