Recently I came a cross to the Google Translate's add-on for Chrome. Basically you have a web page and it translates that web page for you while keeping its structure.
I came to the conclusion that it takes the HTML of that web page and translates the text inside it. For example:
<p>To get it, first you need to have selenium and the web driver install. You can let Python fire the web browser, open the web page URL and grab the HTML source.</p>
<p>Um es zu bekommen, müssen Sie zuerst Selen und den Web-Treiber installieren. Sie können Python den Webbrowser auslösen lassen, die URL der Webseite öffnen und die HTML-Quelle abrufen.</p>
Everything is good until now. However when there is another tag inside the
tag, for example:
<p>To get it, first <strong>you need to</strong> have selenium and the web driver install. You can let Python fire the web browser, open the web page URL and grab the HTML source.</p>
I can't figure out how they decide where to put the
<strong> tag when the translation is complete.
The text inside the
<strong> tags translates into "du brauchst" which is not in the translation. So they can't possibly take the sub-tag and translate it seperately.
Only way I could think of is actually to have word-by-word match between the original sentence and the translation. For example model translated "need" as "brauchst" and "you" as "du" etc. so that they can accurately match the sub-tags.
To achieve it I tried to use attention weights but no luck. I'm not even sure if it's even possible. I also tried a scoring metrics like bleu and hope to get a "similarity" between each word but it didn't do.
I just couldn't figure it out and decided to ask you guys. How do you think it's done?