gleepl
Types
pub type TranslationRequest {
TranslationRequest(
auth_key: Option(String),
endpoint: Option(endpoints.Endpoint),
from: Option(Language),
to: Option(Language),
text: Option(String),
)
}
Constructors
-
TranslationRequest( auth_key: Option(String), endpoint: Option(endpoints.Endpoint), from: Option(Language), to: Option(Language), text: Option(String), )
Functions
pub fn set_auth_key(
request: TranslationRequest,
auth_key: String,
) -> TranslationRequest
Sets the auth key for the request
Example
gleepl.new()
|> gleepl.set_auth_key("<your-auth-key>")
pub fn set_endpoint(
request: TranslationRequest,
endpoint: Endpoint,
) -> TranslationRequest
Sets the endpoint for the request as deepl offers both free and paid endpoints. Defaults to free if not set.
Examples
import gleepl/endpoints
gleepl.new()
|> gleepl.set_endpoint(endpoints.free)
import gleepl/endpoints
gleepl.new()
|> gleepl.set_endpoint(endpoints.paid)
pub fn set_from(
request: TranslationRequest,
language: Language,
) -> TranslationRequest
Sets the language to translate from (deepl source language)
Examples
import gleepl/langs
gleepl.new()
|> gleepl.set_from(langs.english)
import gleepl/langs
gleepl.new()
|> gleepl.set_from(langs.from_iso("es"))
pub fn set_text(
request: TranslationRequest,
text: String,
) -> TranslationRequest
Sets the text to translate
Example
gleepl.new()
|> gleepl.set_text("hello, friend!")
pub fn set_to(
request: TranslationRequest,
language: Language,
) -> TranslationRequest
Sets the language to translate to (deepl target language)
Examples
import gleepl/langs
gleepl.new()
|> gleepl.set_to(langs.french)
import gleepl/langs
gleepl.new()
|> gleepl.set_to(langs.from_iso("es"))
pub fn translate(
request: TranslationRequest,
) -> Result(String, Dynamic)
Executes the request and returns the translated text
Example
import gleepl/endpoints
import gleepl/langs
gleepl.new()
|> gleepl.set_auth_key("<your-auth-key>")
|> gleepl.set_endpoint(endpoints.free)
|> gleepl.set_from(langs.english)
|> gleepl.set_to(langs.french)
|> gleepl.set_text("hello, friend!")
|> gleepl.translate
// -> Ok("Bonjour, mon ami !")