YandexTranslator
A simple Elixir interface to Yandex Translator's translation API
Installation
If available in Hex, the package can be installed
by adding yandex_translator to your list of dependencies in mix.exs:
def deps do
[
{:yandex_translator, "~> 0.9.1"}
]
end
Getting a Subscription Key
To sign up for the free tier, do the following:
- Text Translator is here
Usage
Supported languages
Request for getting list of supported languages is #langs.
YandexTranslator.langs
key - access key, required or optional (if presented in config)
format - one of the [xml|json], default - xml
ui - language code for getting language translations, example - "en"
Responces
{:ok,
%{
"dirs" => ["az-ru", "be-bg", "be-cs", "be-de", "be-en", "be-es", "be-fr",
"be-it", "be-pl", "be-ro", "be-ru", "be-sr", "be-tr", "bg-be", "bg-ru",
"bg-uk", "ca-en", "ca-ru", "cs-be", "cs-en", "cs-ru", "cs-uk", "da-en",
"da-ru", "de-be", "de-en", "de-es", "de-fr", "de-it", "de-ru", "de-tr",
"de-uk", "el-en", "el-ru", "en-be", "en-ca", "en-cs", "en-da", "en-de",
"en-el", "en-es", "en-et", "en-fi", "en-fr", "en-hu", "en-it", "en-lt", ...]
}
}
Detection
Request for detecting language of text is #detect.
YandexTranslator.detect(text: "Hello")
key - access key, required or optional (if presented in config)
format - one of the [xml|json], default - xml
text - text, required
hint - list of possible languages, optional, example - "en,ru"
Responces
{:ok,
%{
"code" => 200,
"lang" => "en"
}
}
Translation
Request for translating text is #translate.
YandexTranslator.translate(text: "Hello", lang: "en-ru")
key - access key, required or optional (if presented in config)
format - one of the [xml|json], default - xml
text - text, required
lang - direction of translation, example - "from-to" or "to"
Responces
{:ok,
%{
"code" => 200,
"lang" => "en-ru",
"text" => ["Привет"]
}
}
Configuration
The default behaviour is to configure using the application environment:
In config/config.exs, add:
config :yandex_translator,
subscription_key: "Your-Subscription-Key"
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/kortirso/open_street_map.
License
The gem is available as open source under the terms of the MIT License.
Disclaimer
Use this package at your own peril and risk.
Documentation
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/yandex_translator.