🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

whatlang

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

whatlang

simple language detection module

0.1.0-1
latest
npm
Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
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

language

FAQs

Package last updated on 24 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