Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including detectlanguage with all npm packages installed. Try it out:

var detectlanguage = require("detectlanguage")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

detectlanguage v1.2.2

This is a JavaScript Client Library for the DetectLanguage Service API

Detect Language API

Build Status npm

JavaScript wrapper for DetectLanguage Service.

 

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free