Getting Started
View SourceThe DeepL API provides a way for programs to send texts and documents to DeepL's servers and receive high-quality translations and text improvements. This enables developers to build a wide range of translation tools using DeepL's leading translation technology.
deepl is a community-maintained Elixir package for integrating with the DeepL API.
Requirements
- Erlang:
27.0or newer - Elixir:
1.18.0-otp-27or newer
Installation
Add deepl to your mix.exs dependencies:
def deps do
[
{:deepl, "~> 0.3.0"}
]
endThen fetch dependencies:
mix deps.get
Authentication
Get your authentication key from the API Keys section of your DeepL account. Free tier allows up to 500,000 characters per month.
Set the key in your config:
# config/config.exs
config :deepl, api_key: "your-api-key"Or set it at runtime:
iex> Deepl.set_api_key("your-api-key")
:okUsage
See the API Reference for full examples. Here are some basics:
Translate text:
iex> Deepl.Translator.translate("Hello World", "ID")
{:ok,
%{
"translations" => [
%{
"detected_source_language" => "EN",
"text" => "Halo Dunia"
}
]
}}Rephrase text:
iex> Deepl.Writer.rephrase("this is a example sentence to imprve", "en-US")
{:ok,
%{
"improvements" => [
%{
"detected_source_language" => "en",
"target_language" => "en-US",
"text" => "This is a sample sentence to improve"
}
]
}}Get supported languages:
iex> Deepl.Language.get_languages()
{:ok,
[
%{"language" => "AR", "name" => "Arabic"},
%{"language" => "BG", "name" => "Bulgarian"}
]}Get usage and quota:
iex> Deepl.Usage.get()
{:ok,
%{
"character_count": 100,
"character_limit": 500000
}}License
Licensed under the MIT License.