Wednesday, March 28, 2018

Using the Google Translate widget to translate almost any foreign website

The following text was written for my "Study of the Month" article for April 2018, but is taken out and published here in advance, so as to not bloat the article more than necessary.


How to get a fast overview on longer foreign websites

Let us talk about how the research for this article was done. While the Google Translate service can only translate a part of the page if entered directly on the website, you can use its widget to translate the entire page, but must modify the code.
First download the website to translate (in this case the Russian article), best might be to download it as “Web page, complete”. Now rename the extension to .html.txt and enter here your widget preference: https://translate.google.com/manager/website/
In this case, after clicking that you want to add the widget to your website, enter any website in the field - it does not matter, it seems, and use the website language - in this case “Russian” - in the field below. Now click on “Next”. Add all languages or specific languages - I chose specific languages and selected only English, as to make the widget easier to use for me. Choose a preferred display mode, and disable all checkboxes below at “Advanced”. I chose “Inline” and “Dropdown only”, but all should work. Possibly you should not use “Automatic”, but you can try that also to see if it works.
Click on “Get Code” now. Important: You must modify the code by adding a http: after the prior to the website starting with //translate.google.com/ - if you don’t do this, the widget will try to load it from your file system where no such file exists. Copy this modified code now into the html.txt file under the line </head> or copy the original code and modify it there. You might want to add empty lines prior to and after the code to find it easier if you did something wrong and need to replace it later.

Now save this, close the file and rename the format from .html.txt to .html which enables you to load it into your web browser. If you use a security tool that disables JavaScript, activate the JavaScript for your file system and for translate.googleapis.com and the top left corner of the page should show the widget now. After this, click on it and select the language you want to translate it to - in my case the only option is English. After a few seconds, the entire page is translated. Strangely, the translation is different from what it is on Google Translate directly, but you should still be able to understand some of the content even with the poor translation. Better readable results require to translate small text snippets at once on the Google Translate website instead, making the widget rather an overview tool than a really useful translation tool. In any case I envy those who understand Russian!

Warning: Never download or visit websites you don’t trust, as this can lead to an infection of your computer if the website contains a virus or other malware! Common sense and caution is one of the most important tools to prevent infections, in some opinions even more than a virus scanner (this does not mean you shouldn’t have some form of software that protects you, however. Personally I use a military-grade sandbox/whitelist tool that also protects system files in addition to the built-in Windows Defender). When in doubt, run your browser in a sandbox (see the Wikipedia article), check the safety prior to visiting the page at all with a scan tool like Virustotal and, when you visit it, modify the script in real-time with your browser’s tools.

No comments:

Post a Comment