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.

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:

codelanguage
arArabic
caCatalan
daDanish
deGerman
enEnglish
esSpanish
frFrench
heHebrew
hiHindi
itItalian
ptPortuguese
pt_BRPortuguese (Brazil)
ruRussian
svSwedish
zh_CNChinese

Default fallbacks

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

original languagefallback language
espt
ptes
frpt
denl
nlde

Examples

i_("hello", lang = "de")
#> locale directory does not exists, using default translations
#> [1] "Hallo"
i_(c("hello", "world"), lang = "es")
#> locale directory does not exists, using default translations
#> [1] "hola" "mundo"
i_(list(id = "hello", translate = "world"), lang = "pt", keys = "translate")
#> locale directory does not exists, using default translations
#> $id #> [1] "hello" #> #> $translate #> [1] "mundo" #>
if (FALSE) { ui <- fluidPage( useShi18ny(), langSelectorInput("lang", position = "fixed"), ) }