---
title: "Internationalization"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Internationalization}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)
```

```{r setup}
library(datamods)
```

When using {datamods} modules, a simple way to modify labels display is provided for using a different language or simply use other labels.
There are 4 different ways to use new labels:

```r
# Using a supported language
set_i18n("fr")

# Using a named list
set_i18n(list("Some label" = "Its translation", ...))

# Using a data.framewith 2 columns
set_i18n(data.frame(label = c(...), translation = c(...)))

# Using a CSV file
set_i18n("path/to/file.csv")
```


## Integrated languages

The following languages are integrated in {datamods} :

* ![](figures/i18n/gb.svg){height=16, style="height:16px"} english, the default.

* ![](figures/i18n/fr.svg){height=16, style="height:16px"} french, activate with:

```{r}
set_i18n("fr")
```

* ![](figures/i18n/mk.svg){height=16, style="height:16px"} macedonian, activate with:

```{r}
set_i18n("mk")
```

* ![](figures/i18n/br.svg){height=16, style="height:16px"} ![](figures/i18n/pt.svg){height=16, style="height:16px"} brazilian portuguese, activate with:

```{r}
set_i18n("pt")
```

* ![](figures/i18n/al.svg){height=16, style="height:16px"} albanian, activate with:

```{r}
set_i18n("al")
```

* ![](figures/i18n/cn.svg){height=16, style="height:16px"} chinese, activate with:

```{r}
set_i18n("cn")
```

* ![](figures/i18n/es.svg){height=16, style="height:16px"} spanish, activate with:

```{r}
set_i18n("es")
```

* ![](figures/i18n/de.svg){height=16, style="height:16px"} german, activate with:

```{r}
set_i18n("de")
```

* ![](figures/i18n/tr.svg){height=16, style="height:16px"} turkish, activate with:

```{r}
set_i18n("tr")
```

* ![](figures/i18n/kr.svg){height=16, style="height:16px"} korean, activate with:

```{r}
set_i18n("kr")
```

* ![](figures/i18n/pl.svg){height=16, style="height:16px"} polish, activate with:

```{r}
set_i18n("pl")
```

* ![](figures/i18n/ja.svg){height=16, style="height:16px"} japanese, activate with:

```{r}
set_i18n("ja")
```

If you want another language to be supported, you can submit a Pull Request to add a CSV file like the one used for french (file is located in `inst/i18n` folder in the package, you can see it [here on GitHub](https://github.com/dreamRs/datamods/blob/master/inst/i18n/fr.csv)).


## Using a list

You can change labels with a named `list`, where names correspond to the labels and values to the translation to use:

```r
options("datamods.i18n" = list(
  "Import a dataset from an environment" = "Importer un jeu de données depuis l'environnement global",
  "Select a data.frame:" = "Sélectionner un data.frame :",
  ...
))
```


## Using a data.frame

You can change labels with a `data.frame` with two columns `label` (the original label) and `translation` (the new label to display):

```r
set_i18n(data.frame(
  label = c("Import a dataset from an environment", "Select a data.frame:", ...),
  translation = c("Importer un jeu de données depuis l'environnement global", "Sélectionner un data.frame :", ...)
))
```


## Using a file

Use a CSV file with same structure than `data.frame` above:

```r
set_i18n("path/to/file.csv")
```

An example of file is shown below.


## All labels

Here's the file used for french translation with all labels used in the package:

```{r, echo=FALSE, eval=TRUE, comment=""}
cat(readLines(system.file("i18n", "fr.csv", package = "datamods"), encoding = "UTF-8"), sep = '\n')
```