toEnglish2
translates a text from any supported source language into English using the DeepL API Free.
Use available_languages2
to list all supported languages.
toEnglish2(
text,
source_lang = NULL,
split_sentences = TRUE,
preserve_formatting = FALSE,
get_detect = FALSE,
context = NULL,
model_type = NULL,
formality = NULL,
glossary_id = NULL,
auth_key
)
A character vector containing the text(s) to be translated. Only UTF-8 encoded plain text is supported. Each element may contain multiple sentences but should not exceed 30 kB.
A string specifying the source language. If NULL
, the API will auto-detect the language.
If of length 1, the same source language is applied to all elements.
Logical. If TRUE
, the engine splits the input into sentences.
For single-sentence inputs, consider setting to FALSE
to prevent unwanted splitting.
Logical. If TRUE
, formatting such as punctuation and casing is preserved.
Logical. If TRUE
, the detected language of the source text is included in the response.
Optional string providing contextual information to improve translation quality, especially for short or ambiguous text. 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 language pairs).
"prefer_quality_optimized"
– Use quality-optimized when available, otherwise fallback.
Optional. Controls formality level of the translation (only 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 custom translation. Must match the language pair and requires source_lang
.
Use list_glossaries2
to retrieve available glossaries.
A string representing the authentication key for the DeepL API Free.
If not provided, the function will attempt to retrieve the key from the environment
variable DEEPL_API_KEY
. You can set this variable using
Sys.setenv(DEEPL_API_KEY = "your_key")
or define it in your .Renviron
file for persistent use.
If get_detect = FALSE
, a character vector with translations is returned.
If get_detect = TRUE
, a tibble with the following columns is returned:
translation
: The translated text.
source_lang
: The detected or specified source language.
To use this function, you must obtain an authentication key by registering for a DeepL API Free account at DeepL API Free. With the Free API, up to 500,000 characters per month can be translated at no cost.
if (FALSE) { # \dontrun{
toEnglish2("Hallo Welt!")
texts <- c("Me llamo Fred.", "Je suis médecin.", "Ich komme aus der Schweiz.")
toEnglish2(texts, get_detect = TRUE)
} # }