Skip to content
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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions vignettes/_translation_links.R
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, adding it to .Rbuildignore causes R check to fail. It checks the vignettes to be able to be built from the tarball bundle alone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh got it. I guess that's why it must be prefixed with _ to not be "hidden", which in turn is why there's no R CMD check failure.

I am only concerned about R CMD check passing, it is fine to include it.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# build a link list of alternative languages (may be character(0))
rikivillalba marked this conversation as resolved.
Show resolved Hide resolved
.write.translation.links <- function(fmt) {
url = "https://rdatatable.gitlab.io/data.table/articles"
path = dirname(knitr::current_input(TRUE))
Copy link
Member

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)?

Copy link
Contributor Author

@rikivillalba rikivillalba Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only alternative I found (other than searching up the call stack) was litedown:::.env$input, that stores the file name (the input path to litedown::fuse()) during the execution. Tested to work building the package from . and from ..

if (basename(path) == "vignettes") {
lang = "en"
} else {
lang = basename(path)
path = dirname(path)
}
translation = dir(path,
recursive = TRUE,
pattern = glob2rx(knitr::current_input(FALSE))
)
transl_lang = ifelse(dirname(translation) == ".", "en", dirname(translation))
block = if (length(which(transl_lang != lang))) {
rikivillalba marked this conversation as resolved.
Show resolved Hide resolved
sprintf(
fmt, paste(collapse = " | ", sprintf(
"[%s](%s)",
transl_lang[transl_lang != lang],
file.path(url, sub("(?i)\\.Rmd$", ".html", translation[transl_lang != lang]))
)))
} else ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about leaving unlinked text in for the current language instead?

Available languages: fr | es

vs

Available languages: en | fr | es

knitr::asis_output(block)
}
6 changes: 3 additions & 3 deletions vignettes/datatable-benchmarking.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ h2 {
}
</style>

Translations of this document are available in

* [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")`
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly.


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

Expand Down
8 changes: 4 additions & 4 deletions vignettes/datatable-faq.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ h2 {
}
</style>

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-faq.html)

