Skip to contents

This 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")

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.

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")
} # }