Skip to content

Commit 154f1c8

Browse files
committed
Fix copy button translations using template labels
1 parent db635c1 commit 154f1c8

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎.babel.cfg‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
[javascript: **.js]
2-
31
[jinja2: **.html]

‎python_docs_theme/layout.html‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ <h3>{{ _('Navigation') }}</h3>
7474
<link rel="shortcut icon" type="image/png" href="{{ pathto('_static/' ~ theme_root_icon, 1) }}">
7575
{%- if builder != "htmlhelp" %}
7676
{%- if not embedded %}
77-
<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>
77+
<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"
78+
data-copy="{{ _('Copy')|e }}"
79+
data-copy-to-clipboard="{{ _('Copy to clipboard')|e }}"
80+
data-copied="{{ _('Copied!')|e }}"></script>
7881
<script type="text/javascript" src="{{ pathto('_static/menu.js', 1) }}"></script>
7982
<script type="text/javascript" src="{{ pathto('_static/search-focus.js', 1) }}"></script>
8083
<script type="text/javascript" src="{{ pathto('_static/themetoggle.js', 1) }}"></script>

‎python_docs_theme/static/copybutton.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ function getCopyableText(rootElement) {
2323
return rootElement.innerText.trim()
2424
}
2525

26+
const copyButtonLabels = document.currentScript.dataset
27+
2628
const loadCopyButton = () => {
2729
const button = document.createElement("button")
2830
button.classList.add("copybutton")
2931
button.type = "button"
30-
button.innerText = _("Copy")
31-
button.title = _("Copy to clipboard")
32+
button.innerText = copyButtonLabels.copy
33+
button.title = copyButtonLabels.copyToClipboard
3234

3335
const makeOnButtonClick = () => {
3436
let timeout = null
@@ -50,9 +52,9 @@ const loadCopyButton = () => {
5052
return
5153
}
5254

53-
buttonEl.innerText = _("Copied!")
55+
buttonEl.innerText = copyButtonLabels.copied
5456
timeout = setTimeout(() => {
55-
buttonEl.innerText = _("Copy")
57+
buttonEl.innerText = copyButtonLabels.copy
5658
}, 1500)
5759
}
5860
}

0 commit comments

Comments
 (0)