Skip to content

Simple util which helps to implement Yandex translation service with RxJava.

Notifications You must be signed in to change notification settings

prilaga/YandexTranslation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

Yandex Translation

Simple util which helps to implement Yandex translation service with RxJava. Example of using:

1. Dependencies

Add to build.gradle file:

dependencies {
   compile 'io.reactivex:rxjava:1.1.6'
   compile 'io.reactivex:rxandroid:1.2.1'
   }

1. Setup

    String sourceText = "Годный переводчик";
    String sourceLang = "ru";
    String destinationLang = "en";
    String key = "your_key";
    YandexTranslation translation = new YandexTranslation();

2. Get a text asynchronously:

    translation.setKey(key)
            .getTextObservable(sourceText, sourceLang, destinationLang)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<String>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(String text) {

                }
            });

3. Get a Translation object asynchronously:

       translation.setKey(key)
            .getTranslationObservable(sourceText, sourceLang, destinationLang)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<YandexTranslation.Translation>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(YandexTranslation.Translation t) {

                }
            });

4. Get a Translation in the same thread:

 Translation translation = getTranslation(sourceText, sourceLang, destinationLang);
 
  if (YandexTranslation.Translation.hasTranslation(translation)){
      String text = translation.translations.get(0);
  }

About

Simple util which helps to implement Yandex translation service with RxJava.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published