### Install ModernMT Client Libraries Source: https://www.modernmt.com/api/index Instructions for installing the ModernMT client libraries for various programming languages and environments. These libraries simplify interaction with the ModernMT API. ```bash npm i modernmt # or yarn add ``` ```html ``` ```bash pip3 install modernmt ``` ```bash go get github.com/modernmt/modernmt-go ``` ```xml com.modernmt modernmt-java 1.5.0 ``` ```gradle compile "com.modernmt:modernmt-java:1.5.0" ``` ```bash dotnet add package modernmt-dotnet ``` ```bash composer require modernmt/modernmt-php ``` -------------------------------- ### Initiate Batch Translation (Go) Source: https://www.modernmt.com/api/index This Go example illustrates how to start a batch translation with ModernMT. It involves setting up translation options, including metadata and an idempotency key, and then calling the BatchTranslate function with the webhook URL, languages, and text. It returns an 'enqueued' status and any potential error. ```go // --- Request --- options := modernmt.TranslateOptions{ Metadata: metadata{ time.Now().UnixNano() / int64(time.Millisecond), // Timestamp }, IdempotencyKey: "b7f04ab3-68d6-47c0-8eea-0743a710b620", } webhook := "https://example.com" enqueued, err := mmt.BatchTranslate(webhook, "en", "it", "Hello world.", &options) ``` -------------------------------- ### Authentication with API Key Source: https://www.modernmt.com/api/index Explains how to authenticate API requests using an API key provided by ModernMT. Includes examples for cURL and various client libraries. ```APIDOC ## Authentication > AUTHENTICATION > LibrariescURLNode.jsPythonGoJava.NETPHP ```curl curl -H "MMT-ApiKey: YOUR_API_KEY" ... ``` ```javascript import {ModernMT} from "modernmt"; const mmt = new ModernMT("YOUR_API_KEY") ``` ```python from modernmt import ModernMT mmt = ModernMT("YOUR_API_KEY") ``` ```go import ( "github.com/modernmt/modernmt-go" ) mmt := modernmt.Create("YOUR_API_KEY") ``` ```java import com.modernmt.ModernMT; ModernMT mmt = new ModernMT("YOUR_API_KEY"); ``` ```csharp using ModernMT; var mmt = new ModernMTService("YOUR_API_KEY"); ``` ```php require "./vendor/autoload.php"; use ModernMT\ModernMT; $mmt = new ModernMT("YOUR_API_KEY"); ``` The ModernMT API uses API keys to authenticate requests. You can view and manage your API key in the account Dashboard. For every API request you have to include an HTTP header named `MMT-ApiKey` which contains your API key as value. API requests without this header will fail. The API key is unique and identifies you, so be sure to keep it secure. ``` -------------------------------- ### Initiate Batch Translation (PHP) Source: https://www.modernmt.com/api/index This PHP example demonstrates how to initiate a batch translation using the ModernMT client. It specifies the webhook URL, source and target languages, and the text to translate. Optional parameters can include metadata and an idempotency key. The function returns an 'enqueued' status. ```php // --- Request --- $webhook = "https://example.com"; $enqueued = $mmt->batchTranslate($webhook, "en", "it", "Hello world.", null, null, [ "metadata" => [ "timestamp" => floor(microtime(true) * 1000) ], "idempotency_key" => "b7f04ab3-68d6-47c0-8eea-0743a710b620" ]); ``` -------------------------------- ### Client Identity Headers Source: https://www.modernmt.com/api/index Details how to provide client identity information (platform name and version) in API requests using `MMT-Platform` and `MMT-PlatformVersion` headers. Includes examples for cURL and various client libraries. ```APIDOC ## Client Identity > CLIENT IDENTITY > LibrariescURLNode.jsPythonGoJava.NETPHP ```curl curl -H "MMT-ApiKey: YOUR_API_KEY" -H "MMT-Platform: simple-cat-tool" -H "MMT-PlatformVersion: 1.2.8" ... ``` ```javascript import {ModernMT} from "modernmt"; const mmt = new ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8") ``` ```python from modernmt import ModernMT mmt = ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8") ``` ```go import ( "github.com/modernmt/modernmt-go" ) mmt := modernmt.CreateWithIdentity("YOUR_API_KEY", "simple-cat-tool", "1.2.8") ``` ```java import com.modernmt.ModernMT; ModernMT mmt = new ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8"); ``` ```csharp using ModernMT; var mmt = new ModernMTService("YOUR_API_KEY", "simple-cat-tool", "1.2.8"); ``` ```php require "./vendor/autoload.php"; use ModernMT\ModernMT; $mmt = new ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8"); ``` Clients which use ModernMT API can specify additional identity information using the following headers: * `MMT-Platform`: the name of the client. * `MMT-PlatformVersion`: the version of the client. Those data are optional but can be extremely valuable in our support activities, allowing us to track the traffic of a specific client, and letting us immediately intervene in case of necessity, therefore we recommend to include them in every API request. ``` -------------------------------- ### Set Client Identity for ModernMT API Requests Source: https://www.modernmt.com/api/index Shows how to provide client identity information, such as platform name and version, in API requests. This helps in tracking and support. It includes examples for various client libraries. ```bash curl -H "MMT-ApiKey: YOUR_API_KEY" -H "MMT-Platform: simple-cat-tool" -H "MMT-PlatformVersion: 1.2.8" ... ``` ```javascript import {ModernMT} from "modernmt"; const mmt = new ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8") ``` ```python from modernmt import ModernMT mmt = ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8") ``` ```go import ( "github.com/modernmt/modernmt-go" ) mmt := modernmt.CreateWithIdentity("YOUR_API_KEY", "simple-cat-tool", "1.2.8") ``` ```java import com.modernmt.ModernMT; ModernMT mmt = new ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8"); ``` ```csharp using ModernMT; var mmt = new ModernMTService("YOUR_API_KEY", "simple-cat-tool", "1.2.8"); ``` ```php require "./vendor/autoload.php"; use ModernMT\ModernMT; $mmt = new ModernMT("YOUR_API_KEY", "simple-cat-tool", "1.2.8"); ``` -------------------------------- ### POST /translate - Translation with Hints Source: https://www.modernmt.com/api/index Translate text while providing hints to guide the translation process, potentially improving accuracy for specific terms. ```APIDOC ## POST /translate - Translation with Hints ### Description Translate text and provide optional hints to influence the translation output. Hints can help ensure specific terms or phrases are translated as intended. ### Method POST ### Endpoint https://api.modernmt.com/translate ### Parameters #### Request Body - **source** (string) - Required - The source language code (e.g., 'it'). - **target** (string) - Required - The target language code (e.g., 'en'). - **q** (string) - Required - The text to translate. - **hints** (string) - Optional - A comma-separated string of hint IDs to guide the translation. - **MMT-ApiKey** (string) - Required - Your ModernMT API key. ### Request Example ```json { "source": "it", "target": "en", "q": "Dì il mio nome.", "hints": "37790" } ``` ### Response #### Success Response (200) - **status** (integer) - The HTTP status code. - **data** (object) - Contains the translation details. - **translation** (string) - The translated text. - **billedCharacters** (integer) - The number of characters billed for the translation. - **characters** (integer) - The total number of characters in the text. - **contextVector** (string) - A vector representing the context used for translation. #### Response Example ```json { "status": 200, "data": { "translation": "Say my name.", "billedCharacters": 15, "characters": 15, "contextVector": "37790:1" } } ``` ``` -------------------------------- ### Initiate Batch Translation (.NET) Source: https://www.modernmt.com/api/index This .NET example demonstrates initiating a batch translation request with ModernMT. It involves setting up TranslateOptions with metadata and an idempotency key, then calling the BatchTranslate method with the webhook URL, languages, and text. The method returns a boolean indicating successful enqueuing. ```csharp // --- Request --- var opts = new TranslateOptions { Metadata = new Dictionary { { "timestamp", DateTimeOffset.Now.ToUnixTimeMilliseconds() } }, IdempotencyKey = "b7f04ab3-68d6-47c0-8eea-0743a710b620" }; const string webhook = "https://example.com"; var enqueued = mmt.BatchTranslate(webhook, "en", "it", "Hello world.", opts); ``` -------------------------------- ### Initiate Batch Translation (Python) Source: https://www.modernmt.com/api/index This Python example demonstrates initiating a batch translation request using the ModernMT library. It requires a webhook URL for receiving results, source and target languages, and the text. Options can be provided for metadata and idempotency keys. The function returns an 'enqueued' status upon successful request submission. ```python # --- Request --- webhook = 'https://example.com' enqueued = mmt.batch_translate(webhook, 'en', 'it', 'Hello world.', options={ 'metadata': { 'timestamp': time.time() }, 'idempotency_key': 'b7f04ab3-68d6-47c0-8eea-0743a710b620' }) ``` -------------------------------- ### Initiate Batch Translation (Java) Source: https://www.modernmt.com/api/index This Java example shows how to initiate a batch translation using the ModernMT client library. It involves creating TranslateOptions, setting metadata and an idempotency key, and then calling the batchTranslate method with the webhook URL, languages, and text. The method returns a boolean indicating if the request was enqueued. ```java // --- Request --- TranslateOptions opts = new TranslateOptions(); opts.setMetadata(new Metadata()); // in our example has a timestamp field opts.setIdempotencyKey("b7f04ab3-68d6-47c0-8eea-0743a710b620"); String webhook = "https://example.com"; boolean enqueued = mmt.batchTranslate(webhook, "en", "it", "Hello world.", opts); ``` -------------------------------- ### Get Public Key Source: https://www.modernmt.com/api/index Retrieves ModernMT's public key for signature verification of callbacks. ```APIDOC ## GET /translate/batch/key ### Description Retrieves the public key used by ModernMT to sign callback requests. This key is necessary for verifying the authenticity of data received at your webhook endpoint. ### Method GET ### Endpoint /translate/batch/key ### Parameters None ### Response #### Success Response (200) - **publicKey** (string) - The public key encoded in base64. #### Response Example ```json { "publicKey": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...\n-----END PUBLIC KEY-----" } ``` ``` -------------------------------- ### Handle Batch Translation Callback (Node.js) Source: https://www.modernmt.com/api/index This Node.js example shows how to process the callback received from the ModernMT API after a batch translation is complete. It utilizes the mmt.handleCallback method, which requires the raw response body and the 'x-modernmt-signature' header. The function parses the translation results and associated metadata. ```javascript // --- Callback --- // body must be an object or a json string // signature must be the value of 'x-modernmt-signature' header const batchTranslation = await mmt.handleCallback(body, signature) ``` -------------------------------- ### Do-not-translate Feature Example (HTML) Source: https://www.modernmt.com/api/index This example demonstrates the 'do-not-translate' feature in ModernMT by showing how to exclude specific text segments from translation using HTML/XML tags. It illustrates two methods: using the 'translate="no"' attribute and the 'class="notranslate"' attribute on a span element. ```html

