Learn R Programming

deeplr (version 1.0.0)

toSpanish2: Translate texts into Spanish using DeepL

Description

toSpanish2 ranslates a text from English, German, French, Italian, Dutch or Polish into Spanish using the undocumented JSON-RPC DeepL API. No authentication key is required to use this service.

Usage

toSpanish2(text, source_lang = NULL, get_detect = FALSE)

Arguments

text

text to be translated. Must not exceed 5000 characters. Only UTF8-encoded plain text is supported. May contain multiple sentences.

source_lang

language of the text to be translated. Can be one of the following:

  • EN English

  • DE German

  • FR French

  • IT Italian

  • NL Dutch

  • PL Polish

If parameter is.null, the API will try to detect the language of the text.

get_detect

if TRUE, the language detected for the source text is also inclued in the response. It corresponds to the value of the argument source_lang if it was specified. If FALSE, only the translated text is returned.

Value

If get_detect is set to FALSE a character vector containing the translation is returned. Otherwise, a data.frame (tibble::tibble) is returned with the following columns:

  • translation the translated text(s).

  • source_lang detected or specified language of the input text.

Examples

Run this code
# NOT RUN {
# Simple translation
toSpanish2("Hallo Welt!")

# Customized translator applied to multiple strings
txt1 <- c("My name is Albert.", "I'm a physicist.", "I was born in 1879 in Ulm.")
purrr::map_chr(txt1, toSpanish2)

# Customized translator applied to multiple strings (with language detection response)
txt2 <- c("Je m'appelle Jean.", "Ich bin Arzt.", "I'm from Wales")
translator2 <- function(t) toSpanish2(text = t, get_detect = T)
purrr::map_df(txt2, translator2)

# }
# NOT RUN {

# }

Run the code above in your browser using DataLab