Deepl.Text (deepl v0.1.2)

View Source

Module for translating text using the DeepL API.

Summary

Functions

Translates a single or multiple texts to the specified target language.

Translates a single or multiple texts to the specified target language.

Types

text()

(since 0.1.0)
@type text() :: binary() | [binary()]

Functions

translate(text, target_lang, opts \\ [])

(since 0.1.0)
@spec translate(text(), binary(), Keyword.t()) :: {:ok, map()} | {:error, String.t()}

Translates a single or multiple texts to the specified target language.

The text parameter can be a single string or a list of strings.

Examples

iex> Deepl.Text.translate("Hello World", "ID")
%{
  "translations" => [
    %{"detected_source_language" => "EN", "text" => "Halo Dunia"}
  ]
}}

iex> Deepl.Text.translate(["Hello World", "Hello Developer"], "ID")
{:ok,
%{
  "translations" => [
    %{"detected_source_language" => "EN", "text" => "Halo Dunia"},
    %{"detected_source_language" => "EN", "text" => "Halo Pengembang"}
  ]
}}

iex> Deepl.Text.translate("Hello World", "ID", show_billed_characters: true)
{:ok,
%{
  "translations" => [
    %{
      "billed_characters" => 11,
      "detected_source_language" => "EN",
      "text" => "Halo Dunia"
    }
  ]
}}

translate!(text, target_lang, opts \\ [])

(since 0.1.0)
@spec translate!(text(), binary(), Keyword.t()) :: map() | Exception.t()

Translates a single or multiple texts to the specified target language.

This function like translate/3, but raises an error if the translation fails.