-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
The help text for [>>>] toggle always in English #23
Comments
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. |
Thank you for your prompt attention. It's not something I've done, either. I looked at <script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script> Perhaps best not to change this. Instead load an extra file, something like |
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. |
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 |
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 <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 // 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"; I have some questions about this approach:
I can submit a PR if people think the approach is reasonable. |
I think it's a pretty reasonable approach.
…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>
.
|
See, for example, https://docs.python.org/fr/3/tutorial/introduction.html. It applies to all interactive code examples.
This is https://bugs.python.org/issue34452, transferred here, as a third party issue. It is related to
PEP 545 - Python Documentation Translations.
Here's what I've found. The purpose of python_docs_theme/static/copybutton.js is
To do this it contains code
Somehow, this text needs to be internationalised.
The text was updated successfully, but these errors were encountered: