Learn R Programming

deeplr (version 1.0.0)

toGerman2: Translate texts into German using DeepL

Description

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

Usage

toGerman2(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

  • FR French

  • ES Spanish

  • 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
toGerman2("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, toGerman2)

# Customized translator applied to multiple strings (with language detection response)
txt2 <- c("Me llamo Fred.", "Je suis m<U+00E9>decin.", "I'm from Wales")
translator2 <- function(t) toGerman2(text = t, get_detect = T)
purrr::map_df(txt2, translator2)

# }
# NOT RUN {

# }

Run the code above in your browser using DataLab