Hello!
I had a task to translate part of the blocks on the page into English.
For example, there is such a div block:

<div> <h3>Заголовок</h3> <ul> <li>Текст</li> <li>Текст</li> <li>Текст</li> </ul> <p>Текст</p> ... </div> 

We need to take the whole block, and transfer it to the translation tool. Only text in Russian should be translated, tags should be ignored you get the following:

 <div> <h3>Title</h3> <ul> <li>Text</li> <li>Text</li> <li>Text</li> </ul> <p>Text</p> ... </div> 

I tried to do the translation through yandex tranlate, but it breaks the tags.

Who knows if a similar tool exists with an API?

    2 answers 2

    And it did not try? https://support.google.com/translate/answer/2534601?hl=en To translate only a block, not the whole page, you can probably replace the div in the iframe and implement the translation plugin in it

    • Not exactly what you need, I would like without additional. plugins do it. But thanks anyway for the hint. - QWERTY

    Found a solution!
    Text translation is performed on the server side via google translate translation of sites.
    It happens like this:
    1. I first translate the entire page through

     $enPage = file_get_contents("https://translate.google.ru/translate?sl=ru&tl=en&js=y&prev=_t&hl=ru&ie=UTF-8&u=mysite.com/page_test.html"); 
    1. Then the DOM manipulator (for example, phpQuery) pick out the blocks I don't need and replace them with the same blocks only those already transferred from $ enPage