A simple Elixir interface to Yandex Translate's translation API
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.6"}
]
end
To sign up go here
To sign up go here
The default behaviour is to configure using the application environment:
In config/config.exs, add:
# for configuring access to cloud api
config :yandex_translator, cloud_api_key: "API_KEY"
config :yandex_translator, cloud_folder_id: "FOLDER_ID"
# for configuring access to old api
config :yandex_translator, api_key: "API_KEY"
Request for getting IAM-token for access to cloud API.
# without params
YandexTranslator.get_iam_token
# or with key
YandexTranslator.get_iam_token([key: "API_KEY"])
key - API KEY, required or optional (if presented in configuration)
Request for getting list of supported languages is #langs. For using cloud api options must contain iam_token param.
# cloud api request
YandexTranslator.langs([iam_token: ""])
# old api request
YandexTranslator.langs([])
iam_token - IAM-token, required
folder_id - folder ID of your account at Yandex.Cloud, required or optional (if presented in configuration)
key - access key, required or optional (if presented in config)
format - one of the [xml|json], default - xml, optional
ui - language code for getting language translations, optional, example - "en"
Request for detecting language of text is #detect. For using cloud api options must contain iam_token param.
# cloud api request
YandexTranslator.detect([iam_token: "", text: "Hello"])
# old api request
YandexTranslator.detect([text: "Hello"])
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"
key - access key, required or optional (if presented in config)
format - one of the [xml|json], default - xml, optional
text - text, required
hint - list of possible languages, optional, example - "en,ru"
Request for translating text is #translate. For using cloud api options must contain iam_token param.
# cloud api request
YandexTranslator.translate([iam_token: "", text: "Hello", target: "ru"])
# old api request
YandexTranslator.translate([text: "Hello", lang: "en-ru"])
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
key - access key, required or optional (if presented in config)
format - one of the [xml|json], default - xml, optional
text - text, required
lang - direction of translation, required, example - "from-to" or "to"
Bug reports and pull requests are welcome on GitHub at https://github.com/kortirso/yandex_translator.
The gem is available as open source under the terms of the MIT License.
Use this package at your own peril and risk.
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/yandex_translator.