toFrench: Translate Texts into French with the DeepL API Pro

View source: R/to_lang.R

toFrenchR Documentation

Translate Texts into French with the DeepL API Pro

Description

toFrench translates a text from any supported source language into French using the DeepL API Pro. Use available_languages to list all supported languages.

Usage

toFrench(
  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
)

Arguments

text

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.

source_lang

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.

split_sentences

Logical. If TRUE, the engine splits the input into sentences. For single-sentence inputs, consider setting to FALSE to prevent unwanted splitting.

preserve_formatting

Logical. If TRUE, formatting such as punctuation and casing is preserved.

get_detect

Logical. If TRUE, the detected language of the source text is included in the response.

context

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.

model_type

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.

formality

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.

glossary_id

Optional. Glossary ID for custom translation. Must match the language pair and requires source_lang. Use list_glossaries to retrieve available glossaries.

auth_key

A string representing the authentication key for the DeepL API Pro. 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.

Details

To use this function, you must obtain an authentication key by registering for a DeepL API Pro account at DeepL API Pro. This service may incur costs depending on the number of characters translated.

Value

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.

References

DeepL API Documentation — Translate

Examples

## Not run: 
toFrench("Hallo Welt!")

texts <- c("Me llamo Fred.", "I'm a doctor.", "Ich komme aus der Schweiz.")
toFrench(texts, get_detect = TRUE)

## End(Not run)


deeplr documentation built on June 8, 2025, 12:47 p.m.