### Install DeepL CLI from Source Source: https://developers.deepl.com/docs/getting-started/deepl-cli Clone the repository, install dependencies, build the project, and link it globally. Finally, verify the installation by checking the version. ```bash git clone https://github.com/DeepLcom/deepl-cli.git cd deepl-cli npm install npm run build npm link deep --version ``` -------------------------------- ### Install DeepL PHP Client Library Source: https://developers.deepl.com/docs This command installs the official DeepL client library for PHP using Composer. ```bash composer require deeplcom/deepl-php ``` -------------------------------- ### Install DeepL.NET Client Library Source: https://developers.deepl.com/docs/getting-started/quickstart Use this command to install the .NET client library for DeepL. This is required before making API requests in C#. ```sh dotnet add package DeepL.net ``` -------------------------------- ### Install DeepL Node.js Client Library Source: https://developers.deepl.com/docs This command installs the official DeepL client library for Node.js using npm. ```bash npm install deepl-node ``` -------------------------------- ### Install DeepL Python Library Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/glossaries-in-the-real-world Install the DeepL Python client library using pip. This is the first step to programmatically interact with the DeepL API. ```bash pip install --upgrade deepl ``` -------------------------------- ### Install DeepL MCP Server Locally Source: https://developers.deepl.com/docs/getting-started/deepl-mcp-server Install the DeepL MCP Server package locally in your project using npm. ```bash npm install deepl-mcp-server ``` -------------------------------- ### Run DeepL MCP Server with npx Source: https://developers.deepl.com/docs/getting-started/deepl-mcp-server Run the server directly using npx for quick access. Ensure Node.js v18 or later is installed. ```bash npx deepl-mcp-server ``` -------------------------------- ### Install Ruby DeepL Gem Source: https://developers.deepl.com/docs/getting-started/quickstart Use this command to install the Ruby gem for DeepL. This is necessary for using the DeepL API in Ruby applications. ```sh gem install deepl-rb ``` -------------------------------- ### Initialize Node.js Project for DeepL MCP Server Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications Sets up a new Node.js project, creates a directory, initializes npm, and installs necessary dependencies including the MCP SDK, DeepL Node.js client, and Zod for validation. ```bash # Create a new directory for our project mkdir deepl-mcp-server cd deepl-mcp-server # Initialize npm project npm init -y # Install dependencies npm install @modelcontextprotocol/sdk deepl-node zod ``` -------------------------------- ### Example XML Request for Outline Detection Source: https://developers.deepl.com/docs/xml-and-html-handling/customized-xml-outline-detection This XML structure demonstrates how to format input for custom outline detection, using tags like `` and ``. ```markup <document> <meta> <title>A document's title This is the first sentence. Followed by a second one. This is the third sentence. ``` -------------------------------- ### Voice API: Discover Supported Languages Source: https://developers.deepl.com/docs/resources/release-notes Use `GET /v3/languages?resource=voice` to programmatically discover language support for voice features. ```bash curl "https://api.deepl.com/v3/languages?resource=voice&auth_key=YOUR_AUTH_KEY" ``` -------------------------------- ### Maven Project Setup and Dependencies Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/java-document-translator Configure your Maven project to include the DeepL Java SDK. This dependency provides the necessary tools for interacting with the DeepL API for document translation. ```xml 4.0.0 com.example java-document-translator 1.0-SNAPSHOT 1.8 1.8 UTF-8 com.deepl.api deepl-java 1.10.0 org.codehaus.mojo exec-maven-plugin 3.0.0 App ``` -------------------------------- ### Retrieve Supported Resources for Languages (v3) Source: https://developers.deepl.com/docs/resources/roadmap-and-release-notes Use `GET /v3/languages/resources` to retrieve information about supported resources for languages, such as voice capabilities. This endpoint is now generally available. ```http GET /v3/languages/resources HTTP/1.1 Host: api.deepl.com Authorization: DeepL-Auth-Key YOUR_AUTH_KEY ``` -------------------------------- ### Translate with default matching threshold Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/how-to-use-translation-memories This example demonstrates a translation request using a translation memory with the default matching threshold of 75%. It shows how a slightly varied source text can still trigger a stored segment. ```shell curl -X POST 'https://api.deepl.com/v2/translate' \ --header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \ --header 'Content-Type: application/json' \ --data '{ "text": [ "Halloo Welt!" ], "target_lang": "EN", "translation_memory_id": "a74d88fb-ed2a-4943-a664-a4512398b994" }' ``` ```json { "translations": [ { "detected_source_language": "DE", "text": "Hello everyone!" } ] } ``` -------------------------------- ### Example Language Data Object Source: https://developers.deepl.com/docs/getting-started/supported-languages An example of a single language object within the `languageData` array. It specifies the language code, name, and support for various features. ```javascript { code: 'DE', name: 'German', translation: true, isVariant: false, glossaries: true, tagHandling: true, textImprovement: true, translationMemory: true, styleRules: true } ``` -------------------------------- ### Translate with 100% matching threshold Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/how-to-use-translation-memories This example shows how to set the translation memory matching threshold to 100% for exact matches only. This prevents stored segments from being applied if the source text is not identical. ```shell curl -X POST 'https://api.deepl.com/v2/translate' \ --header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \ --header 'Content-Type: application/json' \ --data '{ "text": [ "Halloo Welt!" ], "target_lang": "EN", "translation_memory_id": "a74d88fb-ed2a-4943-a664-a4512398b994", "translation_memory_threshold": 100 }' ``` ```json { "translations": [ { "detected_source_language": "DE", "text": "Hello world!" } ] } ``` -------------------------------- ### Python DeepL Client Translation Source: https://developers.deepl.com/docs/getting-started/quickstart This Python snippet shows how to install the DeepL client library and perform a translation. It's recommended to store API keys in environment variables for production. ```sh pip install deepl ``` ```python import deepl auth_key = "{YOUR_API_KEY}" # replace with your key deepL_client = deepl.DeepLClient(auth_key) result = deepl_client.translate_text("Hello, world!", target_lang="DE") print(result.text) ``` ```text Hallo, Welt! ``` -------------------------------- ### Integrate DeepL CLI with Git Hooks Source: https://developers.deepl.com/docs/getting-started/deepl-cli Install Git pre-commit hooks to automatically translate changed files into German and French before each commit. This ensures translations are up-to-date. ```bash deepl hooks install --pre-commit --languages de,fr ``` -------------------------------- ### Perform a Basic Translation Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/glossaries-in-the-real-world Send a simple translation request using the initialized translator object. This example shows translating 'Good evening, Gabrielle' to German. ```python import deepl auth_key = "19f172ae-03a9-..." translator = deepl.Translator(auth_key) result = translator.translate_text("Good evening, Gabrielle", target_lang="DE") print(result.text) # "Guten Abend, Gabrielle" ``` -------------------------------- ### Translate Multiple Text Strings in Java Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/translation-beginners-guide This Java example demonstrates translating multiple text strings with the DeepL API. Import the necessary DeepL classes and replace the placeholder with your API key. Storing API keys in environment variables is recommended for production. ```java import com.deepl.api.*; import java.util.List; public class Main { public static void main(String[] args) throws DeepLException, InterruptedException { String authKey = "{YOUR_API_KEY}"; // replace with your key DeepLClient client = new DeepLClient(authKey); List results = client.translateText( List.of( "What does the 'R' in 'Recursion' stand for?", "Recursão" ), null, "HA" ); System.out.println(results.get(0).getText() + "\n" + results.get(1).getText()); } } ``` -------------------------------- ### Translate Text using .NET Client Library Source: https://developers.deepl.com/docs This snippet demonstrates how to use the DeepL .NET client library for text translation. It includes installation, authentication, and an asynchronous translation call. ```APIDOC ## Translate Text using .NET ### Description Translate text using the official DeepL .NET client library. ### Installation ```bash dotnet add package DeepL.net ``` ### Usage ```csharp using DeepL; // this imports the DeepL namespace. Use the code below in your main program. var authKey = "{YOUR_API_KEY}"; // replace with your key var client = new DeepLClient(authKey); var translatedText = await client.TranslateTextAsync( "Hello, world!", null, LanguageCode.German); Console.WriteLine(translatedText); ``` ### Sample Output ``` Hallo, Welt! ``` ``` -------------------------------- ### Translate Text using Ruby Client Library Source: https://developers.deepl.com/docs This snippet demonstrates how to use the DeepL Ruby client library for text translation. It includes installation, authentication, and making a translation request. ```APIDOC ## Translate Text using Ruby ### Description Translate text using the official DeepL Ruby client library. ### Installation ```bash gem install deepl-rb ``` ### Usage ```ruby require 'deepl' DeepL.configure do |config| config.auth_key = '{YOUR_API_KEY}' # replace with your key end translation = DeepL.translate 'Hello, world!', nil, 'de' puts translation.text ``` ### Sample Output ``` Hallo, Welt! ``` ``` -------------------------------- ### Define a Translation Tool Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications Define a new tool for the MCP server, specifying its name, a description, the parameter schema using Zod, and the implementation function. This example shows the 'translate-text' tool. ```javascript server.tool( "translate-text", // Name "Translate text using DeepL API", // Description { text: z.string().describe("Text to translate"), // ...more parameters }, async ({ text, sourceLang, targetLang, formality }) => { // Implementation } ); ``` -------------------------------- ### XML Document Translation Example Source: https://developers.deepl.com/docs/xml-and-html-handling/structured-content Demonstrates translating an XML document with title and paragraph tags. Text within these tags is identified for sentence splitting, ensuring accurate translation while preserving XML structure. ```markup A document's title This is the first sentence. Followed by a second one. This is the third sentence. ``` ```markup Der Titel eines Dokuments Das ist der erste Satz. Gefolgt von einem zweiten. Dies ist der dritte Satz. ``` -------------------------------- ### Translate Text using PHP Client Library Source: https://developers.deepl.com/docs This snippet shows how to use the DeepL PHP client library to translate text. It covers installation, authentication, and making a translation request. ```APIDOC ## Translate Text using PHP ### Description Translate text using the official DeepL PHP client library. ### Installation ```bash composer require deeplcom/deepl-php ``` ### Usage ```php require_once 'vendor/autoload.php'; use DeepL\Client; $authKey = "{YOUR_API_KEY}"; // replace with your key $deeplClient = new DeepL\DeepLClient($authKey); $result = $deeplClient->translateText('Hello, world!', null, 'de'); echo $result->text; ``` ### Sample Output ``` Hallo, Welt! ``` ``` -------------------------------- ### JavaScript DeepL Node Client Translation Source: https://developers.deepl.com/docs/getting-started/quickstart This JavaScript snippet demonstrates installing the 'deepl-node' package and making a translation request. Storing API keys in environment variables is advised for production environments. ```sh npm install deepl-node ``` ```javascript import * as deepl from 'deepl-node'; const authKey = "{YOUR_API_KEY}"; // replace with your key const deeplClient = new deepl.DeepLClient(authKey); (async () => { const result = await deeplClient.translateText('Hello, world!', null, 'de'); console.log(result.text); })(); ``` ```text Hallo, Welt! ``` -------------------------------- ### Translate Text using Python Client Library Source: https://developers.deepl.com/docs This snippet shows how to use the DeepL Python client library to translate text. It covers installation, authentication, and making a translation request. ```APIDOC ## Translate Text using Python ### Description Translate text using the official DeepL Python client library. ### Installation ```bash pip install deepl ``` ### Usage ```python import deepl auth_key = "{YOUR_API_KEY}" # replace with your key deepL_client = deepl.DeepLClient(auth_key) result = deepl_client.translate_text("Hello, world!", target_lang="DE") print(result.text) ``` ### Sample Output ``` Hallo, Welt! ``` ``` -------------------------------- ### PHP DeepL Client Translation Source: https://developers.deepl.com/docs/getting-started/quickstart This PHP snippet shows how to install the DeepL PHP client library using Composer and perform a text translation. For production, consider using environment variables for your API key. ```sh composer require deeplcom/deepl-php ``` ```php require_once 'vendor/autoload.php'; use DeepL\Client; $authKey = "{YOUR_API_KEY}"; // replace with your key $deeplClient = new DeepL\DeepLClient($authKey); $result = $deeplClient->translateText('Hello, world!', null, 'de'); echo $result->text; ``` ```text Hallo, Welt! ``` -------------------------------- ### JavaScript Fetch Request to PHP Proxy Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/nodejs-proxy Example of how to send a translation request to the PHP proxy server from client-side JavaScript. Ensure the URL correctly points to your running PHP proxy script. ```javascript const url = `http://localhost:8000/deepl-proxy.php?text=${encodeURIComponent(text)}&target_lang=${encodeURIComponent(targetLang)}`; const response = await fetch(url); const result = await response.text(); ``` -------------------------------- ### Java DeepL API Sample Request Source: https://developers.deepl.com/docs/getting-started/quickstart This Java code snippet shows how to use the DeepL client library to translate text. Ensure you have installed the library as per the instructions. Replace '{YOUR_API_KEY}' with your key. For production, use environment variables. ```java import com.deepl.api.*; public class Main { public static void main(String[] args) throws DeepLException, InterruptedException { String authKey = "{YOUR_API_KEY}"; // replace with your key DeepLClient client = new DeepLClient(authKey); TextResult result = client.translateText("Hello, world!", null, "de"); System.out.println(result.getText()); } } ``` -------------------------------- ### Deprecated GET request to /translate Source: https://developers.deepl.com/docs/resources/breaking-changes-change-notices/march-2025-deprecating-get-requests-to-translate-and-authenticating-with-auth_key This is an example of a GET request to the /translate endpoint that will be rejected after March 14, 2025. Use POST requests instead. ```HTTP GET /v2/translate?text=Hello%2C%20world!&target_lang=DE HTTP/2 Host: api.deepl.com Authorization: DeepL-Auth-Key [yourAuthKey] User-Agent: YourApp/1.2.3 ``` -------------------------------- ### Send a Text Translation Request Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/first-things-to-try-with-the-deepl-api Use this cURL command to send a simple text translation request to the DeepL API. Replace '[yourAuthKey]' with your actual API key. This is a basic example to verify your API setup. ```bash curl -X POST 'https://api-free.deepl.com/v2/translate' \ --header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \ --header 'Content-Type: application/json' \ --data '{ "text": [ "Hello, world!" ], "target_lang": "DE" }' ``` -------------------------------- ### Initialize MCP Server Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications Create an MCP-compatible server instance with a specified name, version, and capabilities. This sets up the basic structure for exposing tools to clients. ```javascript const server = new McpServer({ name: "deepl", version: "0.1.0-beta.0", capabilities: { resources: {}, tools: {}, }, }); ``` -------------------------------- ### Initialize DeepL Client and Translate Document Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/java-document-translator Initializes the DeepL client using an authentication key from environment variables and initiates document translation. ```java // Initialize DeepL client String authKey = System.getenv("DEEPL_AUTH_KEY"); if (authKey == null || authKey.isEmpty()) { System.err.println("Error: DEEPL_AUTH_KEY environment variable not set."); return; } File inputFile = Paths.get(inputFilePath).toFile(); File outputFile = Paths.get(outputFilePath).toFile(); DeepLClient client = new DeepLClient(authKey); // Perform translation DocumentStatus status = client.translateDocument(inputFile, outputFile, null, targetLang); System.out.println("Document translation initiated. Document ID: " + status.getDocumentId()); ``` -------------------------------- ### Python: Standard vs. US Regional Endpoint Configuration Source: https://developers.deepl.com/docs/getting-started/regional-endpoints Demonstrates initializing the DeepL Python client with the standard endpoint and a US regional endpoint using the `server_url` parameter. ```python import deepl # Standard endpoint translator = deepl.Translator("[yourAuthKey]") # US regional endpoint translator = deepl.Translator( "[yourAuthKey]", server_url="https://api-us.deepl.com" ) # Usage remains identical result = translator.translate_text("Hello, world!", target_lang="DE") print(result.text) ``` -------------------------------- ### Build Project with Maven Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/java-document-translator Compiles the Java project using Maven. ```bash mvn compile ``` -------------------------------- ### Admin API: Retrieve Custom Tag Analytics Source: https://developers.deepl.com/docs/resources/release-notes Use `GET /v2/admin/analytics/custom-tags` to get usage statistics broken down by custom tags. Supports aggregation by period or day. ```bash curl "https://api.deepl.com/v2/admin/analytics/custom-tags?auth_key=YOUR_AUTH_KEY&aggregate_by=day&start_date=2023-01-01&end_date=2023-01-31" ``` -------------------------------- ### Java: Standard vs. US Regional Endpoint Configuration Source: https://developers.deepl.com/docs/getting-started/regional-endpoints Illustrates setting up the DeepL Java client for the standard endpoint and a US regional endpoint via `TranslatorOptions` and `setServerUrl()`. ```java import com.deepl.api.*; // Standard endpoint Translator translator = new Translator("[yourAuthKey]"); // US regional endpoint TranslatorOptions options = new TranslatorOptions() .setServerUrl("https://api-us.deepl.com"); Translator translator = new Translator("[yourAuthKey]", options); // Usage remains identical TextResult result = translator.translateText("Hello, world!", null, "de"); System.out.println(result.getText()); ``` -------------------------------- ### Retrieve Translation Memories Source: https://developers.deepl.com/docs/resources/release-notes Use `GET /v3/translation_memories` to retrieve a list of translation memories associated with your account. ```bash curl "https://api.deepl.com/v3/translation_memories?auth_key=YOUR_AUTH_KEY" ``` -------------------------------- ### Set Up DeepL CLI Authentication Source: https://developers.deepl.com/docs/getting-started/deepl-cli Configure authentication for the DeepL CLI. You can use an interactive wizard, set the API key directly, or use an environment variable. ```bash deepl init ``` ```bash deepl auth set-key YOUR_API_KEY ``` ```bash export DEEPL_API_KEY=YOUR_API_KEY ``` -------------------------------- ### Retrieve Supported Languages (v3) Source: https://developers.deepl.com/docs/resources/roadmap-and-release-notes Use `GET /v3/languages` to retrieve a list of supported languages for text translation. This endpoint is now generally available. ```http GET /v3/languages HTTP/1.1 Host: api.deepl.com Authorization: DeepL-Auth-Key YOUR_AUTH_KEY ``` -------------------------------- ### Create DeepL MCP Server Implementation Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications Implements the core `McpServer` class using `StdioServerTransport` for communication. It configures the server name, version, and capabilities, and sets up the DeepL translator using an API key from environment variables. ```javascript import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; import * as deepl from 'deepl-node'; // The DeepL API Key is passed in as a part of the client configuration const DEEPL_API_KEY = process.env.DEEPL_API_KEY; const translator = new deepl.Translator(DEEPL_API_KEY); // Create server instance const server = new McpServer({ name: "deepl", // The name clients will use to identify this server version: "0.1.0-beta.0", // Version for compatibility checks capabilities: { resources: {}, tools: {}, }, }); // Server implementation goes here async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error("DeepL MCP Server running on stdio"); } main().catch((error) => { console.error("Fatal error in main():", error); process.exit(1); }); ``` -------------------------------- ### Python Translation Request Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/translation-beginners-guide Translate text using the official DeepL Python client library. Replace {YOUR_API_KEY} with your key and ensure the library is installed. ```py import deepl auth_key = "{YOUR_API_KEY}" # replace with your key deepL_client = deepl.DeepLClient(auth_key) result = deepl_client.translate_text("Hello, bright universe!", target_lang="JA") print(result.text) ``` -------------------------------- ### Run Translator for Marketing Materials Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/java-document-translator Executes the Java document translator using Maven to translate a DOCX file to Japanese. ```bash mvn exec:java -Dexec.args="./brochure.docx JA" ``` -------------------------------- ### API Usage Logger Cookbook Source: https://developers.deepl.com/docs/resources/release-notes A cookbook demonstrating how to capture and analyze DeepL API usage data locally. ```python # This is a placeholder for the actual code example from the cookbook. # The source only provides a link to the GitHub repository. # For the actual code, please refer to: DeepLcom/deepl-api-usage-logger on GitHub. ``` -------------------------------- ### Translate using Style Rules with Custom Instructions Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/translating-between-variants Employ style rules with custom instructions for precise variant translation and consistent transformations across multiple requests. This method is ideal when maintaining exact content is crucial and reusable rules are desired. ```bash curl -X POST 'https://api.deepl.com/v2/translate' \ --header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \ --header 'Content-Type: application/json' \ --data '{ "text": ["I went to the pharmacy."], "target_lang": "en-GB", "style_id": "your-style-rule-id" }' ``` ```json { "translations": [ { "detected_source_language": "EN", "text": "I went to the chemist's." } ] } ``` -------------------------------- ### PHP: Standard vs. US Regional Endpoint Configuration Source: https://developers.deepl.com/docs/getting-started/regional-endpoints Explains how to set up the DeepL PHP client for the standard endpoint and a US regional endpoint using the `server_url` option in the options array. ```php use DeepL\Translator; // Standard endpoint $translator = new Translator('[yourAuthKey]'); // US regional endpoint $translator = new Translator( '[yourAuthKey]', ['server_url' => 'https://api-us.deepl.com'] ); // Usage remains identical $result = $translator->translateText('Hello, world!', null, 'de'); echo $result->text; ``` -------------------------------- ### Retrieve Supported Voice Languages Source: https://developers.deepl.com/docs/resources/roadmap-and-release-notes Use `GET /v3/languages?resource=voice` to programmatically discover language support for the Voice API, including beta features like `spoken_terms` and `translated_speech`. ```http GET /v3/languages?resource=voice HTTP/1.1 Host: api.deepl.com Authorization: DeepL-Auth-Key YOUR_AUTH_KEY ``` -------------------------------- ### Translate Text via cURL Source: https://developers.deepl.com/docs This section provides a cURL command example for making a translation request to the DeepL API. It demonstrates how to include the authorization header and the JSON payload. ```APIDOC ## Translate Text via cURL ### Description Use this cURL command to send a translation request to the DeepL API. ### Method POST ### Endpoint https://api.deepl.com/v2/translate ### Headers - **Content-Type**: application/json - **Authorization**: DeepL-Auth-Key [yourAuthKey] ### Request Body - **text** (array of strings) - Required - The text to translate. - **target_lang** (string) - Required - The language to translate the text into (e.g., "DE" for German). ### Request Example ```bash curl -X POST https://api.deepl.com/v2/translate \ --header "Content-Type: application/json" \ --header "Authorization: DeepL-Auth-Key $API_KEY" \ --data '{ "text": ["Hello world!"], "target_lang": "DE" }' ``` ### Response #### Success Response (200) - **translations** (array of objects) - Contains the translated text and detected source language. - **detected_source_language** (string) - The language detected in the source text. - **text** (string) - The translated text. #### Response Example ```json { "translations": [ { "detected_source_language": "EN", "text": "Hallo, Welt!" } ] } ``` ``` -------------------------------- ### Example XML Response with Customized Outline Detection Source: https://developers.deepl.com/docs/xml-and-html-handling/customized-xml-outline-detection The translated XML response reflects the structure defined by the `splitting_tags` parameter, ensuring sentence splitting aligns with the specified tags. ```markup Der Titel eines Dokuments Das ist der erste Satz. Gefolgt von einem zweiten. Dies ist der dritte Satz. ``` -------------------------------- ### Ruby DeepL API Sample Request Source: https://developers.deepl.com/docs/getting-started/quickstart This Ruby code demonstrates how to configure the DeepL gem with your API key and translate text. Replace '{YOUR_API_KEY}' with your actual key. Environment variables are recommended for production. ```ruby require 'deepl' DeepL.configure do |config| config.auth_key = '{YOUR_API_KEY}' # replace with your key end translation = DeepL.translate 'Hello, world!', nil, 'de' puts translation.text ``` -------------------------------- ### Initialize Translation Process in Godot Script Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/automating-indie-game-localization-with-the-deepl-api-and-godot Sets up the translation structure and initiates the translation process when the script's node is ready. It's recommended to attach this to a button event for manual control. ```gdscript func _ready(): on_translate() ``` ```gdscript func on_translate(): for lang in languages: translations[lang] = {} start_translations() func start_translations(): for original in originals: request_translation( original["key"], original["original"], original["context"] ) ``` -------------------------------- ### Translate Text using JavaScript Client Library Source: https://developers.deepl.com/docs This snippet demonstrates how to use the DeepL Node.js client library for text translation. It includes installation, authentication, and an asynchronous translation call. ```APIDOC ## Translate Text using JavaScript ### Description Translate text using the official DeepL Node.js client library. ### Installation ```bash npm install deepl-node ``` ### Usage ```javascript import * as deepl from 'deepl-node'; const authKey = "{YOUR_API_KEY}"; // replace with your key const deeplClient = new deepl.DeepLClient(authKey); (async () => { const result = await deeplClient.translateText('Hello, world!', null, 'de'); console.log(result.text); })(); ``` ### Sample Output ``` Hallo, Welt! ``` ``` -------------------------------- ### Node.js: Standard vs. US Regional Endpoint Configuration Source: https://developers.deepl.com/docs/getting-started/regional-endpoints Shows how to configure the DeepL Node.js client for the standard endpoint and a US regional endpoint using the `serverUrl` option. ```javascript const deepl = require('deepl-node'); // Standard endpoint const translator = new deepl.Translator('[yourAuthKey]'); // US regional endpoint const translator = new deepl.Translator( '[yourAuthKey]', { serverUrl: 'https://api-us.deepl.com' } ); // Usage remains identical (async () => { const result = await translator.translateText('Hello, world!', null, 'de'); console.log(result.text); })(); ``` -------------------------------- ### Enable Watch Mode for Development Source: https://developers.deepl.com/docs/getting-started/deepl-cli Monitor a directory for file changes and automatically translate them to specified languages, outputting the results to another directory. This is ideal for development environments. ```bash deepl watch ./content/en --to de,fr --output ./content/ ``` -------------------------------- ### C# DeepL API Sample Request Source: https://developers.deepl.com/docs/getting-started/quickstart This C# code snippet demonstrates how to authenticate with the DeepL API using an API key and translate a simple text. Remember to replace '{YOUR_API_KEY}' with your actual key. Storing keys in environment variables is recommended for production. ```csharp using DeepL; var authKey = "{YOUR_API_KEY}"; // replace with your key var client = new DeepLClient(authKey); var translatedText = await client.TranslateTextAsync( "Hello, world!", null, LanguageCode.German); Console.WriteLine(translatedText); ``` -------------------------------- ### Disable Translation of HTML Elements Source: https://developers.deepl.com/docs/xml-and-html-handling/html Use the `translate="no"` attribute to prevent specific HTML elements from being translated by the DeepL API. This example shows a paragraph that remains untranslated. ```markup

