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