Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

translate

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

translate

translate text from one language to another on node.js and the browser. 30+ languages supported, simple as cake.

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.7K
increased by25.43%
Maintainers
0
Weekly downloads
 
Created
Source

translate.js - translates text to different languages, simple as cake

v0.6.0

USAGE

node.js -

    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);
        });
      }); 
    });

browser -

      <!-- 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>

languages

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

fun facts

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

Authors

Andrew Lunny (alunny), Marak Squires, Google

FAQs

Package last updated on 05 Apr 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc