DeepL (AI translation) Actor
Try for free
No credit card required
Go to Store
DeepL (AI translation) Actor
tkapler/deepl-actor
Try for free
No credit card required
Receive high-quality translations from/to 24 languages using the DeepL API. It uses a proprietary algorithm with convolutional neural networks (CNNs) and translate far better than e.g. Google Translate. Free Tier is available.
.editorconfig
1root = true
2
3[*]
4indent_style = space
5indent_size = 4
6charset = utf-8
7trim_trailing_whitespace = true
8insert_final_newline = true
9end_of_line = lf
.eslintrc
1{
2 "extends": "@apify"
3}
.gitignore
1# This file tells Git which files shouldn't be added to source control
2
3.idea
4node_modules
Dockerfile
1# First, specify the base Docker image. You can read more about
2# the available images at https://sdk.apify.com/docs/guides/docker-images
3# You can also use any other image from Docker Hub.
4FROM apify/actor-node:16
5
6# Second, copy just package.json and package-lock.json since it should be
7# the only file that affects "npm install" in the next step, to speed up the build
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --only=prod --no-optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version
21
22# Next, copy the remaining files and directories with the source code.
23# Since we do this after NPM install, quick build will be really fast
24# for most source file changes.
25COPY . ./
26
27# Optionally, specify how to launch the source code of your actor.
28# By default, Apify's base Docker images define the CMD instruction
29# that runs the Node.js source code using the command specified
30# in the "scripts.start" section of the package.json file.
31# In short, the instruction looks something like this:
32#
33# CMD npm start
INPUT_SCHEMA.json
1{
2 "title": "Input schema for the apify_project actor.",
3 "type": "object",
4 "schemaVersion": 1,
5 "properties": {
6 "auth_key": {
7 "title": "Authentication Key",
8 "type": "string",
9 "description": "Authentication Key for DeepL API. You can find it here https://www.deepl.com/pro-account/summary",
10 "editor": "textfield"
11 },
12 "text": {
13 "title": "Source text",
14 "type": "string",
15 "description": "Text you want to translate",
16 "editor": "textarea"
17 },
18 "target_lang": {
19 "title": "Target language",
20 "type": "string",
21 "editor": "select",
22 "description": "The language (and variant) into which the text should be translated",
23 "default": "EN-GB",
24 "enum": ["BG", "CS", "DA", "DE", "EL", "EN-GB", "EN-US", "ES", "ET", "FI", "FR", "HU", "IT", "JA", "LT", "LV", "NL", "PL", "PT-PT", "PT-BR", "RO", "RU", "SK", "SL", "SV", "ZH"],
25 "enumTitles": ["Bulgarian", "Czech", "Danish", "German", "Greek", "English (British)", "English (American)", "Spanish", "Estonian", "Finnish", "French", "Hungarian", "Italian", "Japanese", "Lithuanian", "Latvian", "Dutch", "Polish", "Portuguese (all Portuguese varieties excluding Brazilian Portuguese)", "Portuguese (Brazilian)", "Romanian", "Russian", "Slovak", "Slovenian", "Swedish", "Chinese"]
26 },
27 "source_lang": {
28 "title": "Source language",
29 "type": "string",
30 "editor": "select",
31 "description": "Language of the text to be translated. Default is automatic detection.",
32 "default": "",
33 "enum": ["", "BG", "CS", "DA", "DE", "EL", "EN", "ES", "ET", "FI", "FR", "HU", "IT", "JA", "LT", "LV", "NL", "PL", "PT", "RO", "RU", "SK", "SL", "SV", "ZH"],
34 "enumTitles": ["Autodetect","Bulgarian", "Czech", "Danish", "German", "Greek", "English", "Spanish", "Estonian", "Finnish", "French", "Hungarian", "Italian", "Japanese", "Lithuanian", "Latvian", "Dutch", "Polish", "Portuguese (all Portuguese varieties mixed)", "Romanian", "Russian", "Slovak", "Slovenian", "Swedish", "Chinese"]
35 },
36 "split_sentences": {
37 "title": "Split sentences",
38 "type": "string",
39 "description": "Sets whether the translation engine should first split the input into sentences. This is enabled by default.<br />For applications that send one sentence per text parameter, it is advisable to set split_sentences=0, in order to prevent the engine from splitting the sentence unintentionally.",
40 "editor": "select",
41 "default": "1",
42 "enum": ["0", "1", "nonewlines"],
43 "enumTitles": ["0 - no splitting at all, whole input is treated as one sentence","1 - (default) - splits on punctuation and on newlines","nonewlines - splits on punctuation only, ignoring newlines"]
44 },
45 "preserve_formatting": {
46 "title": "Preserve formatting",
47 "type": "string",
48 "description": "Sets whether the translation engine should respect the original formatting, even if it would usually correct some aspects. <br />The formatting aspects affected by this setting include:<br />-Punctuation at the beginning and end of the sentence<br />-Upper/lower case at the beginning of the sentence",
49 "editor": "select",
50 "default": "0",
51 "enum": ["0", "1"],
52 "enumTitles": ["0 (default) - No, do not preserver formatting","1 - Yes, preserve formatting"]
53 },
54 "formality": {
55 "title": "Formality",
56 "type": "string",
57 "description": "Sets whether the translated text should lean towards formal or informal language. This feature currently only works for target languages 'DE' (German), 'FR' (French), 'IT' (Italian), 'ES' (Spanish), 'NL' (Dutch), 'PL' (Polish), 'PT-PT', 'PT-BR' (Portuguese) and 'RU' (Russian).",
58 "editor": "select",
59 "default": "default",
60 "enum": ["default", "more", "less"],
61 "enumTitles": ["Default","More","Less"]
62 },
63 "glossary_id": {
64 "title": "Glossary ID",
65 "type": "string",
66 "description": "Specify the glossary to use for the translation. Important: This requires the source_lang parameter to be set and the language pair of the glossary has to match the language pair of the request.",
67 "editor": "textfield",
68 "nullable": true
69 }
70 },
71 "required": ["text","auth_key"]
72}
apify.json
1{
2 "env": { "npm_config_loglevel": "silent" }
3}
main.js
1// This is the main Node.js source code file of your actor.
2
3// Import Apify SDK. For more information, see https://sdk.apify.com/
4const Apify = require('apify');
5// Import Got, see https://www.npmjs.com/package/got
6const got = require('got');
7
8Apify.main(async () => {
9 // Get input of the actor (here only for demonstration purposes).
10 const input = await Apify.getInput();
11 console.log('Input:');
12 console.dir(input);
13 const auth_key = input.auth_key;
14 console.log('Glossary ID:');
15 console.log(input.glossary_id)
16
17
18 /**
19 * Actor code
20 */
21 const {body} = await got.post('https://api-free.deepl.com/v2/translate?auth_key='+auth_key, {
22 form: {
23 text: input.text,
24 source_lang: input.source_lang,
25 target_lang: input.target_lang,
26 split_sentences: input.split_sentences,
27 preserve_formatting: input.preserve_formatting,
28 formality: input.formality/*,
29 glossary_id: input.glossary_id*/
30 },
31 responseType: 'json'
32 });
33
34 await Apify.setValue('OUTPUT', body);
35 body.translations[0].source = input.text;
36 await Apify.pushData(body.translations[0]);
37
38
39
40
41
42});
package.json
1{
2 "name": "project-empty",
3 "version": "0.0.1",
4 "description": "This is a boilerplate of an Apify actor.",
5 "dependencies": {
6 "apify": "^2.0.7",
7 "got": "latest"
8 },
9 "devDependencies": {
10 "@apify/eslint-config": "^0.1.3",
11 "eslint": "^7.0.0"
12 },
13 "scripts": {
14 "start": "node main.js",
15 "lint": "./node_modules/.bin/eslint ./src --ext .js,.jsx",
16 "lint:fix": "./node_modules/.bin/eslint ./src --ext .js,.jsx --fix",
17 "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
18 },
19 "author": "It's not you it's me",
20 "license": "ISC"
21}
Developer
Maintained by Community
Actor Metrics
1 monthly user
-
2 stars
Created in Oct 2021
Modified 2 years ago
Categories