Translator R6 Class
Translator R6 Class
Details
This creates shinny.i18n Translator object used for translations.
Now you can surround the pieces of the text you want to translate by
one of the translate statements (ex.: Translator$t("translate me")
).
Find details in method descriptions below.
Methods
Method new()
Initialize the Translator with data
Usage
Translator$new(
translation_csvs_path = NULL,
translation_json_path = NULL,
translation_csv_config = NULL,
separator_csv = ",",
automatic = FALSE
)
Arguments
translation_csvs_path
character with path to folder containing csv translation files. Files must have "translation_" prefix, for example:
translation_<LANG-CODE>.csv
.translation_json_path
character with path to JSON translation file. See more in Details.
translation_csv_config
character with path to configuration file for csv option.
separator_csv
separator of CSV values (default ",")
automatic
logical flag, indicating if i18n should use an automatic translation API.
Method translate()
Translates 'keyword' to language specified by 'set_translation_language'
Usage
Translator$translate(keyword, session = shiny::getDefaultReactiveDomain())
Method t()
Wrapper to translate
method.
Usage
Translator$t(keyword, session = shiny::getDefaultReactiveDomain())
Method set_translation_language()
Specify language of translation. It must exist in 'languages' field.
Method automatic_translate()
Translates 'keyword' to language specified by 'set_translation_language' using cloud service 'api'. You need to set API settings first.
Examples
if (FALSE) {
i18n <- Translator$new(translation_json_path = "translation.json") # translation file
i18n$set_translation_language("it")
i18n$t("This text will be translated to Italian")
}
# Shiny example
if (interactive()) {
library(shiny)
library(shiny.i18n)
#to run this example make sure that you have a translation file
#in the same path
i18n <- Translator$new(translation_json_path = "examples/data/translation.json")
i18n$set_translation_language("pl")
ui <- fluidPage(
h2(i18n$t("Hello Shiny!"))
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
}