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

nbTranslate #838

Merged
merged 18 commits into from
Jan 13, 2017
Merged

nbTranslate #838

merged 18 commits into from
Jan 13, 2017

Conversation

jfbercher
Copy link
Member

nbTranslate -- helps translating notebooks -- provides multilanguage support

Suggestions for a better name would be very welcome, as well as general improvements directions

This extension

  • helps converting markdown cells in a notebook from a language to another (optionally using Google translate),
  • enables to selectively display cells from a given language in a multilanguage notebook.

Basically, the extension allows to copy the original cell into a new one for editing and translating. Optionally, the cell source text can be passed through google translate and the result inserted in the new cell. Basic markdown structures (e.g. bold, emphasis, lists) are preserved/restored after conversion, to the best extent, but this is not perfect, and usually one has to correct the text and structures afterward. Similarly, equations are extracted before conversion and restored in the result.

The extension has been written to play nicely with

  • latex_envs (must be upgraded to version >= 1.3.6)
  • toc2

An exporter is provided to extract one language from the multilanguage notebook.


demo1


demo2

See the README here for further details.

@juhasch
Copy link
Member

juhasch commented Jan 8, 2017

I just tried it. Very nice!
On thing I noticed is that in markdown cell this

<img src="images/dashboard_files_tab.png" width="791px"/>

gets translated to

\u003cImg src = "images / dashboard _dateien_ tab.png" width = "791px" /\u003e

(when translating English to German with the Jupyter Basics example notebook)

@jfbercher
Copy link
Member Author

jfbercher commented Jan 8, 2017

Thanks @juhasch. That is right. Html structures are also translated! I have added a small fix for that, similar to what is done for maths: remove the structures before conversion, put marks at their original places, and reinsert html after conversion at these places.
This is not always perfect since sometimes translation changes elements order and then the html structures can be mixed up; eg <something> text </something> may become </something><something> text in some situations. A more complete approach would need to implement something like an html parser and call the translation for the html data. But a bit complicated for this simple app.

[I would not be surprised if there exists a switch to instruct google translate to ignore html structures. But I have not be able to find it..]

@juhasch
Copy link
Member

juhasch commented Jan 9, 2017

I think not always being perfect is OK. The <img> tags are frequently used in notebooks, so it makes sense to handle them.

@jcb91
Copy link
Member

jcb91 commented Jan 9, 2017

neat!

I think not always being perfect is OK

👍 Yes, me too. If you want it to work reliably on everything, I think it'd be possible by extending a marked parser/lexer/renderer, but it'd certainly be a non-trivial amount of work! Regex works perfectly well enough most of the time, particularly as it's a non-destructive operation where the original text is retained.

The build failure in the conda_env travis case is a result of the updated jupyter_latex_envs requirment version - you'll need to update the conda-forge/jupyter_latex_envs-feedstock recipe to have the newer version made available from conda-forge. Incidentally, this is the reason I put the conda_recipe environment on travis, so that we'd spot things like this that break the conda build that otherwise I know I'd just miss at least half the time. For updating the feedstock recipe, see conda-forge/jupyter_highlight_selected_word-feedstock#3 as an example. Essentially, unless requirements or imports have changed, you can just update version number & checksum (which I get from pypi.io's download files, to make sure the version I'm referencing is available there, but could equally be done locally on the sdist tar.gz). See the instructions in the readme for an important point - make sure to fork the feedstock & submit a PR, as anything pushed directly to the conda-forge repo gets uploaded to conda-forge channel. Let me know if you have problems 👌

@jfbercher
Copy link
Member Author

I have updated the conda-forge/jupyter_latex_envs-feedstock recipe. The tests for nbTranslate now pass.

@jcb91
Copy link
Member

jcb91 commented Jan 10, 2017

Looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants