How to get around some google translate restrictions

I will describe two feints with which you can bypass some of the limitations of google translate.

1. The limit on the number of characters for google translate online is either 3900 or 5000 characters. Sometimes you need more, but reluctance to create an html file with text. To work around this limitation, create an html file with the following content:

<!DOCTYPE HTML>
<html>
 <head>
   <title>Google translator without limits.</title>
 </head>

 <body>
Google translator without limits.  Here comes the English text. It is necessary that translator to work. 
If you do not translate from English, insert the text in your language. Not in the window, but in html.<br>
<textarea id="test" rows="10" cols="45" placeholder="Paste text into this window."></textarea>
<p id="result"></p>
<script>
var textarea = document.getElementById('test');
var result = document.getElementById('result');

function updateResult() {
    result.innerHTML = textarea.value.replace(/\n/g, '<br>');
}

textarea.oninput = updateResult;

</script>
 </body>
</html>


Open this file in Google Chrome. If your translator does not work automatically, launch it through the right mouse button. If you need to translate from non-English, insert in the html several sentences in the language you need, instead of those written there after the body tag.

As you can see, we have the textarea tag in which we insert the text for translation. And the p tag, which gets the text immediately after insertion. A google translator translates it on the fly. The replace method replaces the end of the line with the br tag.

2. Is it possible to get the translation result using javascript? It turns out yes. To verify this, create the following html file:


<!DOCTYPE HTML>
<html>
 <head>
   <title>alert(translation)</title>
 </head>

 <body>
   <div id="div1">This work presents the efficient, matrix-free finite-element library hyper.deal for solving partial differential equations in two to six dimensions with high-order  discontinuous Galerkin methods.It builds upon the low-dimensional finite-element library deal.II to create complex low-dimensional meshes and to operate on them individually. These meshes are combined via a tensor product on the fly and the library provides new special-purpose highly optimized matrix-free functions exploiting domain decomposition as well as shared memory via MPI-3.0 features.</div>

  <a href="URL" onclick="alert(document.getElementById('div1').innerHTML);">...</a>

 </body>
</html>

Open the file in a browser, enable the translator and click on the link with three dots. You will see the following:


<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">    ​​     hyper.deal         -        .       . II         . </font><font style="vertical-align: inherit;">       ,         ,   ,       MPI-3.0.</font></font>

As you can see, font tags have been added, which are easy to remove programmatically.

This opens up new possibilities in the free translation of sites into more than 100 languages. You can place each sentence in div tags and every 5 seconds check all the divs on the page for font tags to appear. As the visitor scrolls the page, all new divs are translated, and they can be sent ajax to the server.

Although the quality of the translation has improved, it is still far from perfect. I would make it possible for readers to offer their own version of the translation. To do this, make each point at the end of the sentence a link, when clicked, a sentence appears in the source language and translation options proposed by other readers.

Well it is possible to translate Habr into 100 languages. If you do not, I will take care of it myself and earn a lot of money. I don’t really need a lot of money, but I have several homeless relatives. I would buy them an apartment by the sea.

I say goodbye to this. Successes.

All Articles