
Last chance! 50% off unlimited learning
Sale ends in
translate2
translates texts between English, German, French, Spanish, Italian, Dutch and Polish
using the undocumented JSON-RPC DeepL API. No authentication key is required to use this service.
translate2(text, source_lang = NULL, target_lang = "EN",
get_detect = FALSE)
text to be translated. Must not exceed 5000 characters. Only UTF8-encoded plain text is supported. May contain multiple sentences.
language of the text to be translated (see below). If parameter is.null
, the API will try to detect
the language of the source.
language into which to translate. Can be one of the following:
EN
English
DE
German
FR
French
ES
Spanish
IT
Italian
NL
Dutch
PL
Polish
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.
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.
# NOT RUN {
# Simple translation
translate2("Hallo Welt!", target_lang = "EN")
# Customized translator applied to multiple strings
txt1 <- c("Mein Name ist Albert.", "Ich bin Physiker.", "Ich wurde 1879 in Ulm geboren.")
translator1 <- function(t) translate2(text = t, target_lang = "FR")
purrr::map_chr(txt1, translator1)
# Customized translator applied to multiple strings (with language detection response)
txt2 <- c("My name is Fred.", "Je suis m<U+00E9>decin.", "Ich komme aus der Schweiz.")
translator2 <- function(t) translate2(text = t, target_lang = "ES", get_detect = T)
purrr::map_df(txt2, translator2)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab