Skip to content

Commit df59c7d

Browse files
rikivillalbaMichaelChiricoaitap
authored
Automate lang links (#6618)
* rebase from master * Update vignettes/_translation_links.R Co-authored-by: Michael Chirico <[email protected]> * Update vignettes/_translation_links.R Co-authored-by: Michael Chirico <[email protected]> * leave current language in, unlinked Co-authored-by: Ricardo Demián Villalba <[email protected]> * merge changes on .Rmd from master, add automated links * Translate "other vignette translations in..." --------- Co-authored-by: Michael Chirico <[email protected]> Co-authored-by: Ivan K <[email protected]>
1 parent f248d33 commit df59c7d

25 files changed

+110
-34
lines changed

vignettes/_translation_links.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# build a link list of alternative languages (may be character(0))
2+
# idea is to look like 'Other languages: en | fr | de'
3+
.write.translation.links <- function(fmt) {
4+
url = "https://rdatatable.gitlab.io/data.table/articles"
5+
path = dirname(knitr::current_input(TRUE))
6+
if (basename(path) == "vignettes") {
7+
lang = "en"
8+
} else {
9+
lang = basename(path)
10+
path = dirname(path)
11+
}
12+
translation = dir(path,
13+
recursive = TRUE,
14+
pattern = glob2rx(knitr::current_input(FALSE))
15+
)
16+
transl_lang = ifelse(dirname(translation) == ".", "en", dirname(translation))
17+
block = if (!all(transl_lang == lang)) {
18+
linked_transl = sprintf("[%s](%s)", transl_lang, file.path(url, sub("(?i)\\.Rmd$", ".html", translation)))
19+
linked_transl[transl_lang == lang] = lang
20+
sprintf(fmt, paste(linked_transl, collapse = " | "))
21+
} else ""
22+
knitr::asis_output(block)
23+
}

vignettes/datatable-benchmarking.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ h2 {
2525
}
2626
</style>
2727

28-
Translations of this document are available in
29-
30-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-benchmarking.html)
28+
```{r echo=FALSE, file='_translation_links.R'}
29+
```
30+
`r .write.translation.links("Translations of this document are available in: %s")`
3131

3232
This document is meant to guide on measuring performance of `data.table`. Single place to document best practices and traps to avoid.
3333

vignettes/datatable-faq.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ h2 {
2626
}
2727
</style>
2828

29-
Translations of this document are available in
30-
31-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-faq.html)
29+
```{r echo=FALSE, file='_translation_links.R'}
30+
```
31+
`r .write.translation.links("Translations of this document are available in: %s")`
3232

3333
```{r, echo = FALSE, message = FALSE}
3434
library(data.table)

vignettes/datatable-importing.Rmd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ h2 {
1515
}
1616
</style>
1717

18-
Translations of this document are available in
19-
20-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-importing.html)
21-
* [Russian](https://rdatatable.gitlab.io/data.table/articles/ru/datatable-importing.html)
18+
```{r echo=FALSE, file='_translation_links.R'}
19+
```
20+
`r .write.translation.links("Translations of this document are available in: %s")`
2221

2322
This document is focused on using `data.table` as a dependency in other R packages. If you are interested in using `data.table` C code from a non-R application, or in calling its C functions directly, jump to the [last section](#non-r-api) of this vignette.
2423

vignettes/datatable-intro.Rmd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ vignette: >
99
\usepackage[utf8]{inputenc}
1010
---
1111

12-
Translations of this document are available in
13-
14-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-intro.html)
15-
* [Russian](https://rdatatable.gitlab.io/data.table/articles/ru/datatable-intro.html)
12+
```{r echo=FALSE, file='_translation_links.R'}
13+
```
14+
`r .write.translation.links("Translations of this document are available in: %s")`
1615

1716
```{r, echo = FALSE, message = FALSE}
1817
require(data.table)

vignettes/datatable-joins.Rmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ knitr::opts_chunk$set(
2222
)
2323
```
2424

25+
```{r, echo=FALSE, file='_translation_links.R'}
26+
```
27+
`r .write.translation.links("Translations of this document are available in: %s")`
28+
2529
In this vignette you will learn how to perform any join operation using resources available in the `data.table` syntax.
2630

2731
It assumes familiarity with the `data.table` syntax. If that is not the case, please read the following vignettes:

vignettes/datatable-keys-fast-subset.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ vignette: >
99
\usepackage[utf8]{inputenc}
1010
---
1111

12-
Translations of this document are available in
13-
14-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-keys-fast-subset.html)
12+
```{r echo=FALSE, file='_translation_links.R'}
13+
```
14+
`r .write.translation.links("Translations of this document are available in: %s")`
1515

1616
```{r, echo = FALSE, message = FALSE}
1717
require(data.table)

vignettes/datatable-programming.Rmd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ vignette: >
99
\usepackage[utf8]{inputenc}
1010
---
1111

12-
Translations of this document are available in
13-
14-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-programming.html)
12+
```{r echo=FALSE, file='_translation_links.R'}
13+
```
14+
`r .write.translation.links("Translations of this document are available in: %s")`
1515

1616
```{r init, include = FALSE}
1717
require(data.table)
@@ -24,7 +24,6 @@ knitr::opts_chunk$set(
2424
)
2525
```
2626

27-
2827
## Introduction
2928

3029
`data.table`, from its very first releases, enabled the usage of `subset` and `with` (or `within`) functions by defining the `[.data.table` method. `subset` and `with` are base R functions that are useful for reducing repetition in code, enhancing readability, and reducing number the total characters the user has to type. This functionality is possible in R because of a quite unique feature called *lazy evaluation*. This feature allows a function to catch its arguments, before they are evaluated, and to evaluate them in a different scope than the one in which they were called. Let's recap usage of the `subset` function.

vignettes/datatable-reference-semantics.Rmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ vignette: >
99
\usepackage[utf8]{inputenc}
1010
---
1111

12-
Translations of this document are available in
13-
14-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-reference-semantics.html)
12+
```{r echo=FALSE, file='_translation_links.R'}
13+
```
14+
`r .write.translation.links("Translations of this document are available in: %s")`
1515

1616
```{r, echo = FALSE, message = FALSE}
1717
require(data.table)
@@ -23,6 +23,7 @@ knitr::opts_chunk$set(
2323
collapse = TRUE)
2424
.old.th = setDTthreads(1)
2525
```
26+
2627
This vignette discusses *data.table*'s reference semantics which allows to *add/update/delete* columns of a *data.table by reference*, and also combine them with `i` and `by`. It is aimed at those who are already familiar with *data.table* syntax, its general form, how to subset rows in `i`, select and compute on columns, and perform aggregations by group. If you're not familiar with these concepts, please read the [`vignette("datatable-intro", package="data.table")`](datatable-intro.html) vignette first.
2728

2829
***

vignettes/datatable-reshape.Rmd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ vignette: >
99
\usepackage[utf8]{inputenc}
1010
---
1111

12-
Translations of this document are available in
13-
14-
* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-reshape.html)
15-
* [Russian](https://rdatatable.gitlab.io/data.table/articles/ru/datatable-reshape.html)
12+
```{r echo=FALSE, file='_translation_links.R'}
13+
```
14+
`r .write.translation.links("Translations of this document are available in: %s")`
1615

1716
```{r, echo = FALSE, message = FALSE}
1817
require(data.table)

0 commit comments

Comments
 (0)