Skip to content

Commit 5b434e7

Browse files
committed
Make copybutton messages translatable
See issue python#23.
1 parent 6487f56 commit 5b434e7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

python_docs_theme/layout.html

+7
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,11 @@
5757

5858
{% trans sphinx_version=sphinx_version|e %}Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> {{ sphinx_version }}.{% endtrans %}
5959
</div>
60+
{# Translated messages used by copybutton #}
61+
{% if builder != "htmlhelp" and not embedded %}
62+
<div class="copybutton-msg" style="display: none">
63+
<p id="copybutton-hide-text">{% trans %}Hide the prompts and output{% endtrans %}</p>
64+
<p id="copybutton-show-text">{% trans %}Show the prompts and output{% endtrans %}</p>
65+
</div>
66+
{% endif %}
6067
{% endblock %}

python_docs_theme/static/copybutton.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ $(document).ready(function() {
88
'.highlight-default .highlight');
99
var pre = div.find('pre');
1010

11+
// search for the translated prompt strings and fallback to use English if not found
12+
var hide_text_p = $('#copybutton-hide-text');
13+
var hide_text = hide_text_p.length > 0 ? hide_text_p.text() : "Hide the prompts and output";
14+
var show_text_p = $('#copybutton-show-text');
15+
var show_text = show_text_p.length > 0 ? show_text_p.text() : "Show the prompts and output";
16+
1117
// get the styles from the current theme
1218
pre.parent().parent().css('position', 'relative');
13-
var hide_text = 'Hide the prompts and output';
14-
var show_text = 'Show the prompts and output';
1519
var border_width = pre.css('border-top-width');
1620
var border_style = pre.css('border-top-style');
1721
var border_color = pre.css('border-top-color');

0 commit comments

Comments
 (0)