Internationalization

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)
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:

# 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} :

set_i18n("fr")
set_i18n("mk")
set_i18n("pt")
set_i18n("al")
set_i18n("cn")
set_i18n("es")
set_i18n("de")
set_i18n("tr")
set_i18n("kr")
set_i18n("pl")
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).

Using a list

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

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

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:

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:

cat(readLines(system.file("i18n", "fr.csv", package = "datamods"), encoding = "UTF-8"), sep = '\n')


Try the datamods package in your browser

Any scripts or data that you put into this service are public.

datamods documentation built on Sept. 26, 2023, 5:07 p.m.