Skip to content

Copy page menu: translate it on translated pages, keep it on screen - #865

Merged
mishig25 merged 2 commits into
mainfrom
copy-menu-translations
Oct 26, 2026
Merged

mishig25 merged 2 commits into
mainfrom
copy-menu-translations

Conversation

@mishig25

@mishig25 mishig25 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

On machine-translated pages, the "Copy page" button and its menu were still in English. Those pages run the English build's JS, so the language can't come from the build's DOCS_LANGUAGE.

  • Language from the URL: the menu reads the language from the page URL (/docs/{lib}/[{version}/]{lang}/…, same rules as hfDocPaths.js). It uses strings for the 11 translate-docs languages (new copyMenuStrings.ts) and falls back to English. This covers the button, "Copied", all menu items and the aria labels. Human-translated builds in those languages get it too.
  • Right-to-left labels: labels get dir="auto", so in Arabic, "فتح في ChatGPT" reads in the right order.
  • Menu placement: the menu opens towards the page content and is clamped to the viewport using its measured width. Normally that's leftwards from the trigger's right edge. In right-to-left pages it opens rightwards, because there the trigger sits at the left, next to the docs sidebar, which paints over the content column. Before, the menu ran off-screen on phones and went under the sidebar on desktop.

Tested end to end. I built two Hub pages with this kit and translated them to ja and ar from the translation cache, then served them from a local moon-landing:

  • After hydration, the button reads "ページをコピー" / "نسخ الصفحة", and the menu, its items and aria labels are translated.
  • The menu stays on screen and clear of the sidebar at 375px and 1280px, in ar, ja and en.
  • English is unchanged.

npm run check shows no new warnings.

The Hub docs need a rebuild with this kit, which means bumping hub-docs' doc-builder pin. The translation job then picks up the new asset hashes, with only cache hits.

🤖 Generated with Claude Code

mishig25 and others added 2 commits October 26, 2026 17:10
Machine-translated pages run the English build's JS, so the menu reads
the page language from the URL and uses its strings for the 11 languages
of translate-docs (also human-translated builds in those languages).
Labels get dir=auto for right-to-left pages, and the menu opens rightwards
when there's no room left of its trigger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In right-to-left pages the trigger sits at the left, next to the docs
sidebar, which paints over the content column: open rightwards there.
Position from the menu's measured width, clamped to the viewport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mishig25
mishig25 merged commit a05dda3 into main Oct 26, 2026
5 checks passed
@mishig25
mishig25 deleted the copy-menu-translations branch October 26, 2026 16:16
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.

1 participant