# Language Detector: Detect Text Language in Bulk (API) (`data-done-right/language-detector`) Actor

Language detector API: detect the language of texts, web pages and dataset fields in bulk. ISO 639-1 code and name, confidence, top 3 candidates, script, reliability flag and optional mixed-language detection by sentence.

- **URL**: https://apify.com/data-done-right/language-detector.md
- **Developed by:** [Data Done Right](https://apify.com/data-done-right) (community)
- **Categories:** Developer tools, Automation, Other
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.64 / 1,000 text detecteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Language Detector: Detect Text Language in Bulk (API)

This **language detector** runs **language detection** on texts, web pages and dataset fields in bulk. Paste sentences, page URLs or pick a dataset and get one row per item with the **ISO 639-1 code and language name**, a confidence score, the **top 3 candidates**, the writing script, an `isReliable` flag and the character count. Optional **mixed-language detection** splits a text into sentences and reports every language with its share. It runs offline inside the Actor: no API key, no external service, no model download at run time.

Pay only for items that got a language result. Empty, failed and skipped items are free.

### What can this language identifier do

- **Detect the language of 75 languages** (English, Spanish, French, German, Portuguese, Russian, Chinese, Japanese, Korean, Arabic, Hindi and more) with the open-source Lingua library, which is strong on short texts.
- **Bulk texts.** One line per text, up to 50,000 items per run. One bad item never stops the run.
- **Web pages.** Give page URLs: the main text is extracted with trafilatura and detected. The page's own `<html lang>` attribute (or content-language / og:locale meta) is returned as a second signal, with `htmlLangMatches` telling you if the page declares the language it actually uses.
- **Dataset fields.** Pick the dataset of another Actor (reviews, comments, tweets, descriptions) and name the field, for example `review.text`.
- **Top 3 candidates** with confidence, so you can see close calls (Spanish vs Portuguese, Norwegian vs Danish).
- **Script detection** from Unicode ranges: Latin, Cyrillic, Greek, Arabic, Hebrew, Devanagari, CJK (Han), Kana (Japanese), Hangul, Thai and others.
- **`isReliable` and low-confidence flag.** Texts shorter than 20 characters always return `lowConfidence: true` and `isReliable: false` with a note. You choose the reliable threshold (default 0.7).
- **Mixed languages (`detectMixed`).** Sentence-by-sentence detection returns `languages` (language, sentences, characters, share) and `isMixed` when two or more languages each cover 15% or more.
- **Restrict the choice.** If you know the text is English, French or German, set `restrictToLanguages` to `en, fr, de`. This makes short texts much more accurate.

### How to detect the language of a text in bulk

1. Paste your texts in **Texts**, one per line (the prefill has four sentences in four languages).
2. Run the Actor.
3. Download the dataset as JSON, CSV or Excel, or call it from the API. The `language` column holds the ISO 639-1 code.

### How to detect the language of a web page

Put page URLs in **Page URLs**. You get the language of the readable text plus `htmlLang`. Public pages only: no login, no CAPTCHA solving, and login-walled social sites are refused. Pages that need JavaScript to show their text come back as `empty` with an explanation.

### How to detect the language of a dataset field

Pick the **Dataset** and set **Dataset field** (default `text`). Every string in that field becomes one row. Dotted paths and list positions work (`comments.0`).

### Input example

```json
{
  "texts": [
    "The quick brown fox jumps over the lazy dog near the river bank.",
    "Hoy hemos publicado una nueva versión de la aplicación con muchas mejoras.",
    "Мы рады сообщить о запуске нашего нового сервиса для малого бизнеса.",
    "今日は天気がとても良いので、公園で友達と一緒にお昼ご飯を食べました。"
  ],
  "urls": ["https://en.wikipedia.org/wiki/Language"],
  "detectMixed": false,
  "restrictToLanguages": [],
  "maxItems": 1000
}
```

### Output example

```json
{
  "index": 2,
  "source": "text",
  "url": null,
  "textPreview": "Hoy hemos publicado una nueva versión de la aplicación con muchas mejoras.",
  "language": "es",
  "languageName": "Spanish",
  "confidence": 0.9986,
  "candidates": [
    {"language": "es", "name": "Spanish", "confidence": 0.9986},
    {"language": "ca", "name": "Catalan", "confidence": 0.0009},
    {"language": "pt", "name": "Portuguese", "confidence": 0.0003}
  ],
  "script": "Latin",
  "isReliable": true,
  "lowConfidence": false,
  "charCount": 75,
  "htmlLang": null,
  "htmlLangMatches": null,
  "status": "detected",
  "error": null,
  "note": null
}
```

With `detectMixed` each row also has `isMixed` and `languages`, for example `[{"language":"en","name":"English","sentences":2,"charCount":96,"share":0.62}, ...]`. A `SUMMARY` record in the key-value store counts results per language.

### Use cases

- Route support tickets, reviews or comments to the right language team.
- Clean a scraped dataset: keep only English rows, or find the rows in an unexpected language.
- Audit a website: do pages declare the right `lang` attribute (`htmlLangMatches`)?
- Pick a translation or NLP model per text, or filter spam in the wrong language.

### How much does it cost

Pay per event: **`text-detected` = $0.0008 per text, page or dataset item with a language result** ($0.80 per 1,000). Empty, failed, skipped and "undetected" (numbers or symbols only) rows are not charged. Platform compute usage is included in the price on paid plans; use **Max items** to cap spend.

### FAQ

**How accurate is the language detection?** Lingua is among the most accurate open-source detectors for short and mixed text. Long, single-language text is almost always right. Very short texts (under 20 characters), names, code and closely related languages are guesses, which is why those rows are flagged `lowConfidence` and show the top 3 candidates.

**Which languages are supported?** The 75 languages of Lingua 2.x (all return an ISO 639-1 code). Languages outside that list are assigned to the closest known one, so use `isReliable` and the confidence to catch them.

**What does confidence mean?** The model's relative probability of the top language among the candidate languages (0 to 1). Restricting `restrictToLanguages` raises it, because there are fewer rivals.

**Can it detect a text that mixes two languages?** Yes, turn on `detectMixed`. It detects each sentence (very short sentences are merged with neighbours) and reports the share of each language. The main `language` still describes the whole text.

**Does it detect the language of a web page?** Yes, from the page's main text, and it also reports what the page declares in `<html lang>`. It does not render JavaScript, so pages that build their content in the browser may return `empty`.

**Does it use an external API or my data?** No. Detection runs inside the Actor. Page URLs are downloaded from the public internet; nothing is sent to a third-party language service.

**Is the first run slow?** The accurate mode loads its language models at start, which takes roughly 10-20 seconds; after that, thousands of texts take seconds. `accuracy: fast` starts quicker but is less accurate on short texts.

### Limits

- 75 languages; no dialect or locale detection (en-GB vs en-US) beyond what a page declares.
- Texts are cut at 20,000 characters for detection (configurable). `charCount` shows the full length.
- Page URLs: public HTML pages up to 10 MB, no JavaScript rendering, no logins.

### Related tools

- **Doc to Text Extractor** to get text out of PDFs and Office files before detecting the language.
- **Keyword Suggestions** to find what people search for in each language.
- **SEO Audit** to check page-level signals such as the `lang` attribute.

# Actor input Schema

## `texts` (type: `array`):

Texts to detect, one per line. Each line is one result row. Example: Bonjour tout le monde, comment allez-vous aujourd'hui ?

## `urls` (type: `array`):

Web pages whose main text should be analysed. The page html lang attribute is returned as a second signal. Public pages only, no logins. Example: https://en.wikipedia.org/wiki/Language.

## `datasetId` (type: `string`):

Optional. Pick an Apify dataset (for example the output of a scraper) and the field below is analysed for every item. Example: a dataset ID such as aBcD1234eFgH5678i.

## `datasetField` (type: `string`):

Field of each dataset item that holds the text (or a list of texts). Dotted paths work. Example: review.text or comments.0. Default: text.

## `detectMixed` (type: `boolean`):

Also split each text into sentences and detect every sentence, so a text that switches language returns a list of languages with their share. Example: true for bilingual reviews or emails. Needs texts of at least 20 characters.

## `restrictToLanguages` (type: `array`):

Optional. Limit the answer to these languages (2-letter ISO 639-1 codes, at least two). This makes short texts much more accurate when you know the likely languages. Example: en, fr, de. Leave empty for all 75 languages.

## `accuracy` (type: `string`):

High uses the full language models (best on short texts, needs more memory and about 10-20 s to start). Fast uses a lighter mode that is quicker but less accurate on short texts. Example: high.

## `reliableThreshold` (type: `number`):

A result is flagged isReliable when its confidence is at least this value (and the text is 20+ characters). Range 0.1 to 0.99. Example: 0.7.

## `maxItems` (type: `integer`):

Maximum texts and pages to process in this run. Items beyond the limit are listed as skipped and not charged. Example: 1000.

## `maxCharsPerText` (type: `integer`):

Longer texts are cut to this length for detection (charCount still shows the full length). 2,000 to 5,000 characters is plenty for a reliable answer. Example: 20000.

## `concurrency` (type: `integer`):

How many page URLs are downloaded at the same time. Example: 4.

## `timeoutSecs` (type: `number`):

Give up on a page URL after this many seconds. Example: 30.

## `proxyConfiguration` (type: `object`):

Only used for page URLs. Leave empty to download pages directly.

## Actor input object example

```json
{
  "texts": [
    "The quick brown fox jumps over the lazy dog near the river bank.",
    "Hoy hemos publicado una nueva versión de la aplicación con muchas mejoras.",
    "Мы рады сообщить о запуске нашего нового сервиса для малого бизнеса.",
    "今日は天気がとても良いので、公園で友達と一緒にお昼ご飯を食べました。"
  ],
  "datasetField": "text",
  "detectMixed": false,
  "accuracy": "high",
  "reliableThreshold": 0.7,
  "maxItems": 1000,
  "maxCharsPerText": 20000,
  "concurrency": 4,
  "timeoutSecs": 30
}
```

# Actor output Schema

## `results` (type: `string`):

All result items of this run (the default dataset), as JSON, CSV, Excel and more.

## `records` (type: `string`):

Key-value store records: the run summary, notes on any problems, and any files.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "texts": [
        "The quick brown fox jumps over the lazy dog near the river bank.",
        "Hoy hemos publicado una nueva versión de la aplicación con muchas mejoras.",
        "Мы рады сообщить о запуске нашего нового сервиса для малого бизнеса.",
        "今日は天気がとても良いので、公園で友達と一緒にお昼ご飯を食べました。"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("data-done-right/language-detector").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "texts": [
        "The quick brown fox jumps over the lazy dog near the river bank.",
        "Hoy hemos publicado una nueva versión de la aplicación con muchas mejoras.",
        "Мы рады сообщить о запуске нашего нового сервиса для малого бизнеса.",
        "今日は天気がとても良いので、公園で友達と一緒にお昼ご飯を食べました。",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("data-done-right/language-detector").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "texts": [
    "The quick brown fox jumps over the lazy dog near the river bank.",
    "Hoy hemos publicado una nueva versión de la aplicación con muchas mejoras.",
    "Мы рады сообщить о запуске нашего нового сервиса для малого бизнеса.",
    "今日は天気がとても良いので、公園で友達と一緒にお昼ご飯を食べました。"
  ]
}' |
apify call data-done-right/language-detector --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,data-done-right/language-detector"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/pZ17gEuKcxtpebMnT/builds/SzKiaGg5qM491zeIx/openapi.json
