The goal of translated is to serve as a minimal demonstration of a package with multilingual documentation.
You can install the development version of translated from GitHub with:
# install.packages("remotes")
remotes::install_github("eliocamp/translated")
The package has just one dummy function, translate_me(), which has
documentation in English and Spanish.
library(translated)
Type ?translate_me in the console for the default (English)
documentation.
Type es?translate_me for the Spanish documentation.
Each function is documented normally with one .Rd per language. The .Rd
for the default language is documented as usual, but the others have
\alias{function-lang} and \keyword{internal}. The former makes it so
that lang?function opens up the correct page (TODO: understand why)
and the latter to hide the translation in the help index.
The idea is to document functions normally using roxygen2 in the default language and add a translation roclet that handles everything else.
This roclet would search for a .yaml file for each documented object
which would hold the translated strings. Each section has its own yaml
field with the original text, the translated text and a
needs_update field to indicate if the original string was changed and
the translation needs to be updated. For example:
title:
original: Title of documentation
translated: 'Título de la documentación'
needs_update: no
The roclet would then create a new .Rd file for each of these files.
If the yaml file doesn’t exist (e.g. it’s a new function that doesn’t
have any translation), the roclet would create the yaml with empty
translated strings.
If the string in the original documentation is different from the string
in the original field, then the roclet would update the field and the
needs_update field.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.