Translator | R Documentation |
Translator R6 Class
Translator R6 Class
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.
new()
Initialize the Translator with data
Translator$new( translation_csvs_path = NULL, translation_json_path = NULL, translation_csv_config = NULL, separator_csv = ",", automatic = FALSE )
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.
get_languages()
Get all available languages
Translator$get_languages()
get_translations()
Get whole translation matrix
Translator$get_translations()
get_key_translation()
Get active key translation
Translator$get_key_translation()
get_translation_language()
Get current target translation language
Translator$get_translation_language()
translate()
Translates 'keyword' to language specified by 'set_translation_language'
Translator$translate(keyword, session = shiny::getDefaultReactiveDomain())
keyword
character or vector of characters with a word or expression to translate
session
Shiny server session (default: current reactive domain)
t()
Wrapper to translate
method.
Translator$t(keyword, session = shiny::getDefaultReactiveDomain())
keyword
character or vector of characters with a word or expression to translate
session
Shiny server session (default: current reactive domain)
set_translation_language()
Specify language of translation. It must exist in 'languages' field.
Translator$set_translation_language(transl_language)
transl_language
character with a translation language code
parse_date()
Parse date to format described in 'cultural_date_format' field in config.
Translator$parse_date(date)
date
date object to format
parse_number()
Numbers parser. Not implemented yet.
Translator$parse_number(number)
number
numeric or character with number
character with number formatting
automatic_translate()
Translates 'keyword' to language specified by 'set_translation_language' using cloud service 'api'. You need to set API settings first.
Translator$automatic_translate(keyword, api = "google")
keyword
character or vector of characters with a word or expression to translate
api
character with the name of the API you want to use. Currently
supported: google
.
at()
Wrapper to automatic_translate
method
Translator$at(keyword, api = "google")
keyword
character or vector of characters with a word or expression to translate
api
character with the name of the API you want to use. Currently
supported: google
.
use_js()
Call to wrap translation in span object. Used for browser-side translations.
Translator$use_js()
clone()
The objects of this class are cloneable with this method.
Translator$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run: i18n <- Translator$new(translation_json_path = "translation.json") # translation file i18n$set_translation_language("it") i18n$t("This text will be translated to Italian") ## End(Not run) # 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) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.