Wynn Netherland changelog.com/posts

translate.js - a JavaScript Babelfish

Translate.js from Marak Squires might not know that the meaning of life is 42, but it can prompt you to ask “¿Cuál es el significado de la vida?” en español.

The JavaScript library wraps the Google Translate API and works in both the browser as well as server-side environments like Node.js:

var sys = require('sys');
var colors = require('./colors'); // colors are fun!
var translate = require('./translate');

// note: the translator is  English=>Spanish by default
translate.text('I want tacos please.', function(text){

  sys.puts('I want tacos please.'.red + ' => '.cyan + text.yellow);
  var input = 'Spanish', output = "Japanese";
  translate.text({input:input,output:output}, text, function(text2){

    var input = 'Japanese', output = "English";
    sys.puts(text.yellow + ' => '.cyan + text2.blue);
    translate.text({input:input,output:output}, text, function(text3){

       sys.puts(text2.blue + ' => '.cyan + text3.red);
       sys.puts('English'.red+'=>'+'Spanish'.yellow+'=>'+'Japanese'.blue+'=>'+'English'.red  +'ntaco request has been normalized. ^_^'.green);
    });
  }); 
});

Go ahead and give it a whirl with Marak’s nifty demo available.

[Source on GitHub] [Demo]


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00