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

Allow internationalization of code folding buttons using pandoc #932

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
28 changes: 22 additions & 6 deletions inst/rmd/h/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@
window.initializeCodeFolding("$code_folding$" === "show");
$endif$
});
// Show/Hide button names internationalization.
// Variables used in codefolding.js.
$if(code_folding_show_btn)$
var ShowCode = $code_folding_show_btn$;
$else$
var ShowCode = 'Show';
$endif$
$if(code_folding_hide_btn)$
var HideCode = $code_folding_hide_btn$;
$else$
var HideCode = 'Hide';
$endif$
</script>
$endif$

Expand Down Expand Up @@ -386,11 +398,18 @@

$if(code_menu)$
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span>$if(code_folding_button)$$code_folding_button$$else$Code$endif$</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" style="min-width: 50px;">
$if(code_folding)$
<li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
<li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
<li><a id="rmd-show-all-code" href="#">
$if(code_folding_show)$$code_folding_show$$else$Show All Code$endif$
</a></li>
<li><a id="rmd-hide-all-code" href="#">
$if(code_folding_hide)$$code_folding_hide$$else$Hide All Code$endif$
</a></li>
$if(source_embed)$
<li role="separator" class="divider"></li>
$endif$
Expand All @@ -400,11 +419,8 @@
$endif$
</ul>
</div>

$endif$

$endif$

$if(title)$
<h1 class="title toc-ignore">$title$</h1>
$if(subtitle)$
Expand Down
9 changes: 6 additions & 3 deletions inst/rmd/h/navigation-1.1/codefolding.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Variables defined in default.html.
// var ShowCode = 'Show';
// var HideCode = 'Hide';

window.initializeCodeFolding = function(show) {

Expand Down Expand Up @@ -30,7 +33,7 @@ window.initializeCodeFolding = function(show) {
$(this).detach().appendTo(div);

// add a show code button right above
var showCodeText = $('<span>' + (show ? 'Hide' : 'Code') + '</span>');
var showCodeText = $('<span>' + (show ? HideCode : ShowCode) + '</span>');
var showCodeButton = $('<button type="button" class="btn btn-default btn-xs code-folding-btn pull-right"></button>');
showCodeButton.append(showCodeText);
showCodeButton
Expand All @@ -49,10 +52,10 @@ window.initializeCodeFolding = function(show) {

// update state of button on show/hide
div.on('hidden.bs.collapse', function () {
showCodeText.text('Code');
showCodeText.text(ShowCode);
});
div.on('show.bs.collapse', function () {
showCodeText.text('Hide');
showCodeText.text(HideCode);
});
});

Expand Down