Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make copybutton messages translatable #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions python_docs_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@

{% trans sphinx_version=sphinx_version|e %}Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> {{ sphinx_version }}.{% endtrans %}
</div>
{# Translated messages used by copybutton #}
{% if builder != "htmlhelp" and not embedded %}
<div class="copybutton-msg" style="display: none">
<p id="copybutton-hide-text">{% trans %}Hide the prompts and output{% endtrans %}</p>
<p id="copybutton-show-text">{% trans %}Show the prompts and output{% endtrans %}</p>
</div>
{% endif %}
{% endblock %}
8 changes: 6 additions & 2 deletions python_docs_theme/static/copybutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ $(document).ready(function() {
'.highlight-default .highlight');
var pre = div.find('pre');

// search for the translated prompt strings and fallback to use English if not found
var hide_text_p = $('#copybutton-hide-text');
var hide_text = hide_text_p.length > 0 ? hide_text_p.text() : "Hide the prompts and output";
var show_text_p = $('#copybutton-show-text');
var show_text = show_text_p.length > 0 ? show_text_p.text() : "Show the prompts and output";

// get the styles from the current theme
pre.parent().parent().css('position', 'relative');
var hide_text = 'Hide the prompts and output';
var show_text = 'Show the prompts and output';
var border_width = pre.css('border-top-width');
var border_style = pre.css('border-top-style');
var border_color = pre.css('border-top-color');
Expand Down