Skip to contents

Using {aetranslations} functions

Currently there are three translators available.

  • “wmcloud”: this uses the {polyglotr} package to access wikimedia translations, it is free. You may however get blocked if you use it too much too quickly. It is the slowest option, but has the least formatting issues as it works with markdown directly.
  • “deepl”: this uses the {babeldown} package to access deepl. This is the fastest but sometimes does some weird stuff with formatting. Requiers an API key, see below.
  • “gemini”: this uses {ellmer} and {mall} to send requests to the gemini API. It is slow and not super reliable. Requires an API key, see bleow.

Both gemini and deepl require an API key. Ask Alex for this. IT IS IMPORTANT THAT WE DO NOT SHARE THIS OR POST IT ON GITHUB OR ANYWHERE ELSE.

The deepl API key can be found in our deepl account The google gemini API is access through the admin console. To set who has access go to generative AI > gemini app and turn on/off for specific org units. To specificall manage the API key go to console.cloud.google.com and select the translations project in the top left. Once you have the keys you will need to put these in your r environment file (run the below to open this)

usethis::edit_r_environ()

Then for deepl you need to copy the below two lines (and add the key) DEEPL_API_KEY = “xxxxx” DEEPL_API_URL = “https://api.deepl.com

And for gemini GEMINI_API_KEY = “xxxxx”

Save and close.

Using google gemini in positron

Another alternative is to use google gemini directly in positron (the new alternative to Rstudio).

This is actually really quick and impressive, but we arent convinced that it would not go rogue and change documents formatting or structure (and this is hard to control).

To use it, you need to first get setup with positron by installing and following the r setup instructions. Then install the extension for google gemini. Then you login with your google account. It will ask you to select a google workspace project - select translations. If this is not available to you then contact Alex.

If you are using this you should be very explicit with the prompt such as: “You are a professional technical translator. Your task is to translate the ‘content’ column in the provided data structure into”, target_lang, “.”, “RULES:”, “1. Only translate content where the ‘type’ is ‘rmd_heading’ or ‘rmd_markdown’.”, “2. If the ‘type’ is ‘rmd_chunk’ (R code), only translate the code comments, and ensure the translated comment retains the leading ‘#’ and is on the same line(s) as the original comment(s).”, “3. PRESERVATION IS CRITICAL: The ‘id’, ‘type’, and ‘original_content’ columns MUST be preserved EXACTLY as they are in the input. DO NOT alter their values.”, “4. Maintain all markdown formatting (e.g., bold, links, lists) in the translated content.”

Or if you are asking it to translate a whole document:

“You are a professional technical translator. Your task is to translate the ‘r_practical.qmd’ file in the into french and then save it to ‘r_practical.fr.qmd’ ”, “RULES:”, “1. Only translate content for headers and normal text.”, “2. In code chunks (R code), only translate the code comments, and ensure the translated comment retains the leading ‘#’ and is on the same line(s) as the original comment(s).”, “3. PRESERVATION IS CRITICAL: The document structure and organisation as well as content MUST be preserved EXACTLY as they are in the input. DO NOT alter their values.”, “4. Maintain all markdown formatting (e.g., bold, links, lists) in the translated content.”