# Yet Another Dataset Translator (`mvolfik/yet-another-dataset-translator`) Actor

Actor to translate datasets with field selection and source language detection. Requires Google Translate API Key.

- **URL**: https://apify.com/mvolfik/yet-another-dataset-translator.md
- **Developed by:** [Matěj Volf](https://apify.com/mvolfik) (community)
- **Categories:** Automation
- **Stats:** 4 total users, 1 monthly users, 100.0% runs succeeded, 1 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?

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

## Yet another dataset translator

Actor to translate datasets with field selection and source language detection. Requires Google Translate API Key.

### Features

#### Language detection

For each dataset item, this actor performs language detection. If it detects that the item is already in the target language, it skips translation of that item, thus saving your Google Translate budget.

#### Mock run

You can run this actor with empty API key to mock translate items. That way you can test your setup without spending money. Additionally, the actor prints statistics including price estimate, to allow you to predict your Google Cloud spending.

Note: the estimate is provided solely for your convenience, without any guarantees of accuracy or correctness. Always check Google Translate API pricing and perform your own estimation.

### Input

#### `dataset_ids`

List of IDs of datasets to translate. This allows you to combine items from multiple Actor runs if needed.

#### `api_key`

Google Translate API key. This field is stored securely encrypted on Apify servers. If you don't provide a key, the actor will run in "mock translation" mode, only prefixing each string with `"TRANSLATED "` instead of calling to Google servers.

#### `field_patterns_to_translate`

Provide a list of globs to identify fields that should be translated. Supported wildcards:

- `*`: any number of any characters: `*Field` matches `Field`, `someField`, `1Field` but not `field`
- `?`: a single character: `?ield` matches `yield`, `Field`, ` ield` but not `ield` or `aField`
- `[chars]`: a single occurence of any character in `chars`: `[fF]ield` matches `field` and `Field`, but not any of `ffield`, `yield`, `ield`
- `[!chars]`: a single occurence of any character not in `chars`: `[!y ]ield` matches `field`, `Yield`, but not `ield`, `yield`, ` ield`

(The globs can of course appear at any position in the pattern, and you can combine them in any way. Use a single glob `*` to translate all fields.)

#### `detect_language_threshold`

Language detection threshold. Default value of `0.7` is suitable for most use-cases, but if you need to be 100% sure that all output text is in given language, you can increase it to a value like `0.95`.

If you provide `0`, language detection won't be performed at all and all fields matched by patterns will be sent for translation.

The detection is performed at the level of items, on the first 500 characters of concatenation of fields that are to be translated. That means that from given item either all matched, or no fields are translated.

#### `output_dataset_id`

ID of output dataset, if you need to aggregate items from multiple runs into one dataset. If not provided, Actor will use its own default dataset.

#### `translation_marker_field`

Default value = `wasTranslated`. Each output item will contain this field, specifying if the item was translated (→ `true`) or not (→ `false`).

If you set this field to empty string (or `null`), the field will not exist.

#### `original_value_field_prefix`

Default value = `original_`. Each translated item item will also contain a copy of each translated field, prefixed with this value, that will contain the original, untranslated string. For example, for input item

```json
{ "text": "Auf Wiedersehen." }
```

The output would be

```json
{
    "text": "Goodbye.",
    "original_text": "Auf Wiedersehen."
}
```

If you set `original_value_field_prefix` to empty string (or `null`), the original values will not be provided in output.

***

**Disclaimer**: This Actor serves as a tool that interfaces with the Google Translate API and does not hold any responsibility for the quality of translations provided by this third-party service. By supplying an API key, the user consents to this Actor accessing the Google Translate API on their behalf. Users are responsible for ensuring that the amount of text submitted for translation is within their allocated quota and adheres to the Google Translate API's terms of service.

# Actor input Schema

## `dataset_ids` (type: `array`):

IDs of datasets to translate

## `api_key` (type: `string`):

See https://cloud.google.com/translate/docs/setup for setup instructions

## `target_language` (type: `string`):

Language to translate into

## `field_patterns_to_translate` (type: `array`):

You can use sipmly full names of the fields, but you can also use globs: \* matches any number of characters, ? matches any single character, \[seq] matches any character in seq

## `detect_language_threshold` (type: `string`):

If the confidence of detected language is lower than this threshold, the text is translated. Default is 0.7. Use 0 to always translate.

## `output_dataset_id` (type: `string`):

ID of the dataset to store the results in

## `translation_marker_field` (type: `string`):

This field will contain True if the text was translated, False otherwise

## `original_value_field_prefix` (type: `string`):

This prefix will be added to the names of fields containing original values

## Actor input object example

```json
{
  "target_language": "en",
  "detect_language_threshold": "0.7"
}
```

# 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 = {
    "target_language": "en",
    "detect_language_threshold": "0.7"
};

// Run the Actor and wait for it to finish
const run = await client.actor("mvolfik/yet-another-dataset-translator").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 = {
    "target_language": "en",
    "detect_language_threshold": "0.7",
}

# Run the Actor and wait for it to finish
run = client.actor("mvolfik/yet-another-dataset-translator").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 '{
  "target_language": "en",
  "detect_language_threshold": "0.7"
}' |
apify call mvolfik/yet-another-dataset-translator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,mvolfik/yet-another-dataset-translator"
        }
    }
}
```

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/zskUkHBIVPGbvZagZ/builds/yinEkHimJooO9e3y0/openapi.json