My First Heading

My first paragraph.

``` ```markup

Meine erste Überschrift

My first paragraph.

``` -------------------------------- ### Configure Claude Desktop to Use DeepL MCP Server Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications Add your DeepL MCP server configuration to the Claude Desktop configuration file. Ensure you replace placeholder paths and API keys with your actual values. ```json { "mcpServers": { "deepl": { "command": "node", "args": [ "/path/to/deepl-mcp-server/src/index.mjs" ], "env": { "DEEPL_API_KEY": "your-api-key-here" } } } } ``` -------------------------------- ### Set Up Stdio Transport for MCP Server Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications Establish communication between the MCP server and clients using the StdioServerTransport. This enables the server to connect and exchange messages. ```javascript const transport = new StdioServerTransport(); await server.connect(transport); ``` -------------------------------- ### Run Translator for Technical Documentation Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/java-document-translator Executes the Java document translator using Maven to translate a PDF file to US English. ```bash mvn exec:java -Dexec.args="./api-documentation.pdf EN-US" ``` -------------------------------- ### Translate to German (Swiss) or French (Canadian) Source: https://developers.deepl.com/docs/resources/roadmap-and-release-notes Use `de-CH` or `fr-CA` as `target_lang` values for text translation to get tailored translations for Swiss German and Canadian French. These variants are now generally available. ```http POST /v2/translate HTTP/1.1 Host: api.deepl.com Authorization: DeepL-Auth-Key YOUR_AUTH_KEY Content-Type: application/x-www-form-urlencoded text=Hello&target_lang=de-CH ``` -------------------------------- ### Define Game Texts and Target Languages in GDScript Source: https://developers.deepl.com/docs/learning-how-tos/cookbook/automating-indie-game-localization-with-the-deepl-api-and-godot Specifies the target languages for translation and the original game texts with their keys, original content, and context. This setup is the first step in the localization process. ```gdscript var languages = [ "DE", "ES", "JA" ] var originals = [ {"key": "player_greeting", "original": "Hey there, ready for an adventure?", "context": "Player character; Initial interaction"}, {"key": "exit", "original": "Press 'Exit' to leave.", "context": "Instruction; Button label for exiting the game"}, {"key": "score", "original": "Your score is:", "context": "Result; Displayed after completing a level"}, ] ``` -------------------------------- ### Translate a Document Source: https://developers.deepl.com/docs/learning-how-tos/examples-and-guides/first-things-to-try-with-the-deepl-api This cURL command demonstrates how to initiate a document translation request. Ensure you replace '[yourAuthKey]' with your API key and 'document.docx' with the path to your file. Further steps are required to retrieve the translated document. ```bash curl -X POST 'https://api-free.deepl.com/v2/document' \ --header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \ --form 'target_lang=DE' \ --form 'file=@document.docx' ```