Small convenience library allowing developers to easily interact with the DetectLanguage API.
Switch branches/tags
Clone or download
Pull request Compare This branch is 14 commits ahead, 2 commits behind pmoelgaard:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
api
lib
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

Detect Language API

npm version Build Status

JavaScript wrapper for Language Detection API.

 

Installation

npm install detectlanguage [--save]

 

Configuration

Before using Detect Language API client you have to setup your personal API key.
You can get it by signing up at detectlanguage.com

 

Usage

Setup

var DetectLanguage = require('detectlanguage');
var detectLanguage = new DetectLanguage({
    key: '[INSERT YOUR KEY HERE]',
    ssl: true|false (defaults to TRUE)
});    

Simple Detection

Takes a simple string and detects the language with a list of detections.

Request
var dataSimple = "I am a Teapot and a Submarine";
detectLanguage.detect(dataSimple, function(error, result) {
    console.log(JSON.stringify(result));
});
Response
{
  data: {
    detections: [
      {
        language: "en",
        isReliable: true,
        confidence: 7.85
      }
    ]
  }
}

Bulk Detection (Recommended)

Takes an array simple string and detects the language with a list of detections.

Request
var dataBulk = [
    "I am a Teapot and a Submarine",
    "Soy una tetera y un submarino",
    "Jeg er en tekande og en ubåd"
]
detectLanguage.detect(dataBulk, function(error, result) {
    console.log(JSON.stringify(result));
});
Response
{
  data: {
    detections: [
      [
        {
          language: "en",
          isReliable: true,
          confidence: 7.85
        }
      ],
      [
        {
          language: "es",
          isReliable: true,
          confidence: 3.75
        }
      ],
      [
        {
          language: "da",
          isReliable: true,
          confidence: 4.09
        }
      ]
    ]
  }
}

Supported Languages

Returns the list of supported languages.

Request
detectLanguage.languages(function(error, result) {
    console.log(JSON.stringify(result));
});
Response
[
  {
    code: "ab",
    name: "ABKHAZIAN"
  },
  {
    code: "aa",
    name: "AFAR"
  },
  {
    code: "af",
    name: "AFRIKAANS"
  }
  ...
]

User Status

Returns information about your account and it's status.

Request
detectLanguage.status(function(error, result) {
    console.log(JSON.stringify(result));
});
Response
{
  date: "2015-02-21",
  requests: 31,
  bytes: 429,
  plan: "FREE",
  plan_expires: null,
  daily_requests_limit: 5000,
  daily_bytes_limit: 1048576,
  status: "ACTIVE"
}

 

Author

Peter Andreas Moelgaard (GitHub, Twitter)

 

License

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0