<commit_before># retext-language [![Build Status](https://img.shields.io/travis/wooorm/retext-language.svg?style=flat)](https://travis-ci.org/wooorm/retext-language) [![Coverage Status](https://img.shields.io/coveralls/wooorm/retext-language.svg?style=flat)](https://coveralls.io/r/wooorm/retext-language?branch=master)

Detect the language of text with **[Retext](https://github.com/wooorm/retext)**.

## Installation

npm:

```bash
$ npm install retext-language
```

Component:

```bash
$ component install wooorm/retext-language
```

Bower:

```bash
$ bower install retext-language
```

## Usage

```javascript
var Retext = require('retext');
var visit = require('retext-visit');
var language = require('retext-language');

var retext = new Retext()
    .use(visit)
    .use(language);

retext.parse('Alle mennesker er født frie og', function (err, tree) {
    console.log(tree.data.language);
    /* 'nno' // Which is Norwegian Nynorsk. */
});

retext.parse(
    'Tots els éssers humans neixen lliures i iguals. ' + 
    'All human beings are born free and equal.\n' + 
    'Toate ființele umane se nasc libere și egale. ' + 
    '人人生而自由﹐在尊嚴和權利上一律平等。',
    function (err, tree) {
        console.log(tree.data.language);
        /* 'cat' // Catalan */

        tree.visit(tree.PARAGRAPH_NODE, function (node) {
            console.log(node.toString(), node.data.language);
        });
        /**
         * 'Tots els éssers humans neixen lliures i iguals. All human beings are born free and equal.', 'cat' // Catalan
         * 'Toate ființele umane se nasc libere și egale. 人人生而自由﹐在尊嚴和權利上一律平等。', 'ron' // Romanian
         */

        tree.visit(tree.SENTENCE_NODE, function (node) {
            console.log(node.toString(), node.data.language);
        });
        /**
         * 'Tots els éssers humans neixen lliures i iguals.', 'cat' // Catalan
         * 'All human beings are born free and equal.', 'eng' // English
         * 'Toate ființele umane se nasc libere și egale.', 'ron' // Romanian
         * '人人生而自由﹐在尊嚴和權利上一律平等。', 'cmn' // Mandarin Chinese
         */
    }
);
```

## Supported Languages

retext-language supports the 175 languages provided by **[wooorm/franc](https://github.com/wooorm/franc#supported-languages)**. 

**Note!** Results may vary depending on which [parser](https://github.com/wooorm/retext#parsers) you use. It’s probably better for most cases to detect the language (with **[wooorm/franc](https://github.com/wooorm/franc)**) before parsing, and choose a parser according to the results.

## API

None, **retext-language** automatically detects the language of each [`SentenceNode`](https://github.com/wooorm/textom#textomsentencenode-nlcstsentencenode) (using **[wooorm/franc](https://github.com/wooorm/franc)**), and stores the language in `node.data.language`. Additionally, information about all detected languages is stored in `node.data.languages`.

The average of the detected languages on parents ([paragraph](https://github.com/wooorm/textom#textomparagraphnode-nlcstparagraphnode)s and [root](https://github.com/wooorm/textom#textomrootnode-nlcstrootnode)s), through the same `parent.data.language` and `parent.data.languages`.

## Performance

On a MacBook air:
<commit_msg>Add links to installation methods in `Readme.md`<commit_after># retext-language [![Build Status](https://img.shields.io/travis/wooorm/retext-language.svg?style=flat)](https://travis-ci.org/wooorm/retext-language) [![Coverage Status](https://img.shields.io/coveralls/wooorm/retext-language.svg?style=flat)](https://coveralls.io/r/wooorm/retext-language?branch=master)

Detect the language of text with **[Retext](https://github.com/wooorm/retext)**.

## Installation

[npm](https://docs.npmjs.com/cli/install):

```bash
$ npm install retext-language
```

[Component.js](https://github.com/componentjs/component):

```bash
$ component install wooorm/retext-language
```

[Bower](http://bower.io/#install-packages):

```bash
$ bower install retext-language
```

## Usage

```javascript
var Retext = require('retext');
var visit = require('retext-visit');
var language = require('retext-language');

var retext = new Retext()
    .use(visit)
    .use(language);

retext.parse('Alle mennesker er født frie og', function (err, tree) {
    console.log(tree.data.language);
    /* 'nno' // Which is Norwegian Nynorsk. */
});

retext.parse(
    'Tots els éssers humans neixen lliures i iguals. ' + 
    'All human beings are born free and equal.\n' + 
    'Toate ființele umane se nasc libere și egale. ' + 
    '人人生而自由﹐在尊嚴和權利上一律平等。',
    function (err, tree) {
        console.log(tree.data.language);
        /* 'cat' // Catalan */

        tree.visit(tree.PARAGRAPH_NODE, function (node) {
            console.log(node.toString(), node.data.language);
        });
        /*
         * 'Tots els éssers humans neixen lliures i iguals. All human beings are born free and equal.', 'cat' // Catalan
         * 'Toate ființele umane se nasc libere și egale. 人人生而自由﹐在尊嚴和權利上一律平等。', 'ron' // Romanian
         */

        tree.visit(tree.SENTENCE_NODE, function (node) {
            console.log(node.toString(), node.data.language);
        });
        /*
         * 'Tots els éssers humans neixen lliures i iguals.', 'cat' // Catalan
         * 'All human beings are born free and equal.', 'eng' // English
         * 'Toate ființele umane se nasc libere și egale.', 'ron' // Romanian
         * '人人生而自由﹐在尊嚴和權利上一律平等。', 'cmn' // Mandarin Chinese
         */
    }
);
```

## Supported Languages

retext-language supports the 175 languages provided by **[wooorm/franc](https://github.com/wooorm/franc#supported-languages)**. 

**Note!** Results may vary depending on which [parser](https://github.com/wooorm/retext#parsers) you use. It’s probably better for most cases to detect the language (with **[wooorm/franc](https://github.com/wooorm/franc)**) before parsing, and choose a parser according to the results.

## API

None, **retext-language** automatically detects the language of each [`SentenceNode`](https://github.com/wooorm/textom#textomsentencenode-nlcstsentencenode) (using **[wooorm/franc](https://github.com/wooorm/franc)**), and stores the language in `node.data.language`. Additionally, information about all detected languages is stored in `node.data.languages`.

The average of the detected languages on parents ([paragraph](https://github.com/wooorm/textom#textomparagraphnode-nlcstparagraphnode)s and [root](https://github.com/wooorm/textom#textomrootnode-nlcstrootnode)s), through the same `parent.data.language` and `parent.data.languages`.

## Performance

On a MacBook air:

{'fraction_non_alphanumeric': 0.14789051867533645, 'fraction_numerical': 0.0009073037955542114, 'mean_word_length': 3.661028893587033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 26, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1934478', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2240, 'n_words': 522}