yandex_translator v0.9.3 YandexTranslator View Source

Elixir client for Yandex.Translate API

Configuration (new API)

An API key and folder id can be set in your application’s config. For getting api key and folder is check readme.

config :yandex_translator, cloud_api_key: "API_KEY"
config :yandex_translator, cloud_folder_id: "FOLDER_ID"

Configuration (old API)

An API key can be set in your application’s config. For getting api key check readme.

config :yandex_translator, api_key: "API_KEY"

Link to this section Summary

Functions

Detect language for text For using cloud api options must contain iam_token param

Get IAM-token for using it in requests to Yandex.Cloud Valid 12 hours

Get IAM-token for using it in requests to Yandex.Cloud Valid 12 hours

Get available languages for translation

Get available languages for translation For using cloud api options must contain iam_token param

Translate word or phrase For using cloud api options must contain iam_token param

Link to this section Functions

Link to this function detect(options) View Source
detect(keyword()) :: {:ok, %{}}

Detect language for text For using cloud api options must contain iam_token param.

Example (cloud API)

iex> YandexTranslator.detect([iam_token: "", text: "Hello"])
{:ok, %{"language" => "en"}}

Options (cloud API)

iam_token - IAM-token, required
folder_id - folder ID of your account at Yandex.Cloud, required or optional (if presented in configuration)
text - text for detection, required
hint - list of possible languages, optional, example - "en,ru"

Example (old API)

iex> YandexTranslator.detect([text: "Hello", format: "json"])
{:ok, %{"code" => 200, "lang" => "en"}}

Options (old API)

key - API KEY, required or optional (if presented in config)
format - one of the [xml|json], optional, default - xml
text - text for detection, required
hint - list of possible languages, optional, example - "en,ru"
Link to this function get_iam_token() View Source
get_iam_token() :: {:ok, %{iamToken: String.t()}}

Get IAM-token for using it in requests to Yandex.Cloud Valid 12 hours.

Example

iex> YandexTranslator.get_iam_token
{:ok, %{"iamToken" => ""}}
Link to this function get_iam_token(options) View Source
get_iam_token(keyword()) :: {:ok, %{iamToken: String.t()}}

Get IAM-token for using it in requests to Yandex.Cloud Valid 12 hours.

Example

iex> YandexTranslator.get_iam_token([])
{:ok, %{"iamToken" => ""}}

Options

key - API KEY, required or optional (if presented in configuration)
Link to this function langs() View Source
langs() :: {:ok, %{}}

Get available languages for translation

Example

iex> YandexTranslator.langs
Link to this function langs(options) View Source
langs(keyword()) :: {:ok, %{}}

Get available languages for translation For using cloud api options must contain iam_token param.

Example (cloud API)

iex> YandexTranslator.langs([iam_token: ""])
{:ok, %{"languages" => [%{"language" => "az"}, %{...}, ...]}}

Options (cloud API)

iam_token - IAM-token, required
folder_id - folder ID of your account at Yandex.Cloud, required or optional (if presented in configuration)

Example (old API)

iex> YandexTranslator.langs([format: "json"])
{:ok, %{"dirs" => ["az-ru", ...]}}

Options (old API)

key - API KEY, required or optional (if presented in configuration)
format - one of the [xml|json], optional, default - xml
ui - language code for getting language translations, optional, example - "en"
Link to this function translate(options) View Source
translate(keyword()) :: {:ok, %{}}

Translate word or phrase For using cloud api options must contain iam_token param.

Example (cloud API)

iex> YandexTranslator.translate([iam_token: iam_token, text: "hello world", source: "en", target: "es"])
{:ok, %{"translations" => [%{"text" => "hola mundo"}]}}

Options (cloud API)

iam_token - IAM-token, required
folder_id - folder ID of your account at Yandex.Cloud, required or optional (if presented in configuration)
text - text for detection, required
source - source language, ISO 639-1 format (like "en"), optional
target - target language, ISO 639-1 format (like "ru"), required
format - text format, one of the [plain|html], default - plain, optional

Example (old API)

iex> YandexTranslator.translate([format: "json", text: "Hello", lang: "en-es"])
{:ok, %{"code" => 200, "lang" => "en-es", "text" => ["Hola"]}}

Options (old API)

key - API KEY, required or optional (if presented in config)
format - one of the [xml|json], optional, default - xml
text - text, required
lang - direction of translation, optional, example - "from-to" or "to"