toPortuguese2: Translate Texts into Portuguese with the DeepL API Free

View source: R/to_lang2.R

toPortuguese2R Documentation

Translate Texts into Portuguese with the DeepL API Free

Description

toPortuguese2 translates a text from any supported source language into Portuguese using the DeepL API Free. Use available_languages2 to list all supported languages.

Usage

toPortuguese2(
  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_glossaries2 to retrieve available glossaries.

auth_key

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.

Details

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.

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: 
toPortuguese2("Hallo Welt!")

texts <- c("My name is Fred.", "Je suis médecin.", "Ich komme aus der Schweiz.")
toPortuguese2(texts, get_detect = TRUE)

## End(Not run)


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