-
Notifications
You must be signed in to change notification settings - Fork 16
Producing translated reports with csasdown
You can control the csasdown template language with the french
sub-option for each output type. For example, for Tech Reports, open index.Rmd
in your French report folder and change this:
output:
csasdown::techreport_pdf:
french: false
to this:
output:
csasdown::techreport_pdf:
french: true
In general, the simplest way we've found to get the content translated is:
- copy the contents of the .Rmd files into corresponding .docx files
- create an Excel spreadsheet with a row for each figure axis label, legend, etc. that needs to be translated but isn't directly within the .Rmd files
- have the .docx files translated; include a set of instructions (here's a template to start)
- copy the contents of your report folder with the .Rmd files to a new appropriately named folder; e.g.
report
andreport-french
- when you get back translated .docx files, paste the translated content into the .Rmd; do this file by file and render the document frequently to find any errors that translation has introduced (this cannot be overemphasized—you may even choose to work in sections of text for larger files)
- you can comment out sections in
bookdown.yml
with#
to speed up rendering and to troubleshoot any translation issues
If you are particularly adept with Git, you may choose instead to keep the French version on a separate branch.
Make sure all your table and figure-producing functions create both French and English versions based on a french
R global option. For example:
library(rosettafish)
plot_example <- function(){
french <- isTRUE(getOption("french"))
plot(1:10, 2011:2020, xlab = en2fr("year", french))
}
# English:
plot_example()
# French:
options(french = TRUE)
plot_example()
Then set the global french
option at the beginning of your French report .Rmd files.
When producing both and English and a French versions of a document, it is important to follow the language-specific formatting rules.
Item | English | French |
---|---|---|
Decimal separator | period | comma |
Long number separator | comma | space |
You can set the decimal to comma with R global option:
options(OutDec = ",")
Do this at the beginning of a French document. Note that in rare cases, this can create confusing errors if an R function is expecting decimals to be .
.
You can format the big/long numbers separator with formatC()
for one-off numbers:
x <- 123456789101112
formatC(x, format = "f", big.mark = " ", digits = 0)
#> "123 456 789 101 112"
Or within knitr kable()
tables (which is what csasdown::csas_table()
is a wrapper for) with:
x <- data.frame(col1 = rnorm(3, 1e6, 1e4))
csasdown::csas_table(x, format.args = list(decimal.mark = ',', big.mark = " "))
#> col1
#> ------------
#> 1 008 137,9
#> 988 438,3
#> 999 657,5