Translation

Overview

The Translation API uses a proprietary deep learning model to translate text between commonly spoken languages. Our multilingual model can translate between any two supported languages, preserving meaning and fluency without requiring intermediate translation to English. Our model is optimized for shorter segments of text to support enterprise use-cases at scale. A key example would be translation or localization of user-generated content such as social media posts, comments, messages, or reviews.

Language Support

The Translation API currently supports translation between any pair of the following languages:

  • English
  • Spanish
  • Portuguese
  • German
  • Arabic
  • French
  • Hindi (Devanagari script only)
  • Indonesian
  • Italian
  • Japanese
  • Korean
  • Thai
  • Chinese (Simplified)
  • Chinese (Traditional)

As examples, we would support translation between Portuguese and German or Spanish and French without requiring intermediate translation to English. We also plan to add support for additional languages in the coming months. To learn more or request additional languages, please contact [email protected].

Translation API Requests

Requests to the Translation API take three inputs: the raw text data you wish to translate, an identifier for the source language (optional), and an identifier for the target language. The API returns a translation of the input text into the specified target language.

Language IDs

Our model will automatically determine the language of the input, however you can also specify one. When submitting translation requests, you'll need to provide the following IDs to specify the language of the source text and the target language for the translation:

LanguageIdentifier
EnglishEN
SpanishES
FrenchFR
GermanDE
PortuguesePT
Hindi (Devanagari)HI
IndonesianID
ItalianIT
ArabicAR
JapaneseJA
KoreanKO
ThaiTH
Chinese (Simplified)ZH_CN
Chinese (Traditional)ZH_TW

Form Data and Request Syntax

The following form data must be provided in body of API request:

FieldTypeDescription
text_dataStringRaw text content you wish to translate
input_language (optional)StringThe two character ID specifying the language of the input text
output_languageStringThe two character ID for the language you wish to translate to

You can submit translation API requests either synchronously or asynchronously depending on your needs and submission volume. For more information on each submission protocol, please visit our API Reference pages.

Here's example syntax for a synchronous (on-demand) request to translate from English to Spanish:

import requests
import json

headers = {
    'Authorization': 'Token YOUR_API_KEY', 
}

data = {
  'text_data': 'To be or not to be, that is the question.',
  'options': json.dumps({
          'input_language': 'EN',
          'output_language': 'ES'})
}

response = requests.post('https://api.thehive.ai/api/v2/task/sync',
                          headers=headers, 
                          data=data)

response_string = response.text 
response_dict = response.json()
await api.task_sync({
      form_data: {
        text_data: "To be or not to be, that is the question.",
        options: JSON.stringify({
          input_language: 'EN',
          output_language: 'ES',
        })
      },

🚧

IMPORTANT:

Text inputs are limited to 512 characters. To translate longer segments of text, you'll need to split the source text into shorter segments. For best results, we recommend splitting into complete sentences (e.g., based on punctuation and/or capitalization) to preserve context and meaning. The Translation API is generally not intended for long-form content such as documents and full webpages.

Response

The Translation API will return a translation of the input text in the specified target language. The translation model is trained to understand punctuation standards in supported languages and preserves any punctuation included the input text. To see an annotated example of the Translation API response object, you can visit our API reference page.


What’s Next

See an example Translation API response object with an overview of response fields.