```{r, echo = FALSE, message = FALSE}
library(data.table)
knitr::opts_chunk$set(
Expand All @@ -41,6 +37,10 @@ knitr::opts_chunk$set(
.old.th = setDTthreads(1)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

The first section, Beginner FAQs, is intended to be read in order, from start to finish. It's just written in a FAQ style to be digested more easily. It isn't really the most frequently asked questions. A better measure for that is looking on Stack Overflow.

This FAQ is required reading and considered core documentation. Please do not ask questions on Stack Overflow or raise issues on GitHub until you have read it. We can all tell when you ask that you haven't read it. So if you do ask and haven't read it, don't use your real name.
Expand Down
6 changes: 3 additions & 3 deletions vignettes/datatable-importing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ h2 {
}
</style>

Translations of this document are available in

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

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.

Expand Down
8 changes: 4 additions & 4 deletions vignettes/datatable-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ vignette: >
\usepackage[utf8]{inputenc}
---

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-intro.html)

```{r, echo = FALSE, message = FALSE}
require(data.table)
knitr::opts_chunk$set(
Expand All @@ -25,6 +21,10 @@ knitr::opts_chunk$set(
.old.th = setDTthreads(1)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

This vignette introduces the `data.table` syntax, its general form, how to *subset* rows, *select and compute* on columns, and perform aggregations *by group*. Familiarity with the `data.frame` data structure from base R is useful, but not essential to follow this vignette.

***
Expand Down
4 changes: 4 additions & 0 deletions vignettes/datatable-joins.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ knitr::opts_chunk$set(
)
```

```{r, echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

In this vignette you will learn how to perform any join operation using resources available in the `data.table` syntax.

It assumes familiarity with the `data.table` syntax. If that is not the case, please read the following vignettes:
Expand Down
8 changes: 4 additions & 4 deletions vignettes/datatable-keys-fast-subset.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ vignette: >
\usepackage[utf8]{inputenc}
---

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-keys-fast-subset.html)

```{r, echo = FALSE, message = FALSE}
require(data.table)
knitr::opts_chunk$set(
Expand All @@ -24,6 +20,10 @@ knitr::opts_chunk$set(
.old.th = setDTthreads(1)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

This vignette 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, add/modify/delete columns *by reference* in `j` and group by using `by`. If you're not familiar with these concepts, please read the vignettes [`vignette("datatable-intro", package="data.table")`](datatable-intro.html) and [`vignette("datatable-reference-semantics", package="data.table")`](datatable-reference-semantics.html) first.

***
Expand Down
7 changes: 3 additions & 4 deletions vignettes/datatable-programming.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ vignette: >
\usepackage[utf8]{inputenc}
---

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-programming.html)

```{r init, include = FALSE}
require(data.table)
knitr::opts_chunk$set(
Expand All @@ -24,6 +20,9 @@ knitr::opts_chunk$set(
)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

## Introduction

Expand Down
9 changes: 5 additions & 4 deletions vignettes/datatable-reference-semantics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ vignette: >
\usepackage[utf8]{inputenc}
---

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-reference-semantics.html)

```{r, echo = FALSE, message = FALSE}
require(data.table)
knitr::opts_chunk$set(
Expand All @@ -23,6 +19,11 @@ knitr::opts_chunk$set(
collapse = TRUE)
.old.th = setDTthreads(1)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

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.

***
Expand Down
8 changes: 4 additions & 4 deletions vignettes/datatable-reshape.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ vignette: >
\usepackage[utf8]{inputenc}
---

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-reshape.html)

```{r, echo = FALSE, message = FALSE}
require(data.table)
knitr::opts_chunk$set(
Expand All @@ -24,6 +20,10 @@ knitr::opts_chunk$set(
.old.th = setDTthreads(1)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

This vignette discusses the default usage of reshaping functions `melt` (wide to long) and `dcast` (long to wide) for *data.tables* as well as the **new extended functionalities** of melting and casting on *multiple columns* available from `v1.9.6`.

***
Expand Down
8 changes: 4 additions & 4 deletions vignettes/datatable-sd-usage.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ vignette: >
}
</style>

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-sd-usage.html)

```{r, echo = FALSE, message = FALSE}
require(data.table)
knitr::opts_chunk$set(
Expand All @@ -39,6 +35,10 @@ knitr::opts_chunk$set(
.old.th = setDTthreads(1)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

This vignette will explain the most common ways to use the `.SD` variable in your `data.table` analyses. It is an adaptation of [this answer](https://stackoverflow.com/a/47406952/3576984) given on StackOverflow.

# What is `.SD`?
Expand Down
8 changes: 4 additions & 4 deletions vignettes/datatable-secondary-indices-and-auto-indexing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ vignette: >
\usepackage[utf8]{inputenc}
---

Translations of this document are available in

* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-secondary-indices-and-auto-indexing.html)

```{r, echo = FALSE, message = FALSE}
require(data.table)
knitr::opts_chunk$set(
Expand All @@ -24,6 +20,10 @@ knitr::opts_chunk$set(
.old.th = setDTthreads(1)
```

```{r echo=FALSE, file='_translation_links.R'}
```
`r .write.translation.links("Translations of this document are available in: %s")`

This vignette assumes that the reader is familiar with data.table's `[i, j, by]` syntax, and how to perform fast key based subsets. If you're not familiar with these concepts, please read the [`vignette("datatable-intro", package="data.table")`](datatable-intro.html), [`vignette("datatable-reference-semantics", package="data.table")`](datatable-reference-semantics.html), and [`vignette("datatable-keys-fast-subset", package="data.table")`](datatable-keys-fast-subset.html) vignettes first.

***
Expand Down
Loading