Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 20, 2022 07:51 am GMT

How to translate HTML for free using google translate.

Introduction

While working on a new feature for my side project eduo instrukcije, I needed to translate HTML to other languages which was challenging to do for free. Google translate api has parameter "format" that when set to "html" ignores all tags and translates only real text, but it's not free. There are couple of reversed engineered google translate apis that are totally free, but none of them had the format option available. Then I found out that you can use Google Translate api inside google sheets, and you can create real apis with google sheets, and I think that's pretty cool.

How to do it?

First open google sheets and open a new app script
Image description

Then paste this doGet function

function doGet(e){  var params = e.parameter;  var translation = LanguageApp.translate(params.text, params.froml, params.to, {contentType: 'html'});  return ContentService.createTextOutput(translation).setMimeType(ContentService.MimeType.TEXT);}

Then go and deploy your api

Image description

Make sure that type is Web app and that everyone has access to it
Image description

Then copy your url Image description

Testing

Go to your url and add query parameters
Image description

And that's it!


Original Link: https://dev.to/jakovglavac/how-to-translate-html-for-free-using-google-translate-2nf

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To