The Leaning Tower of Pisa is known as Torre pendente di Pisa in Italian.

The Leaning Tower of Pisa is known as Torre pendente di Pisa in Italian.

``` -------------------------------- ### Base URL and Client Libraries Source: https://www.modernmt.com/api/index Provides the base URL for the ModernMT API and lists available client libraries for various programming languages. ```APIDOC ## Introduction > BASE URL ``` https://api.modernmt.com/ ``` CLIENT LIBRARIES cURL Node.js Python Go Java .NET PHP By default, the documentation demonstrates using cURL to interact with the API over HTTPS. Select one of our official client libraries to see examples in code. ``` -------------------------------- ### GET /translate/languages - List Supported Languages Source: https://www.modernmt.com/api/index Retrieves a list of all language codes supported by the ModernMT translation service. These codes are in ISO 639-1 format. ```APIDOC ## GET /translate/languages ### Description Gives the list of supported language codes (`ISO 639-1`) for translation. ### Method GET ### Endpoint /translate/languages ### Parameters #### Query Parameters None. ### Request Example ```json { "example": "No request body needed for this GET request." } ``` ### Response #### Success Response (200) - **data** (array) - An array containing supported language codes. - **status** (integer) - The HTTP status code of the response. #### Response Example ```json { "data": [ "en", "fr", "es" ], "status": 200 } ``` ``` -------------------------------- ### Authenticate with ModernMT API using API Keys Source: https://www.modernmt.com/api/index Demonstrates how to authenticate API requests using an API key. This is a fundamental step for all interactions with the ModernMT API. It shows the key header to be included in requests. ```bash curl -H "MMT-ApiKey: YOUR_API_KEY" ... ``` ```javascript import {ModernMT} from "modernmt"; const mmt = new ModernMT("YOUR_API_KEY") ``` ```python from modernmt import ModernMT mmt = ModernMT("YOUR_API_KEY") ``` ```go import ( "github.com/modernmt/modernmt-go" ) mmt := modernmt.Create("YOUR_API_KEY") ``` ```java import com.modernmt.ModernMT; ModernMT mmt = new ModernMT("YOUR_API_KEY"); ``` ```csharp using ModernMT; var mmt = new ModernMTService("YOUR_API_KEY"); ``` ```php require "./vendor/autoload.php"; use ModernMT\ModernMT; $mmt = new ModernMT("YOUR_API_KEY"); ``` -------------------------------- ### Equivalent Terms Glossary Format Source: https://www.modernmt.com/api/index Details the structure and requirements for an equivalent terms glossary CSV file. ```APIDOC ## Equivalent Terms Glossary ### Description An equivalent terms glossary provides corresponding terms across multiple languages, acting as a multi-lingual dictionary. ### File Format - CSV file with multiple columns. - First column: `tuid` (unique string identifier). - Remaining columns: ISO 639-1 language codes. - First row: Header with `tuid` followed by language codes. - Empty values are permissible for non-`tuid` fields, but each row must have at least two non-empty, non-`tuid` fields. ### Example ```csv tuid | en | it | fr | es ----|----|----|----|---- 1 | test | prova | | prueba 2 | Translated | Translated | Translated | Translated 3 | | ModernMT | | ModernMT ``` ### Usage Ensures consistent translation of terms within the same row across specified languages. The `tuid` is essential for updating specific entries. ``` -------------------------------- ### Initiate Batch Translation (Node.js) Source: https://www.modernmt.com/api/index This Node.js snippet shows how to initiate a batch translation using the ModernMT library. It specifies the webhook URL, source and target languages, and the text to translate. Optional parameters allow for custom metadata and an idempotency key to prevent duplicate requests. The function returns an 'enqueued' status. ```javascript // --- Request --- const webhook = 'https://example.com'; const enqueued = await mmt.batchTranslate(webhook, 'en', 'it', 'Hello world.', undefined, undefined, { metadata: { timestamp: Date.now() }, idempotencyKey: 'b7f04ab3-68d6-47c0-8eea-0743a710b620' }) ``` -------------------------------- ### Create New Memory - Go Source: https://www.modernmt.com/api/index Creates a new memory with the specified name and an optional description using the ModernMT SDK for Go. This function is part of the Memories package. ```go memory, err := mmt.Memories.Create("chemistry", "") ``` -------------------------------- ### API Response Codes Source: https://www.modernmt.com/api/index Explains the structure of success and error responses from the ModernMT API. ```APIDOC ## Response and Errors ### Success Response (2xx) ```json { "status": 200, "data": ... } ``` - **status** (integer): Indicates a successful request (2xx range). - **data** (any): Contains the result of the API request. ### Error Response (4xx, 5xx) ```json { "status": 400, "error": { "type": "UnsupportedLanguageException", "message": "Language pair not supported: en > xd" } } ``` - **status** (integer): Indicates an error occurred (4xx or 5xx range). - **error** (object): Contains details about the error. - **type** (string): The type of error encountered. - **message** (string): A descriptive message explaining the error. ### HTTP Status Codes - `2xx`: Success - `4xx`: Client-side errors (e.g., missing parameters, invalid data). - `5xx`: Server-side errors within ModernMT. ``` -------------------------------- ### Handle Batch Translation Callback (Go) Source: https://www.modernmt.com/api/index This Go snippet demonstrates handling the callback from ModernMT for batch translations. It uses the HandleTranslateCallbackWithMetadata function, requiring the raw body, signature header, and a pointer to a metadata struct. The function returns the translated data and any error encountered during processing. ```go // --- Callback --- // body must be a slice of bytes // signature must be the value of 'x-modernmt-signature' header metadata := &metadata{} data, err := mmt.HandleTranslateCallbackWithMetadata(body, signature, &metadata) ``` -------------------------------- ### Quality Estimation - Multiple Texts (Go) Source: https://www.modernmt.com/api/index Performs quality estimation for multiple sentences using the ModernMT Go client. The function takes source language, target language, and slices of source sentences and translations as arguments, returning quality estimation results and an error object. ```go qes, err := mmt.QeList("en", "it", []string{"Hello world", "This is an example"}, []string{"Ciao mondo", "Questo è un esempio"}) ``` -------------------------------- ### POST /translate/qe - Multiple Texts Quality Estimation Source: https://www.modernmt.com/api/index Allows to evaluate the quality of a list of translations. ```APIDOC ## POST /translate/qe - Multiple Texts Quality Estimation ### Description Allows to evaluate the quality of a list of translations. ### Method POST ### Endpoint https://api.modernmt.com/translate/qe ### Parameters #### Request Body - **source** (string) - Required - The language code (`ISO 639-1`) of the source sentences. - **target** (string) - Required - The language code (`ISO 639-1`) of the translations. - **sentence** (array) - Required - An array of input sentences. Maximum 128 sentences, total characters <= 10240. - **translation** (array) - Required - An array of input translations. Maximum 128 translations, total characters <= 10240. ### Request Example ```json { "source": "en", "target":"it", "sentence":["Hello world", "This is an example"], "translation": ["Ciao mondo", "Questo è un esempio"] } ``` ### Response #### Success Response (200) - **score** (number) - Represents the quality of the translation. The value can be between `0` (lower) and `1` (higher). #### Response Example ```json { "status": 200, "data": [ { "score": 0.902 }, { "score": 0.956 } ] } ``` ``` -------------------------------- ### Context Vector Guessing from Raw Text Source: https://www.modernmt.com/api/index This endpoint allows you to guess a context vector from raw text. You can provide the text directly or as a file. ```APIDOC ## POST /context-vector ### Description Analyzes provided content (text or file) to generate a context vector for translation quality maximization. ### Method POST ### Endpoint https://api.modernmt.com/context-vector ### Parameters #### Query Parameters - **source** (string) - Required - The language code (ISO 639-1) of the source content. - **targets** (array of strings) - Required - The language codes (ISO 639-1) of the targets, separated by a comma. The response will contain a different vector for each target provided. - **hints** (string) - Optional - Hints for the context vector. - **limit** (integer) - Optional - The maximum number of memories to include in the vector. Lowest weight memories will be filtered out. If omitted or zero, no limit will be applied. - **compression** (string) - Optional - Specifies the compression algorithm. Required if content is compressed. Supported algorithms: gzip. #### Request Body - **content** (file) - Optional - The text file to be analyzed. - **text** (string) - Required if content is omitted - The text to be analyzed. ### Request Example (File) ```json { "content": "@path/to/text_file", "source": "en", "targets": ["it", "es"] } ``` ### Request Example (Text) ```json { "text": "This is an example text for context vector computation", "source": "en", "targets": ["it", "es"] } ``` ### Response #### Success Response (200) - **source** (string) - The language code (ISO 639-1) of the source content provided in the request. - **vectors** (object) - A JSON object whose keys are the target language codes provided in the request, each one with the corresponding context vector as value. #### Response Example ```json { "status": 200, "data": { "source": "en", "vectors": { "it": "37787:0.191,37784:0.163,37790:0.14,37791:0.092" } } } ``` ``` -------------------------------- ### Manage Glossary Entries Source: https://www.modernmt.com/api/index Endpoints for managing glossary entries within a memory, including adding and updating them. ```APIDOC ## POST /memories/:id/glossary ### Description Adds glossary entries to a specified memory. ### Method POST ### Endpoint /memories/:id/glossary ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the memory. #### Query Parameters None #### Request Body - **glossary** (array) - Required - An array of glossary entry objects. - **source_phrase** (string) - Required - The source phrase for the glossary entry. - **target_phrase** (string) - Required - The target translation for the glossary entry. - **locale** (string) - Required - The locale code (e.g., 'en-US', 'fr-FR'). ### Request Example ```json { "glossary": [ { "source_phrase": "example", "target_phrase": "ejemplo", "locale": "en-ES" } ] } ``` ### Response #### Success Response (200) - **status** (integer) - HTTP status code, should be 200. - **data** (object) - A confirmation message or details about the added entries. #### Response Example ```json { "status": 200, "data": { "message": "Glossary entries added successfully." } } ``` ## PUT /memories/:id/glossary ### Description Updates existing glossary entries in a specified memory. ### Method PUT ### Endpoint /memories/:id/glossary ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the memory. #### Query Parameters None #### Request Body - **glossary** (array) - Required - An array of glossary entry objects to update. - **source_phrase** (string) - Required - The source phrase of the entry to update. - **target_phrase** (string) - Required - The new target translation. - **locale** (string) - Required - The locale code of the entry. ### Request Example ```json { "glossary": [ { "source_phrase": "example", "target_phrase": "Beispiel", "locale": "en-DE" } ] } ``` ### Response #### Success Response (200) - **status** (integer) - HTTP status code, should be 200. - **data** (object) - A confirmation message or details about the updated entries. #### Response Example ```json { "status": 200, "data": { "message": "Glossary entries updated successfully." } } ``` ``` -------------------------------- ### Create New Memory - cURL Source: https://www.modernmt.com/api/index Creates a new memory with a specified name. Requires an MMT-ApiKey header and JSON Content-Type. Returns a JSON representation of the created memory. ```bash curl -X POST \ -H "Content-Type: application/json" \ -H "MMT-ApiKey: YOUR_API_KEY" \ --data '{"name": "chemistry"}' \ "https://api.modernmt.com/memories" ``` -------------------------------- ### Translate Text with Hints using ModernMT API Source: https://www.modernmt.com/api/index Translates text while incorporating hints (e.g., glossary IDs) to influence the translation output. Supports cURL, Node.js, Python, Go, Java, .NET, and PHP. ```curl curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Content-Type: application/json" \ -H "MMT-ApiKey: YOUR_API_KEY" \ --data '{"source": "it", "target":"en", "q":"Dì il mio nome.", "hints":"37790"}' \ "https://api.modernmt.com/translate" ``` ```javascript const translation = await mmt.translate("it", "en", "Dì il mio nome.", [37790]) ``` ```python translation = mmt.translate("it", "en", "Dì il mio nome.", [37790]) ``` ```go translation, err := mmt.TranslateAdaptive("it", "en", "Dì il mio nome.", []int64{37790}, "", nil) ``` ```java Translation translation = mmt.translate("it", "en", "Dì il mio nome.", new long[]{37790}); ``` ```csharp var translation = mmt.Translate("it", "en", "Dì il mio nome.", new long[]{37790}); ``` ```php $translation = $mmt->translate("it", "en", "Dì il mio nome.", [37790]); ``` -------------------------------- ### Initiate Batch Translation via API (cURL) Source: https://www.modernmt.com/api/index This snippet demonstrates how to send a POST request to the ModernMT API's batch translation endpoint using cURL. It includes essential headers like Content-Type, MMT-ApiKey, and x-idempotency-key, along with the JSON payload specifying source and target languages, the text to translate, a webhook URL, and optional metadata. ```curl curl -X POST \ -H "Content-Type: application/json" \ -H "MMT-ApiKey: YOUR_API_KEY" \ -H "x-idempotency-key: b7f04ab3-68d6-47c0-8eea-0743a710b620" \ --data '{"source":"en", "target":"it", "q":"Hello world.", "webhook":"https://example.com", "metadata": {"timestamp":1676023422231}}' \ "https://api.modernmt.com/translate/batch" ``` -------------------------------- ### POST /translate/qe - Single Text Quality Estimation Source: https://www.modernmt.com/api/index Allows to evaluate the quality of a single translation. ```APIDOC ## POST /translate/qe - Single Text Quality Estimation ### Description Allows to evaluate the quality of a single translation. ### Method POST ### Endpoint https://api.modernmt.com/translate/qe ### Parameters #### Request Body - **source** (string) - Required - The language code (`ISO 639-1`) of the source sentence. - **target** (string) - Required - The language code (`ISO 639-1`) of the translation. - **sentence** (string) - Required - The input sentence. Maximum 10240 characters. - **translation** (string) - Required - The input translation. Maximum 10240 characters. ### Request Example ```json { "source":"en", "target":"it", "sentence":"Hello world", "translation": "Ciao mondo" } ``` ### Response #### Success Response (200) - **score** (number) - Represents the quality of the translation. The value can be between `0` (lower) and `1` (higher). #### Response Example ```json { "status": 200, "data": { "score": 0.854 } } ``` ``` -------------------------------- ### POST /memories/:id/glossary - CSV FILE Source: https://www.modernmt.com/api/index Uploads glossary content to a specified memory using a CSV file. The `type` parameter is required, and compression can be specified if the CSV is compressed. ```APIDOC ## POST /memories/:id/glossary - CSV FILE ### Description Uploads glossary content to a specified memory using a CSV file. The `type` parameter is required, and compression can be specified if the CSV is compressed. ### Method POST ### Endpoint `/memories/:id/glossary` ### Parameters #### Query Parameters - **id** (integer) - Required - The unique identifier of the memory. #### Request Body - **csv** (file) - Required - The CSV file containing the glossary content. - **compression** (string) - Optional - Specifies the compression algorithm. Supported: `gzip`. - **type** (string) - Required - The type of glossary. Must be `unidirectional` or `equivalent`. ### Request Example ```json { "csv": "@path/to/file.csv", "type": "unidirectional" } ``` ### Response #### Success Response (200) - **status** (integer) - The HTTP status code. - **data** (object) - Contains information about the import job. - **id** (string) - The unique identifier of the import job. - **memory** (integer) - The ID of the memory the glossary is being imported into. - **size** (integer) - The size of the imported glossary content. - **progress** (integer) - The current progress of the import job (0-100). #### Response Example ```json { "status": 200, "data": { "id": "00000000-0000-0000-0000-0000000379fc", "memory": 37790, "size": 18818, "progress": 0 } } ``` ``` -------------------------------- ### Store Glossary Content via Terms Source: https://www.modernmt.com/api/index Add individual glossary terms to a memory. Requires memory ID, a list of terms, the glossary type, and a TU ID for equivalent types. Returns an Import Job upon successful submission. ```curl curl -X POST \ -H "Content-Type: application/json" \ -H "MMT-ApiKey: YOUR_API_KEY" \ --data '{"tuid":"1", "type":"equivalent", "terms":[{"term": "test", "language": "en"}, {"term": "prova", "language": "it"}, {"term": "prueba", "language": "es"}]}' \ "https://api.modernmt.com/memories/37790/glossary" ``` ```node const terms = [ {term: "test", language: "en"}, {term: "prova", language: "it"}, {term: "prueba", language: "es"} ]; const importJob = await mmt.memories.addToGlossary(37790, terms, "equivalent", "1"); ``` ```python terms = [ {"term": "test", "language": "en"}, {"term": "prova", "language": "it"}, {"term": "prueba", "language": "es"}, ] import_job = mmt.memories.add_to_glossary(37790, terms, "equivalent", "1") ``` ```go terms := []GlossaryTerm{{ Term: "test", Language: "en", }, { Term: "prova", Language: "it", }, { Term: "prueba", Language: "es", }} importJob, err := mmt.Memories.AddToGlossary(37790, terms, "equivalent", "1") ``` ```java List terms = new ArrayList<>(); terms.add(new GlossaryTerm("test", "en")); terms.add(new GlossaryTerm("prova", "it")); terms.add(new GlossaryTerm("prueba", "es")); ImportJob importJob = mmt.memories.addToGlossary(37790, terms, "equivalent", "1"); ``` ```csharp var terms = new List { new("test", "en"), new("prova", "it"), new("prueba", "es"), }; var importJob = mmt.Memories.AddToGlossary(37790, terms, "equivalent", "1"); ``` ```php $terms = [ ["term" => "test", "language" => "en"], ["term" => "prova", "language" => "it"], ["term" => "prueba", "language" => "es"] ]; $importJob = $mmt->memories->addToGlossary(37790, $terms, "equivalent", "1"); ``` -------------------------------- ### Translate Text with Glossaries using ModernMT API Source: https://www.modernmt.com/api/index Translates text, applying specified glossaries to ensure consistent terminology. Supports cURL, Node.js, Python, Go, Java, .NET, and PHP. ```curl curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Content-Type: application/json" \ -H "MMT-ApiKey: YOUR_API_KEY" \ --data '{"source": "en", "target":"it", "q":"I loved the movie: The perks of being a wallflower.", "glossaries":"37787,37784,37790,37791"}' \ "https://api.modernmt.com/translate" ``` ```javascript const translation = await mmt.translate("en", "it", "I loved the movie: The perks of being a wallflower.", undefined, undefined, { glossaries: [37787, 37784, 37790, 37791] }); ``` ```python translation = mmt.translate("en", "it", "I loved the movie: The perks of being a wallflower.", options={ "glossaries": [37787, 37784, 37790, 37791], }) ``` ```go options := modernmt.TranslateOptions{ Glossaries: []int64{37787, 37784, 37790, 37791}, } translation, err := mmt.Translate("en", "it", "I loved the movie: The perks of being a wallflower.", &options) ``` ```java TranslateOptions opts = new TranslateOptions(); opts.setGlossaries(new long[]{ 37787, 37784, 37790, 37791 }); Translation translation = mmt.translate("en", "it", "I loved the movie: The perks of being a wallflower.", opts); ``` ```csharp var options = new TranslateOptions(); options.SetGlossaries(new long[] { 37787, 37784, 37790, 37791 }); var translation = mmt.Translate("en", "it", "I loved the movie: The perks of being a wallflower.", options); ``` ```php $translation = $mmt->translate("en", "it", "I loved the movie: The perks of being a wallflower.", null, null, [ 'glossaries' => [37787, 37784, 37790, 37791], ]); ``` -------------------------------- ### Translate Text with Alternative Translations Source: https://www.modernmt.com/api/index Demonstrates how to use the ModernMT API to translate text and request alternative translations. Supports multiple programming languages and cURL. ```curl curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Content-Type: application/json" \ -H "MMT-ApiKey: YOUR_API_KEY" \ --data '{"source": "en", "target":"it", "q":"The weather is good today", "alt_translations": 2}' \ "https://api.modernmt.com/translate" ``` ```javascript const translation = await mmt.translate("en", "it", "The weather is good today", undefined, undefined, { altTranslations: 2 }) ``` ```python translation = mmt.translate("en", "it", "The weather is good today", options={ "alt_translations": 2 }) ``` ```go translation, err := mmt.Translate("en", "it", "The weather is good today", &modernmt.TranslateOptions{ AltTranslations: 2, }) ``` ```csharp TranslateOptions opts = new TranslateOptions(); opts.setAltTranslations(2); Translation translation = mmt.translate("en", "it", "The weather is good today", opts); ``` ```dotnet var translation = mmt.Translate("en", "it", "The weather is good today", new TranslateOptions { AltTranslations = 2 }); ``` ```php $translation = $mmt->translate("en", "it", "The weather is good today", null, null, [ 'alt_translations' => 2 ]); ``` -------------------------------- ### Memories Management API Source: https://www.modernmt.com/api/index Endpoints for managing translation memories, including listing, retrieving, creating, updating, and deleting memories and their content. ```APIDOC ## Memories Endpoints ### Description These endpoints allow for the management of translation memories. ### Method GET, POST, PUT, DELETE ### Endpoints #### Memory Operations - **GET /memories**: List all memories. - **GET /memories/:id**: Retrieve a specific memory by its ID. - **POST /memories**: Create a new memory. - **PUT /memories/:id**: Update an existing memory by its ID. - **DELETE /memories/:id**: Delete a memory by its ID. #### Content Operations - **POST /memories/:id/content**: Add content to a specific memory. - **PUT /memories/:id/content**: Update content in a specific memory. ``` -------------------------------- ### Retrieve All Memories - cURL Source: https://www.modernmt.com/api/index Fetches a list of all memories associated with the API key. Requires an MMT-ApiKey header. Returns an array of memory objects. ```bash curl -H "MMT-ApiKey: YOUR_API_KEY" "https://api.modernmt.com/memories" ``` -------------------------------- ### Update Glossary Entry using Go Source: https://www.modernmt.com/api/index Replaces terms in a glossary entry for a given memory. It takes the memory ID, a slice of GlossaryTerm, the type of glossary, and the tuid as input. ```go terms := []GlossaryTerm{{ Term: "test", Language: "en", }, { Term: "prova", Language: "it", }, { Term: "prueba", Language: "es", }} importJob, err := mmt.Memories.ReplaceInGlossary(37790, terms, "equivalent", "1") ``` -------------------------------- ### Quality Estimation - Single Text (Go) Source: https://www.modernmt.com/api/index Performs quality estimation for a single sentence using the ModernMT Go client. The function takes source language, target language, source sentence, and translation as arguments and returns a quality score and an error object. ```go qe, err := mmt.Qe("en", "it", "Hello world", "Ciao mondo") ``` -------------------------------- ### Store Glossary Content via CSV File Source: https://www.modernmt.com/api/index Upload a CSV file to store glossary content in a memory. Requires memory ID, the CSV file, and the glossary type. Other parameters like compression can be specified. Returns an Import Job upon successful submission. ```curl curl -X POST \ -H "MMT-ApiKey: YOUR_API_KEY" \ -F "csv=@path/to/file.csv" \ -F 'type=unidirectional' \ "https://api.modernmt.com/memories/37790/glossary" ``` ```node const importJob = await mmt.memories.importGlossary(37790, "/path/to/file.csv", "unidirectional"); // or ReadStream ``` ```python import_job = mmt.memories.import_glossary(37790, "/path/to/file.csv", "unidirectional") # or stream ``` ```go importJob, err := mmt.Memories.ImportGlossaryPath(37790, "path/to/file.csv", "unidirectional", "") // or *os.File ``` ```java ImportJob importJob = mmt.memories.importGlossary(37790, "path/to/file.csv", "unidirectional"); // or File ``` ```csharp var importJob = mmt.Memories.ImportGlossary(37790, "path/to/file.csv", "unidirectional"); // or FileStream ``` ```php $importJob = $mmt->memories->importGlossary(37790, "path/to/file.csv", "unidirectional"); ``` -------------------------------- ### Retrieve All Memories - Go Source: https://www.modernmt.com/api/index Retrieves a list of all memories using the ModernMT SDK for Go. This function is part of the Memories package. ```go memories, err := mmt.Memories.List() ``` -------------------------------- ### Generate Context Vector from File Source: https://www.modernmt.com/api/index This functionality allows generating a context vector from a file. It supports various libraries and takes source and target languages as input. The output is a JSON object containing context vectors for each target language. ```curl curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "MMT-ApiKey: YOUR_API_KEY" \ -F "content=@path/to/text_file" \ -F "source=en" \ -F "targets=it" \ -F "targets=es" \ "https://api.modernmt.com/context-vector" ``` ```javascript const contextVectors = await mmt.getContextVectorFromFile("en", ["es", "it"], "path/to/file.txt") // or ReadStream ``` ```python context_vectors = mmt.get_context_vector_from_file("en", ["es", "it"], "path/to/file.txt") # or stream ``` ```go contextVectors, err := mmt.GetContextVectorsFromFilePath("en", []string{"es", "it"}, "path/to/file.txt", nil, 0, "") // or *os.File ``` ```java String contextVectors = mmt.getContextVectorFromFile("en", Arrays.asList("es", "it"), "path/to/file.txt"); // or File ``` ```csharp var contextVectors = mmt.GetContextVectorFromFile("en", new List{"es", "it"}, "path/to/file.txt"); // or FileStream ``` ```php $context_vectors = $mmt->get_context_vector_from_file("en", ["es", "it"], "path/to/file.txt"); ```