diff --git a/kit/src/lib/CopyLLMTxtMenu.svelte b/kit/src/lib/CopyLLMTxtMenu.svelte index 6d87a42ca..3479333f5 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,16 +166,27 @@ 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 size = `min-width:${Math.max(rect.width + 80, 220)}px;max-width:${window.innerWidth - 2 * gutter}px;`; + menuStyle = `top:${rect.bottom + gutter}px;left:0;visibility:hidden;${size}`; + await tick(); + if (!menuEl) return; + const width = menuEl.getBoundingClientRect().width; + // Open towards the page content: leftwards from the trigger's right edge, or rightwards from its + // left edge in right-to-left pages (where the trigger sits at the left, next to the sidebar). + const rtl = !!triggerEl.closest('[dir="rtl"]'); + const left = Math.max( + gutter, + Math.min(rtl ? rect.left : rect.right - width, window.innerWidth - gutter - width) + ); + menuStyle = `top:${rect.bottom + gutter}px;left:${left}px;${size}`; } function closeMenu() { @@ -236,14 +249,14 @@ > - {copied ? "Copied" : label} + {copied ? t.copied : label}