google-translate-api icon indicating copy to clipboard operation
google-translate-api copied to clipboard

Allow 'format' queryparam to be passed in to Google Translate API

Open thejeff77 opened this issue 7 years ago • 3 comments

Allow the 'format' query parameter string so that the user can pass in html to the google translate API.

thejeff77 avatar Sep 30 '18 21:09 thejeff77

I am not familiar with the google translate API, but I was able to pass raw HTML to the translate api and it seems to work fine:

// test.js
const translate = require("google-translate-api");
const content = `<h3>a cat plus a rat plus a dog, is a hog</h3>
<h4>Yes, the above statement is true</h4>`;
translate(content, { from: "en", to: "es" })
  .then(res => {
    console.log("res.text:", res.text);
  })
  .catch(err => {
    console.error("translate: error! err:", err);
  });
$ node test.js
res.text: <h3> un gato más una rata más un perro, es un cerdo </h3>
<h4> Sí, la declaración anterior es verdadera </h4>

Was there a more specific issue you were having with passing in html?

jalMogo avatar Nov 05 '18 07:11 jalMogo

Forgive me, but you're answering issues for a library which talks to the Google Translate API but you have no familiarity with it? That is interesting.

The translate API is documented publicly here:

https://cloud.google.com/translate/docs/reference/translate

From the docs linked to above:

format | string                                        The format of the source text, in either HTML (default) or plain-text. A                     value of html indicates HTML and a value of text                     indicates plain-text.
-- | --

It seems one of the things that is missing from this library to be able to manually specify in the request. Depending on the value of this param, it will override the default behavior of the service & can change the response to a desirable outcome given the request body.

It also appears that manual specification of the model param is also not supported by this library.

It would be pretty cool to get full support for all API options through this library, and luckily there aren't that many options for the API, so supporting it fully isn't far off.

thejeff77 avatar Nov 10 '18 19:11 thejeff77

Was there a more specific issue you were having with passing in html?

in my case, i need character-exact html translations with google's free API so i ended up writing an html2google encoder in my translate.js script

also see my post in Prohibit the translation of pieces of text in Google Translate

milahu avatar May 26 '21 12:05 milahu