Socket
Socket
Sign inDemoInstall

whatlang

Package Overview
Dependencies
0
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    whatlang

simple language detection module


Version published
Weekly downloads
8
increased by700%
Maintainers
0
Created
Weekly downloads
 

Readme

Source

whatlang.js for node.js

a simple wrapper around the google language detection API (V1)

http://code.google.com/apis/language/translate/v1/using_rest_langdetect.html

install

  var whatlang = require('/path/to/whatlang.js');
  

usage

  //whatlang(query, callback, parameterObject)
  whatlang('Ich bin ein kleines maedchen und tanze auf der berliner mauer.');
  
  /* prints on the console
  { responseData: { 
      language: 'de',
      isReliable: true,
      confidence: 0.66124046
      },
    responseDetails: null,
    responseStatus: 200,
    requestData: { 
      query: 'Ich bin ein kleines maedchen und tanze auf der berliner mauer.' 
    } 
  }
  */
  
   //with a custom callback function 
   var langinfo = whatlang('Ich bin ein kleines maedchen.',
   function(langinf){ console.log(langinf.responseData.language); }); 
   // -> de
   
   //with a parameterObject
   //see http://code.google.com/apis/language/translate/v1/using_rest_langdetect.html#request_format for list of parameters
   var langinfo = whatlang('Ich bin ein kleines maedchen.',
   function(langinf){ console.log(langinf.responseData.language); },
   { userip:'74.125.224.72', key:'boguskey' });
   //throws an "ResponseStatus 400 Error: invalid key"
   

additional methods (chaining supported)

   whatlang.setDefaultKey('your key here').setDefaultUserIp('74.125.224.72').detect('this is a very english english sentence');
   
   //set your google key
   whatlang.setDefaultKey('your key here');
   
   //set your default user ip
   whatlang.setDefaultUserIp('74.125.224.72');
   
  //whatlang.detect() === whatlog()
   whatlang.detect('a string');
   

  
  

Keywords

FAQs

Last updated on 24 Apr 2011

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc