# Language Detector (`zsoftware/language-detector`) Actor

Detect the language of each line of text using machine learning.
Paste multiple lines of text into the input, and this actor will identify the language of each one, returning results with confidence scores and alternative guesses based on a trained statistical model.

- **URL**: https://apify.com/zsoftware/language-detector.md
- **Developed by:** [Karim](https://apify.com/zsoftware) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 15 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Language Detector Actor

This actor detects the language of each line of text using machine learning techniques. It allows users to input multiple lines of text, with each line representing a separate text sample. The actor will return the detected language for each line, along with confidence scores and alternative language guesses.

### Features

- **Language Detection**: Automatically detects the language of each line of text.
- **Confidence Scores**: Provides the likelihood of the language detection for each guess.
- **Alternative Guesses**: In case the first guess isn't 100% accurate, it returns additional language options with probabilities.
- **Multi-line Support**: Accepts multiple text lines as input (one per line), with each line being processed individually.

### Input

- **Text**: Paste or enter multiple lines of text (one text sample per line). Each line will be processed separately to detect the language.

#### Example Input

```
Hello, how are you?
Bonjour, comment ça va?
これは日本語です。
```

### Output

The actor will return the detected language for each line of text, along with alternative language guesses and their confidence scores.

#### Example Output

```json
[
  {
    "text": "Hello, how are you?",
    "language": "en",
    "confidence": 0.999995
  },
  {
    "text": "Bonjour, comment ça va?",
    "language": "fr",
    "confidence": 0.999991
  },
  {
    "text": "Hola, ¿cómo estás?",
    "language": "es",
    "confidence": 0.999995
  },
  {
    "text": "これは日本語です。",
    "language": "ja",
    "confidence": 1.0
  }
]
```

### How It Works

1. **Input Processing**: Users input multiple lines of text (one line per text sample). Each line is parsed and passed to the language detection model.
2. **Language Detection**: The actor uses a **machine learning model** (Naive Bayes classifier) to detect the language based on n-gram patterns found in the input.
3. **Output**: For each line of text, the actor returns the detected language, along with the confidence score and alternative guesses.

### Deployment

This actor is deployed on Apify and can be used via the **Apify Console**. Once deployed, users can provide text as input and retrieve language detection results through the UI.

### Usage

1. Go to the Apify Console.
2. Run the actor with your text input.
3. Download the results or view them in the Apify UI.

### Limitations

- The actor is best suited for shorter texts, such as sentences or short paragraphs.
- Accuracy can vary with very short or ambiguous text inputs.

# Actor input Schema

## `text` (type: `string`):

Enter one text sample per line. Each line will be analyzed as a separate input.

## Actor input object example

```json
{
  "text": "Hello, how are you?\nBonjour, comment ça va?\nHola, ¿cómo estás?\nこれは日本語です。"
}
```

# 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 = {
    "text": `Hello, how are you?
Bonjour, comment ça va?
Hola, ¿cómo estás?
これは日本語です。`
};

// Run the Actor and wait for it to finish
const run = await client.actor("zsoftware/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 = { "text": """Hello, how are you?
Bonjour, comment ça va?
Hola, ¿cómo estás?
これは日本語です。""" }

# Run the Actor and wait for it to finish
run = client.actor("zsoftware/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 '{
  "text": "Hello, how are you?\\nBonjour, comment ça va?\\nHola, ¿cómo estás?\\nこれは日本語です。"
}' |
apify call zsoftware/language-detector --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,zsoftware/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/zM1tnz27Q6VPVwqsJ/builds/yZK0TvFy9C8AZGoil/openapi.json
