From 1de85c165792152803a1b37f20d203283d8e6869 Mon Sep 17 00:00:00 2001 From: Mishig Date: Mon, 26 Oct 2026 17:10:07 +0100 Subject: [PATCH 1/2] Copy page menu: translate it for translated docs; keep it on screen 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 --- kit/src/lib/CopyLLMTxtMenu.svelte | 68 +++++----- kit/src/lib/copyMenuStrings.ts | 202 ++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+), 30 deletions(-) create mode 100644 kit/src/lib/copyMenuStrings.ts diff --git a/kit/src/lib/CopyLLMTxtMenu.svelte b/kit/src/lib/CopyLLMTxtMenu.svelte index 6d87a42ca..15efec30a 100644 --- a/kit/src/lib/CopyLLMTxtMenu.svelte +++ b/kit/src/lib/CopyLLMTxtMenu.svelte @@ -9,6 +9,7 @@ import IconAnthropic from "./IconAnthropic.svelte"; import IconMCP from "./IconMCP.svelte"; import IconHuggingChat from "./IconHuggingChat.svelte"; + import { copyMenuStrings } from "./copyMenuStrings"; interface Props { label?: string; @@ -17,16 +18,17 @@ containerStyle?: string; } + const isClient = typeof window !== "undefined"; + const hasDocument = typeof document !== "undefined"; + const t = copyMenuStrings(isClient ? window.location.pathname : ""); + let { - label = "Copy page", - markdownDescription = "Copy page as Markdown for LLMs", + label = t.copyPage, + markdownDescription = t.copyPageDescription, containerClass = "", containerStyle = "", }: Props = $props(); - const isClient = typeof window !== "undefined"; - const hasDocument = typeof document !== "undefined"; - function resolveSourceUrl() { if (!isClient || !window.location) return; const current = window.location.href.replace(/#.*$/, ""); @@ -55,8 +57,8 @@ const externalOptions: ExternalOption[] = [ { - label: "Open in HuggingChat", - description: "Ask questions about this page", + label: t.openIn("HuggingChat"), + description: t.askQuestions, icon: "huggingchat", buildUrl: () => { const encodedAttachment = encodeURIComponent(SOURCE_URL_MD); @@ -67,8 +69,8 @@ }, }, { - label: "Open in ChatGPT", - description: "Ask questions about this page", + label: t.openIn("ChatGPT"), + description: t.askQuestions, icon: "chatgpt", buildUrl: () => encodedPrompt @@ -76,15 +78,15 @@ : "https://chatgpt.com", }, { - label: "Open in Claude", - description: "Ask questions about this page", + label: t.openIn("Claude"), + description: t.askQuestions, icon: "claude", buildUrl: () => encodedPrompt ? `https://claude.ai/new?q=${encodedPrompt}` : "https://claude.ai/new", }, { - label: "Connect to MCP Client", - description: "Install MCP server on Cursor, VS Code, etc.", + label: t.connectMcp, + description: t.connectMcpDescription, icon: "mcp", buildUrl: () => "https://huggingface.co/mcp", }, @@ -164,15 +166,21 @@ function openMenu() { open = true; ensurePromptAndUrl(); - if (isClient && triggerEl) { - void tick().then(() => { - if (!triggerEl) return; - const rect = triggerEl.getBoundingClientRect(); - const gutter = 10; - const minWidth = Math.max(rect.width + 80, 220); - const right = Math.max(window.innerWidth - rect.right, gutter); - menuStyle = `top:${rect.bottom + gutter}px;right:${right}px;min-width:${minWidth}px;`; - }); + if (isClient) void positionMenu(); + } + + async function positionMenu() { + await tick(); + if (!triggerEl) return; + const rect = triggerEl.getBoundingClientRect(); + const gutter = 10; + const minWidth = Math.max(rect.width + 80, 220); + const right = Math.max(window.innerWidth - rect.right, gutter); + menuStyle = `top:${rect.bottom + gutter}px;right:${right}px;min-width:${minWidth}px;`; + await tick(); + // no room left of the trigger (it sits at the start of the line in right-to-left pages): open rightwards + if (menuEl && menuEl.getBoundingClientRect().left < gutter) { + menuStyle = `top:${rect.bottom + gutter}px;left:${Math.max(rect.left, gutter)}px;min-width:${minWidth}px;`; } } @@ -236,14 +244,14 @@ > - {copied ? "Copied" : label} + {copied ? t.copied : label}