-
Notifications
You must be signed in to change notification settings - Fork 986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automate lang links #6618
base: master
Are you sure you want to change the base?
Automate lang links #6618
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6618 +/- ##
=======================================
Coverage 98.60% 98.60%
=======================================
Files 79 79
Lines 14518 14518
=======================================
Hits 14316 14316
Misses 202 202 ☔ View full report in Codecov by Sentry. |
vignettes/.translation_links.R
Outdated
block = sprintf( | ||
"%s: %s\n", | ||
switch(lang, | ||
fr = "Des traductions de ce document sont disponibles dans les langues suivantes", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method for defining translations is non-standard. I think this would be better as gettext(...)
or to simplify, just use English. Only list the other languages at the top of the English vignette. and then the other vignettes can just link back to English.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think in gettext however I don't figure out how to get the string for the appropriate language to compile the vignettes in all languages, other than set Sys.setLanguage()
in each call.
Another option is to hardcode the header and let the code generate only the links.
But I think your second option is ok.
fa2522b
to
7c661b4
Compare
I made the following changes:
_translation_links.R must be bundled in the package so r CMD check can build the vignettes. However that source is 'knitted' and present in each .R file generated from .Rmd and installed in doc. French vignettes are no modified at all. An equivalent to "from English original vignette" message linking back to english might be added to translated vignettes, or code similar to that of the english ones, it is up to the owner to decide. In the script case it will add all available links excluding that of the current vignette language determined from the folder name. As part of spanish translators there is work in progres in https://github.com/cienciadedatos/traduccion-vignettes-datatable |
# build a link list of alternative languages (may be character(0)) | ||
.write.translation.links <- function(fmt) { | ||
url = "https://rdatatable.gitlab.io/data.table/articles" | ||
path = dirname(knitr::current_input(TRUE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a litedown equivalent (#6583)?
pattern = glob2rx(knitr::current_input(FALSE)) | ||
) | ||
transl_lang = ifelse(dirname(translation) == ".", "en", dirname(translation)) | ||
block = if (length(which(transl_lang != lang))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block = if (length(which(transl_lang != lang))) { | |
block = if (!all(transl_lang == lang)) { |
@@ -0,0 +1,25 @@ | |||
# build a link list of alternative languages (may be character(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# build a link list of alternative languages (may be character(0)) | |
# build a link list of alternative languages (may be character(0)) | |
# idea is to look like 'Other languages: en | fr | de' |
Just commenting on expected output to facilitate reading/future refactoring
transl_lang[transl_lang != lang], | ||
file.path(url, sub("(?i)\\.Rmd$", ".html", translation[transl_lang != lang])) | ||
))) | ||
} else "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-benchmarking.html) | ||
```{r echo=FALSE, file='_translation_links.R'} | ||
``` | ||
`r .write.translation.links("Translations of this document are available in: %s")` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC the idea is the translation team will just translate this string themselves directly in the .Rmd file, is that right? (seems fine, just want to confirm my understanding)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also have this helper script, let's keep a consistent naming style (personally, I like your snake case style here):
https://github.com/Rdatatable/data.table/blob/master/vignettes/.check.translations.R
Also note that this should probably be added to .Rbuildignore
? Maybe just ignore all vignettes/_.*
files?
In response to #6613
This is my proposal to automate link generation:
Note that currently, in documents with a TOC (datatable-faq.Rmd) the link list is below the toc in the packaged vignettes. That is unchanged as the TOC is built automatically by commonmark.
Also, #6394 should be considered.