Getting started with Translate
Yandex Translate provides an API for integrating translation technologies into your applications. If you want to use a UI for translation, use Yandex Translator
In this section, you will learn how to translate text using the Translate API.
To use the examples, install cURL
Refer to the step-by-step guides for more examples in different programming languages.
To learn how to create a service account and an API key to integrate Yandex Translate into your application, see Setting up access with API keys.
Getting started
-
On the Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account yet, create one. -
Get the authorization data for your account:
-
Get an IAM token to authenticate your Yandex account or federated account. Transmit the token in the
Authorization
header of each request in the following format:Authorization: Bearer <IAM token>
-
Get the ID of any folder for which your account has the
ai.translate.user
role or higher. Make sure to include your folder ID in thefolderId
field in the body of each request.
-
Translating text
The example below is intended to be run in MacOS and Linux. To run it in Windows, see how to work with Bash in Microsoft Windows.
This example shows how to translate two strings containing Hello and World into Russian. The text source language is recognized automatically.
-
Create a file with the request body, e.g.,
body.json
:{ "folderId": "<Folder_ID>", "texts": ["Hello", "World"], "targetLanguageCode": "ru" }
Where:
folderId
: Folder ID received before starting.texts
: Text to translate as a list of strings.targetLanguageCode
: Target language. You can get the language code with a list of supported languages.
-
Submit the file for translation by running the command:
export IAM_TOKEN=<IAM_token> curl \ --request POST \ --header "Content-Type: application/json" \ --header "Authorization: Bearer ${IAM_TOKEN}" \ --data '@<path_to_JSON_file>' \ "https://translate.api.cloud.yandex.net/translate/v2/translate"
Where
IAM_TOKEN
is the IAM token received before starting.The service will return the translated strings:
{ "translations": [ { "text": "Hello", "detectedLanguageCode": "en" }, { "text": "World", "detectedLanguageCode": "en" } ] }