Yandex Translate API

Additional

Language
Java
Version
N/A
Created
Oct 16, 2015
Updated
Apr 30, 2022 (Retired)
Owner
Vladislav Bauer (vbauer)
Contributors
Vladislav Bauer (vbauer)
Emir Kılıç (emirkilic)
2
Activity
Badge
Generate
Download
Source code

Yandex Translate API

yandex-translate-api is a simple REST client library for Yandex.Translate. The API provides access to the Yandex online machine translation service. It supports more than 90 languages and can translate separate words or complete texts.

Online documentation: Javadoc

Prerequisites

The following actions are required to work with this library:

  • Install JDK 1.8
  • Get a free API key.

Setup

Gradle configuration:

repositories {
    maven {
        url "https://jitpack.io"
    }
}

dependencies {
    compile 'com.github.vbauer:yandex-translate-api:1.4.2'
}

Maven configuration:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.vbauer</groupId>
    <artifactId>yandex-translate-api</artifactId>
    <version>1.4.2</version>
</dependency>

Usage

FYI:

The entry point of this library is YTranslateApi interface (and the corresponding implementation YTranslateApiImpl).

def key = "<your key>"
def api = new YTranslateApiImpl(key)

Using instance of this service you can work with the following features:

  • DetectionApi detects the language of the specified text.
  • LanguageApi returns a list of translation directions supported by the service.
  • TranslationApi allows to translate text from one language to another.

DetectionApi

The following example returns Language.EN:

def language = api.detectionApi().detect("Hello, World!")

LanguageApi

To retrieve all available languages without their names, use the following code snippet:

def languages = api.languageApi().all()

It is also possible to fetch names for each language, using ui parameter:

def languages = api.languageApi().all(Language.RU)

TranslationApi

The following code should translate Russian's "Как дела?" to some English variant ("How are you doing?" or something similar):

def translation = api.translationApi().translate(
    "Как дела?", Direction.of(Language.RU, Language.EN)
)

Source language could be also detected automatically (so you need to specify only target language):

def translation = api.translationApi().translate("Как дела?", Language.EN)

Thanks to

License

MIT