Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Translate
  • Getting started
  • Step-by-step instructions
    • All instructions
    • How to translate text
    • How to improve the accuracy of translations
    • Detecting language
    • Getting a list of supported languages
  • Concepts
    • Overview
    • Retraining models
    • Glossaries
    • Glossary support
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • TranslationService
    • REST
      • v2
        • Handling errors
        • Troubleshooting
        • Overview
        • Translation
          • Overview
          • detectLanguage
          • listLanguages
          • translate
      • v1 (DEPRECATED)
        • Overview
        • How to translate text
        • Detecting language
        • List of supported languages
        • Response format
  • Quotas and limits
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Policy before January 1, 2019
  • Questions and answers
  1. Getting started

Getting started with Translate

  • Before getting started
  • Translate text from any language

In this section, you will learn how to translate text using the Translate API. To translate a text, pass it using the translate method.

Before getting started

To use the examples, install cURL and get the authorization data for your account:

User's account on Yandex
Service accounts
Federated account
  1. On the billing page, make sure that your billing account status is ACTIVE or TRIAL_ACTIVE. If you don't have a billing account, create one.
  2. Get an IAM token required for authentication.
  3. Get the ID of any folder that your account is granted the editor role or higher for.
  1. Select the authentication method:

    • Get an IAM token used in the examples.

    • Create an API key. Pass the API key in the Authorization header in the following format:

      Authorization: Api-Key <API key>
      
  2. Assign the editor role or a higher role to the service account for the folder where it was created.

    Don't specify the folder ID in your requests: the service uses the folder where the service account was created.

  1. Authenticate with the CLI as a federated user.

  2. Use the CLI to get an IAM token required for authentication:

    $ yc iam create-token
    
  3. Get the ID of any folder that your account is granted the editor role or higher for.

Translate text from any language

This example shows how to translate the following two lines of text into Russian: Hello and World. The text language is recognized automatically.

  1. Create a file with the request body (for example, body.json).
    In folder_id, enter the folder ID. List the text strings to translate in the texts field.

    In the targetLanguageCode field, enter the target language in ISO 639-1 format. For Russian, it's ru. The language code can be obtained together with a list of supported languages.

    {
        "folder_id": "b1gvmob95yysaplct532",
        "texts": ["Hello", "World"],
        "targetLanguageCode": "ru"
    }
    
  2. To upload the file for translation, use the translate method:

    $ export IAM_TOKEN=CggaATEVAgA...
    $ curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ${IAM_TOKEN}" \
        -d '@body.json' \
        "https://translate.api.cloud.yandex.net/translate/v2/translate"
    

    The response from the service will contain translated text:

    {
        "translations": [
            {
            "text": "Привет",
            "detectedLanguageCode": "en"
            },
            {
            "text": "Мир",
            "detectedLanguageCode": "en"
            }
        ]
    }
    

What's next

  • Learn more about service concepts
  • Read our other instructions
  • Learn about API authentication methods
In this article:
  • Before getting started
  • Translate text from any language
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC