Changelog

JavaScript Icon changelog.com

translate.js - a JavaScript Babelfish

logged by @logbot 2010-07-03T01:54:00Z permalink #javascript #node

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]

0:00 / 0:00