Translate a column in a data frame
translate_df.RdThis function translates a specified column in a data frame from a source language to a target language using various translation services.
Usage
translate_df(
dataset,
column,
source_lang,
target_lang,
translator = "wmcloud",
formality = "more",
glossary = NULL
)Arguments
- dataset
A data frame containing the text to be translated.
- column
The name of the column to translate (a string).
- source_lang
The source language code (e.g., "en").
- target_lang
The target language code - only one allowed (e.g., "es", "fr").
- translator
The translation service to use. Options are "wmcloud" (default), "deepl", and "gemini". Note that "deepl" uses babelquarto and "gemini" uses mall, both of these require an API token in your environment.
- formality
If using "deepl" as translator sets how formal the grammar is - accepts arguments passed to babeldown, "more"(default) but also accepts "default", "less", "prefer_more", "prefer_less"
- glossary
If using "deepl" as translator allows to use a glossary for preset tranlsations, Specify the name in quotations of the glossary to be used, if any (defaults to NULL).
Value
The input data frame with a new column containing the translations.
The new column will be named with the value of target_lang.
Examples
if (FALSE) { # \dontrun{
df <- data.frame(english = c("Hello", "World"), french = c("Bonjour", "Monde"))
translate_df(df, "english", "en", "es")
} # }