Learn R Programming

deeplr (version 1.0.0)

toGerman: Translate texts into German using the official DeepL Translator API

Description

toGerman translates a text from English, French, Spanish, Italian, Dutch or Polish into German using the official DeepL Translator API. To use this service, an authentication key is required.

Usage

toGerman(text, source_lang = NULL, tag_handling = NULL,
  split_sentences = TRUE, preserve_formatting = FALSE, get_detect = FALSE,
  auth_key = "your_key")

Arguments

text

text to be translated. Only UTF8-encoded plain text is supported. May contain multiple sentences. The request size should not exceed 30kbytes.

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 source

tag_handling

if set to "xml", the translation engine tries to find matches for XML enclosed words in the translated sentence and enclose them with the same tags. If no matching words are found, the tags are removed.

split_sentences

if TRUE, the translation engine splits the input into sentences. If only one sentence is translated, it is recommended to set to FALSE to prevent the engine from unintentionally splitting the sentence.

preserve_formatting

if TRUE, the translation engine tries to preserve some aspects (e.g. punctuation at the beginning and end of the sentence, upper/lower case at the beginning of the sentence) of the formatting.

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.

auth_key

DeepL authentication key which provides access to the API.

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.

  • source_lang detected or specified language of the input text.

Details

To get an authentication key, you need to register for a DeepL Pro account (https://www.deepl.com/pro.html). This currently costs 20 euros per month and allows the translation of 1,000,000 characters per month (see https://www.deepl.com/pro-pricing.html).

References

DeepL API documentations

Examples

Run this code
# NOT RUN {
# Simple translation
toGerman("Hallo Welt!", auth_key = "my_key")

# Customized translator applied to multiple strings
txt1 <- c("My name is Albert.", "I'm a physicist.", "I was born in 1879 in Ulm.")
translator1 <- function(t) toGerman(text = t, auth_key = "x")
purrr::map_chr(txt1, translator1)

# 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) toGerman(text = t, get_detect = T, auth_key = "x")
purrr::map_df(txt2, translator2)

# }
# NOT RUN {

# }

Run the code above in your browser using DataLab