You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The help text for [>>>] toggle always in English #23
Thank you for your prompt attention. It's not something I've done, either. I looked at view-source:https://docs.python.org/3/tutorial/introduction.html. It contains
Perhaps best not to change this. Instead load an extra file, something like static/fr_text.js. that contains all the language variable text. This file should I think be part of the FRench translation of the docs (or generated from such). Once you've got that, use it in copybutton.js.
There are libraries and tools associated with GNU gettext, that will help you with this. I hope this helps.
While is it hard to add translation directly into the javascript file, I was wondering if it is possible to add the strings in a HTML file, and use jQuery to fetch the translated string back.
Sphinx has the ability to extract sentences from HTML. For example, we could add the strings into layout.html, on which all the HTML pages are based:
<divstyle="display: none">
<pid="copybutton-hide-text">{%trans%}Hide the prompts and output{%endtrans%}</p>
<pid="copybutton-show-text">{%trans%}Show the prompts and output{%endtrans%}</p>
</div>
And in the copybutton.js, we try to fetch the translated string and provide the English fallback:
// search for the translated prompt strings and fallback to use English if not foundvarhide_text_p=$('#copybutton-hide-text');varhide_text=hide_text_p.length>0 ? hide_text_p.text() : "Hide the prompts and output";varshow_text_p=$('#copybutton-show-text');varshow_text=show_text_p.length>0 ? show_text_p.text() : "Show the prompts and output";
I have some questions about this approach:
Where in the HTML template should we place the translated string? In block footer or header?
Should we instead interpolate the javascript itself, say, treating copybutton.js like a Sphinx template so it directly supports i18n?
Will there be a certain configuration where a user might accidentally see this div and get confused?
I can submit a PR if people think the approach is reasonable.
On Sat, Feb 16, 2019, 1:12 PM Liang-Bo Wang ***@***.***> wrote:
While is it hard to add translation directly into the javascript file, I
was wondering if it is possible to add the strings in a HTML file, and use
jQuery to fetch the translated string back.
Sphinx has the ability to extract sentences from HTML. For example, we
could add the strings into layout.html, on which all the HTML pages are
based:
<div 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>
And in the copybutton.js, we try to fetch the translated string and
provide the English fallback:
// search for the translated prompt strings and fallback to use English if not foundvar 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";
I have some questions about this approach:
1. Where in the HTML template should we place the translated string?
In block footer or header?
2. Should we instead interpolate the javascript itself, say, treating
copybutton.js like a Sphinx template so it directly supports i18n?
3. Will there be a certain configuration where a user might
accidentally see this div and get confused?
I can submit a PR if people think the approach is reasonable.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#23 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPUc98QYUqid5cUJfdTLGnixaVYkSIcks5vOHRAgaJpZM4WGevB>
.
Activity
theacodes commentedon Aug 21, 2018
Tricky. Not sure how to internationalize text within a JS file.
We could see about moving that text into the Jinja templates and use JS to show/hide it.
jfine2358 commentedon Aug 21, 2018
Thank you for your prompt attention. It's not something I've done, either. I looked at
view-source:https://docs.python.org/3/tutorial/introduction.html. It containsPerhaps best not to change this. Instead load an extra file, something like
static/fr_text.js. that contains all the language variable text. This file should I think be part of the FRench translation of the docs (or generated from such). Once you've got that, use it incopybutton.js.There are libraries and tools associated with GNU gettext, that will help you with this. I hope this helps.
theacodes commentedon Aug 21, 2018
I've honestly never done translation stuff, but I'm happy to give it a shot once I find some time.
In the meantime, it would be awesome if anyone with specific experience here can help.
jfine2358 commentedon Aug 21, 2018
This might be helpful.
https://docs.djangoproject.com/en/2.1/topics/i18n/translation/#internationalization-in-javascript-code
terryjreedy commentedon Aug 21, 2018
I would talk to the people doing doc translations: https://devguide.python.org/experts/#documentation-translations. Discussion on https://mail.python.org/mailman/listinfo/doc-sig
ccwang002 commentedon Feb 16, 2019
While is it hard to add translation directly into the javascript file, I was wondering if it is possible to add the strings in a HTML file, and use jQuery to fetch the translated string back.
Sphinx has the ability to extract sentences from HTML. For example, we could add the strings into
layout.html, on which all the HTML pages are based:And in the
copybutton.js, we try to fetch the translated string and provide the English fallback:I have some questions about this approach:
footerorheader?copybutton.jslike a Sphinx template so it directly supports i18n?I can submit a PR if people think the approach is reasonable.
theacodes commentedon Feb 17, 2019
Make copybutton messages translatable
hugovk commentedon Apr 6, 2025
Fixed by #225.