From 154f1c8b79a0beb5a2571ffea941607bc4f4d03e Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Sat, 21 Nov 2026 21:15:10 +0100 Subject: [PATCH] Fix copy button translations using template labels --- .babel.cfg | 2 -- python_docs_theme/layout.html | 5 ++++- python_docs_theme/static/copybutton.js | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.babel.cfg b/.babel.cfg index cc4c9de0..692580d8 100644 --- a/.babel.cfg +++ b/.babel.cfg @@ -1,3 +1 @@ -[javascript: **.js] - [jinja2: **.html] diff --git a/python_docs_theme/layout.html b/python_docs_theme/layout.html index 10232585..ab1cfe39 100644 --- a/python_docs_theme/layout.html +++ b/python_docs_theme/layout.html @@ -74,7 +74,10 @@

{{ _('Navigation') }}

{%- if builder != "htmlhelp" %} {%- if not embedded %} - + diff --git a/python_docs_theme/static/copybutton.js b/python_docs_theme/static/copybutton.js index f90eb1e8..88ee0c61 100644 --- a/python_docs_theme/static/copybutton.js +++ b/python_docs_theme/static/copybutton.js @@ -23,12 +23,14 @@ function getCopyableText(rootElement) { return rootElement.innerText.trim() } +const copyButtonLabels = document.currentScript.dataset + const loadCopyButton = () => { const button = document.createElement("button") button.classList.add("copybutton") button.type = "button" - button.innerText = _("Copy") - button.title = _("Copy to clipboard") + button.innerText = copyButtonLabels.copy + button.title = copyButtonLabels.copyToClipboard const makeOnButtonClick = () => { let timeout = null @@ -50,9 +52,9 @@ const loadCopyButton = () => { return } - buttonEl.innerText = _("Copied!") + buttonEl.innerText = copyButtonLabels.copied timeout = setTimeout(() => { - buttonEl.innerText = _("Copy") + buttonEl.innerText = copyButtonLabels.copy }, 1500) } }