Translates UTF-8 encoded plain text between supported languages using the DeepL API Free. A list of supported source and target languages is available at https://developers.deepl.com/docs/getting-started/supported-languages. An authentication key is required. The Free plan allows up to 500,000 characters per month.
translate2(
text,
target_lang = "EN",
source_lang = NULL,
split_sentences = TRUE,
preserve_formatting = FALSE,
get_detect = FALSE,
context = NULL,
model_type = NULL,
formality = NULL,
glossary_id = NULL,
auth_key
)
Character vector. The text(s) to translate. Each element can contain multiple sentences but must not exceed 30 kB. Only UTF-8 plain text is supported.
Character vector. Target language(s) for translation. If length 1, all texts are translated into the same language.
Character vector or NULL
. Source language(s). If NULL
, the language
is auto-detected. If of length 1, it is applied to all texts.
Logical. If TRUE
(default), DeepL splits input into sentences before
translating. Set to FALSE
to avoid unintended splits in short texts.
Logical. If TRUE
, preserves some text formatting (e.g., punctuation and capitalization).
Logical. If TRUE
, returns a tibble including detected source languages along
with translations.
Optional. Contextual text to improve translation quality, especially for short or ambiguous inputs. Context is not translated and does not count toward character limits.
Optional. Specifies the DeepL model to use:
"latency_optimized"
– Default low-latency model.
"quality_optimized"
– Higher-quality, higher-latency model (Pro only, limited languages).
"prefer_quality_optimized"
– Uses quality-optimized when available; otherwise falls back.
Optional. Controls the formality level of the translation (only supported for certain target languages):
"default"
– Neutral.
"more"
– More formal.
"less"
– More informal.
"prefer_more"
– Prefer formal, fallback to default.
"prefer_less"
– Prefer informal, fallback to default.
Optional. Glossary ID for translation. Must match the language pair and requires source_lang
.
Use list_glossaries2
to retrieve IDs.
Character. Your DeepL API authentication key. If missing, the function uses
the DEEPL_API_KEY
environment variable. You can set it using
Sys.setenv(DEEPL_API_KEY = "your_key")
or in your .Renviron
file.
If get_detect = FALSE
, returns a character vector of translated texts.
If get_detect = TRUE
, returns a tibble with:
translation
– Translated text.
source_lang
– Detected or provided source language.
Register for a free DeepL API key at https://www.deepl.com/pro#developer.
Only texts passed via the text
argument count toward your monthly character quota.
if (FALSE) { # \dontrun{
translate2("I like to translate texts.", target_lang = "DE")
translate2(
c("I like to translate texts.", "Ich übersetze gerne Texte."),
target_lang = "FR"
)
translate2("I like to translate texts.", target_lang = c("FR", "DE", "IT"))
translate2(
c("I like to translate texts.", "Ich übersetze gerne Texte."),
target_lang = c("FR", "IT")
)
} # }