Note: Please check out this interesting post on a NotebookTranslate function(direct link to cloud notebook), by Thomas Colignatus.
Starting with version 11.1 the Wolfram Language includes a new text translation function, aptly named TextTranslation
.
Recently I made a post which showed how you can use this function to query Wolfram|Alpha in any language.
But there is so much more you can do with this function. In this post I will share the idea of a TranslationCell
function, which creates a regular text cell, with an attached button which lets you toggle from English to a specific language.
Let's start with a famous English quote from the recent past:
We choose to go to the Moon! We choose to go to the Moon in this decade and do the other things, not because they are easy, but because they are hard; because that goal will serve to organize and measure the best of our energies and skills, because that challenge is one that we are willing to accept, one we are unwilling to postpone, and one we intend to win, and the others, too.
And let's assign this quote to a variable named quote
:
quote = "We choose to go to the Moon! We choose to go to the Moon in \
this decade and do the other things, not because they are easy, but \
because they are hard; because that goal will serve to organize and \
measure the best of our energies and skills, because that challenge \
is one that we are willing to accept, one we are unwilling to \
postpone, and one we intend to win, and the others, too."
I don't want to get to deeply into the implementation details, but if you are interested in them I recommend perusing the code for it on my GitHub project:
https://github.com/arnoudbuzing/prototypes/blob/master/Prototypes/Notebook.wl#L148
And if you want to try this function, simply install the paclet that has this function included:
PacletInstall["https://github.com/arnoudbuzing/prototypes/releases/download/v0.2.5/Prototypes-0.2.5.paclet"]
So let's take a look at an example:
TranslateCell[ quote, "Spanish" ]
This creates the following cell:
And clicking on the button will translate the English text to Spanish (this may take 1-2 seconds since it is calling a translation service):
Clicking the button again reverts to English (this is fast, because it stored the original text in the cell as metadata):
And of course this works for many languages, like Russian:
TranslationCell[ quote, "Russian" ]
Or Swedish:
TranslationCell[ quote, "Swedish" ]
Or Arabic:
TranslationCell[ quote, "Arabic" ]
It might be useful to extend this idea to support translation between any two languages ( "LanguageA" -> "LanguageB" ), so I think this will be the next improvement.
Let me know what you think! I am interested in feedback and additional ideas on how to use TextTranslation
in the Wolfram Language!