i18n: Translate text

Description Usage Arguments Value Available languages Default fallbacks Examples

Description

Translate strings, vectors or lists in the Server of a Shiny app. There are currently 15 languages available for translation (see Available languages below). Note that the i_ function should be used within the Server of the app and the ui_ function should be used in the UI.

Usage

1
2
3
i_(str, lang = NULL, i18n = NULL, markdown = FALSE, keys = c("name", "label"))

ui_(string, lang = NULL)

Arguments

str

A string, vector or list to be translated.

lang

Code for the language that the original language should be translated into.

i18n

List of language configurations, can only be set for i_. Options that can be set are:

defaultLang Default language used in Shiny app; default = "en"

availableLangs Language that can be chosen for translation in Shiny app; there are currently 15 Available languages (see below); defaults to all.

localeDir Directory to yaml or csv file(s) which contain custom keyword translations; default = "locale"

fallbacks List of fallback languages if translation for a word is not found in desired language; defaults to Default fallbacks (see below)

queryParameter String to define query parameter if language to be set through URL; default = "lang"

customTranslationSource String to change the type of source for custom translations. Options: "yaml" and "csv"; default = "yaml". If "csv" there needs to be a "translations.csv" in the localeDir with an "id" column and columns for languages (e.g. "en", "es", ...)

markdown

Transform markdown text to HTML, can only be set for i_; default = FALSE

keys

If str is a list this is a string (or a vector of strings) specifying which key(s) of the list to translate; can only be set for i_.

Value

Translation of input text in the same format as the input.

Available languages

There are currently 15 languages available for translation:

code language
ar Arabic
ca Catalan
da Danish
de German
en English
es Spanish
fr French
he Hebrew
hi Hindi
it Italian
pt Portuguese
pt_BR Portuguese (Brazil)
ru Russian
sv Swedish
zh_CN Chinese

Default fallbacks

If no fallback languages are specified, translations automatically fall back onto the following languages.

original language fallback language
es pt
pt es
fr pt
de nl
nl de

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
i_("hello", lang = "de")

i_(c("hello", "world"), lang = "es")

i_(list(id = "hello", translate = "world"), lang = "pt", keys = "translate")

## Not run: 
ui <- fluidPage(
useShi18ny(),
langSelectorInput("lang", position = "fixed"),
)

## End(Not run)

jpmarindiaz/shi18ny documentation built on March 31, 2021, 5:15 p.m.