From 5b434e775daa022b43291313c17d572e186b66b2 Mon Sep 17 00:00:00 2001 From: Liang-Bo Wang Date: Sun, 17 Feb 2019 16:06:07 -0600 Subject: [PATCH] Make copybutton messages translatable See issue #23. --- python_docs_theme/layout.html | 7 +++++++ python_docs_theme/static/copybutton.js | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/python_docs_theme/layout.html b/python_docs_theme/layout.html index 822e6ed..a312a97 100644 --- a/python_docs_theme/layout.html +++ b/python_docs_theme/layout.html @@ -57,4 +57,11 @@ {% trans sphinx_version=sphinx_version|e %}Created using Sphinx {{ sphinx_version }}.{% endtrans %} + {# Translated messages used by copybutton #} + {% if builder != "htmlhelp" and not embedded %} + + {% endif %} {% endblock %} diff --git a/python_docs_theme/static/copybutton.js b/python_docs_theme/static/copybutton.js index f5960d2..b55bbaf 100644 --- a/python_docs_theme/static/copybutton.js +++ b/python_docs_theme/static/copybutton.js @@ -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');