Sha256: 5d3bef9443f172868660c1220f1800d0d0effebc5cce006588771a46ae8470eb

Contents?: true

Size: 1.17 KB

Versions: 50

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env   node
module.paths.push(["/usr/local/lib/node_modules"]);
function output(te) {
  console.log(te);
}

const translate = require("google-translate-extended-api");

const a1 = process.argv[2];
const a2 = process.argv[3];

exit = process.exit;


async function translate_sentence(sentence) {
 var langs = Object.keys(translate.languages);
  var results = {};
  //console.log(sentence)
  for (var l of langs) {
    if (l == "auto" || l == "getCode" || l == "isSupported"||(a2  && l != a2)      ) continue;
    async function a() {
      var res = "";
      for (const s of sentence.split(/\s*(\.|\n)(\s*|$)/)) {
  //    	console.log("F");
        if (s.trim() == "") continue;
        const b = s + ". ";
        //process.stderr.write(b);
        const r = ((await translate(b, "en", l)).translation || "") + " ";
        res += r;
        process.stderr.write(r);
//        if (argv[1] !== undefined) break;
      }
      return res;
//      return res.trim(;
    }
    const res = await a();
    results[l] = res;
    if (a2) break;
  }
 // process.stderr.write("]\n");
  output(results);
}

function main_() {
  ts(a1);
}

function ts(s) {
  translate_sentence(s);
}

main_();

Version data entries

50 entries across 49 versions & 6 rubygems

Version Path
ufos-1.0.94 ./other/experimental_code/translate
aliens-1.0.94 ./other/experimental_code/translate
freespeech-1.0.94 ./other/experimental_code/translate
elonmusk-1.0.94 ./other/experimental_code/translate
politics-1.0.94 ./other/experimental_code/translate
democracy-1.0.94 ./other/experimental_code/translate
democracy-1.0.93 ./other/experimental_code/translate
ufos-1.0.91 ./other/experimental_code/translate
aliens-1.0.91 ./other/experimental_code/translate
freespeech-1.0.91 ./other/experimental_code/translate
elonmusk-1.0.91 ./other/experimental_code/translate
politics-1.0.91 ./other/experimental_code/translate
politics-1.0.89 ./other/experimental_code/translate
ufos-1.0.87 ./other/experimental_code/translate
aliens-1.0.87 ./other/experimental_code/translate
freespeech-1.0.87 ./other/experimental_code/translate
elonmusk-1.0.87 ./other/experimental_code/translate
politics-1.0.87 ./other/experimental_code/translate
ufos-1.0.88 ./other/experimental_code/translate
aliens-1.0.88 ./other/experimental_code/translate