Simple mechanism to translate labels in a Shiny application.
Usage
i18n(x, translations = i18n_translations())
i18n_translations(package = packageName(parent.frame(2)))
set_i18n(value, packages = c("datamods", "esquisse"))Arguments
- x
Label to translate.
- translations
Either a
listor adata.framewith translations.- package
Name of the package where the function is called, use
NULLoutside a package. It will retrieve option"i18n.<PACKAGE>"(or"i18n"if no package) to returns appropriate labels.- value
Value to set for translation. Can be:
single
characterto use a supported language ("fr","mk","al","pt"for esquisse and datamods packages).a
listwith labels as names and translations as values.a
data.framewith 2 column:label&translation.path to a CSV file with same structure as for
data.frameabove.
- packages
Name of packages for which to set i18n, default to esquisse and datamods
Examples
library(datamods)
# Use with an objet
my.translations <- list(
"Hello" = "Bonjour"
)
i18n("Hello", my.translations)
#> [1] "Bonjour"
# Use with options()
options("i18n" = list(
"Hello" = "Bonjour"
))
i18n("Hello")
#> [1] "Bonjour"
# With a package
options("datamods.i18n" = "fr")
i18n("Browse...", translations = i18n_translations("datamods"))
#> [1] "Parcourir..."
# If you call i18n() from within a function of your package
# you don't need second argument, e.g.:
# i18n("Browse...")