Translate a Quarto/R Markdown document
translate_doc.RdParses a .qmd or .Rmd file, translates specified elements (headings, text, code comments), and reconstructs the document with the translations.
Usage
translate_doc(
source_path = "pages/r_practical.qmd",
target_path = "pages/test.qmd",
source_lang = "en",
target_lang = "fr",
translator = "wmcloud",
include_headings = TRUE,
include_text = TRUE,
include_comments = TRUE
)Arguments
- source_path
Path to the source .qmd or .Rmd file.
- target_path
Path to write the translated .qmd or .Rmd file.
- source_lang
The source language code (e.g., "en").
- target_lang
The target language code (e.g., "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.
- include_headings
Logical, whether to translate headings (default TRUE).
- include_text
Logical, whether to translate markdown text (default TRUE).
- include_comments
Logical, whether to translate R code comments (default TRUE).
Value
This function does not return an object but writes the translated
document to the target_path.
Examples
if (FALSE) { # \dontrun{
# create a dummy file
qmd_content <- c("---", "title: 'My Doc'", "---", "", "# Header", "", "Some text.")
writeLines(qmd_content, "test.qmd")
translate_doc("test.qmd", "test_fr.qmd", "en", "fr")
} # }