huymluu/yandex-translate-api


JAVA wrapper for Yandex translate api (https://tech.yandex.com/translate)

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

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

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.huymluu:yandex-translate-api:'
	}
	dependencies {
		implementation("com.github.huymluu:yandex-translate-api:")
	}
	<dependency>
	    <groupId>com.github.huymluu</groupId>
	    <artifactId>yandex-translate-api</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.huymluu" % "yandex-translate-api" % ""
        
        

                            
    :dependencies [[com.github.huymluu/yandex-translate-api ""]]
        
        

Readme


Yandex Translate API usage

Register API key

Get free API key at https://tech.yandex.com/translate/

Initialization

YandexTranslator yandexTranslator = new YandexTranslator("YOUR YANDEX API KEY");

Get supported languages

List<Language> supportedLanguages = yandexTranslator.getSupportedLanguages();

Translate

// Translate single term - explicit 'from' & 'to' languages
String translated = yandexTranslator.translate("Hello world", Language.ENGLISH, Language.GERMAN);

// Translate single term - auto detect 'from' language
String translated = yandexTranslator.translate("Hello world", Language.GERMAN);

// Translate list of terms
List<String> input = new ArrayList<String>();
input.add("Hello");
input.add("World");
List<String> translated = yandexTranslator.translate(input, Language.GERMAN);

Detect language

// Auto detect best language
Language detectedLanguage = yandexTranslator.detectLanguage("Hello world");

// Detect best language with hint
Language detectedLanguage = yandexTranslator.detectLanguage("Hallo", Language.GERMAN);

// Detect best language with multiple hint
Language detectedLanguage = yandexTranslator.detectLanguage("Hallo", Language.ENGLISH, Language.GERMAN);

Yandex Dictionary API usage

Register API key

Get free API key at https://tech.yandex.com/dictionary/

Initialization

YandexDictionary yandexDictionary = new YandexDictionary("YOUR YANDEX API KEY");

Get supported lookup directions

Map<Language, List<Language>> directions = yandexDictionary.getSupportedTranslateDirections();

Lookup

// Simple lookup
List<Definition> definitions = yandexDictionary.lookup("time", Language.ENGLISH, Language.GERMAN);

// Lookup with flags (not sure what it means, read https://tech.yandex.com/dictionary/doc/dg/reference/lookup-docpage/)
List<Definition> definitions = yandexDictionary.lookup("time", Language.ENGLISH, Language.GERMAN, LookupFlag.FAMILY, LookupFlag.MORPHO, LookupFlag.POS_FILTER);

TODO

  • Support XML (no need, just JSON is enough)
  • Support more request params: options, ui