var sys = require('sys');
var colors = require('colors'); // colors are fun!
var translate = require('./lib/translate');
// note: the translator is English=>Spanish by default
translate.text('I want tacos please.', function(err, text){
sys.puts('I want tacos please.'.red + ' => '.cyan + text.yellow);
var input = 'Spanish', output = "Japanese";
translate.text({input:input,output:output}, text, function(err, text2){
var input = 'Japanese', output = "English";
sys.puts(text.yellow + ' => '.cyan + text2.blue);
translate.text({input:input,output:output}, text, function(err, text3){
sys.puts(text2.blue + ' => '.cyan + text3.red);
sys.puts('English'.red+'=>'+'Spanish'.yellow+'=>'+'Japanese'.blue+'=>'+'English'.red +'\ntaco request has been normalized. ^_^'.green);
});
});
});
<!-- main translate.js library -->
<script type="text/javascript" src="./lib/translate.js"></script>
<!-- load up the languages definition file -->
<script type="text/javascript" src="./lib/languages.js"></script>
<!-- jquery not required, just used in the demo page -->
<script type="text/javascript" src="./vendor/jquery.js"></script>
<script type="text/javascript">
var languages;
$(document).ready(function(){
languages = getLangs();
// populate the select box
for(var lang in languages){
$('#langInput').append('<option value = "'+lang+'">' + lang + '</option>');
}
for(var lang in languages){
$('#langOutput').append('<option value = "'+lang+'">' + lang + '</option>');
}
/***** NAMED EVENTS *****/
$(document).bind('##TRANSLATE_TEXT##', function(e){
$('#run').attr('disabled','disabled');
$('#run').val('translating...');
var input = $('#langInput').val(), output = $('#langOutput').val();
translate.text({input:input,output:output}, $('#theCode').val(), function(result){
$('#run').attr('disabled','');
$('#run').val('<== translate ==>');
$('#output').val( result );
});
});
/**** END NAMED EVENTS ****/
/**** BIND UI EVENTS ****/
// select box change
$('#langSelector').change(function(){
$(document).trigger('##CHANGE_LANGUAGE##', {"fontName":$(this).val()})
});
$('#run').click(function(e){
$(document).trigger('##TRANSLATE_TEXT##');
});
/**** END UI BIND EVENTS ****/
// little bit of a onReady hack. i'll fix the API a bit so this can be done better
$(document).trigger('##CHANGE_LANGUAGE##', {"fontName":'Doh'});
$('#langInput').val('English');
$('#langOutput').val('Spanish');
});
</script>
Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese | Croatian Czech Danish Dutch English Estonian Filipino Finnish French Galician | Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish | Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian Persian | Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish | Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish |
translate.js uses the google api and requires an internet connection
if you want to actually hear the translated text as audio you could use say.js