Source: https://eventregistry.org/documentation?tab=detectLanguage

# Detect language

Detect the language in which the provided text is written.

Use the API call to detect the language in which the provided text is written. The output will provide a information about the reliability of the detected language as well as the list of most likely languages and the probability of that language. The languages as provided using their ISO1 and ISO3 language codes.

**Endpoint:** GET | POST `http://analytics.eventregistry.org/api/v1/detectLanguage`

**Headers:** Content-Type: application/json

#### `Parameters`

#### `apiKey`

string (required)

Your API key

#### `text`

string (required)

Text on which you want to detect the language.

## Request examples

### Example 1

Request body:

```json
{
  "text": "Microsoft released a new version of Windows OS.",
  "apiKey": "YOUR_API_KEY"
}
```

```python
from eventregistry import *
er = EventRegistry(apiKey = YOUR_API_KEY)
analytics = Analytics(er)

res = analytics.detectLanguage("Microsoft released a new version of Windows OS.")
predictedLanguages = res.get("languages", [])
if len(predictedLanguages) > 0:
    print("Predicted langauge is %s, iso1 code: %s, iso3 code: %s" % (predictedLanguages[0]["name"], predictedLanguages[0]["iso1"], predictedLanguages[0]["iso3"]))
```

```javascript
var er = new erBase.EventRegistry();
                    var analytics = new erBase.Analytics(er);
                    analytics.detectLanguage("Microsoft released a new version of Windows OS.").then((response) => {
                        console.log(response);
                    });
```

```typescript
const er = new EventRegistry();
                    const analytics = new Analytics(er);
                    analytics.detectLanguage("Microsoft released a new version of Windows OS.").then((response) => {
                        console.log(response);
                    });
```

## Example output

```json
{
  "reliable": true,
  "textBytes": 8533,
  "languages": [
    {
      "name": "LITHUANIAN",
      "code": "lt",
      "percent": 99,
      "score": 1177,
      "iso3": "lit",
      "iso1": "lt"
    }
  ],
  "chunks": [
    {
      "name": "LITHUANIAN",
      "code": "lt",
      "offset": 0,
      "bytes": 8953
    }
  ]
}
```

## Output schema

```json
{
  "type": "object",
  "properties": {
    "reliable": {
      "type": "boolean"
    },
    "textBytes": {
      "type": "integer"
    },
    "languages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "percent": {
            "type": "string"
          },
          "score": {
            "type": "string"
          }
        }
      }
    },
    "chunks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "offset": {
            "type": "string"
          },
          "bytes": {
            "type": "string"
          }
        }
      }
    }
  }
}
```
