New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translation for radioButton() choices and selectInput() #54
Comments
This was just my issue, I resolved this using following function. It works for me. Hope you find it useful too. trF<-function(x){ use single quotation mark (') around x argument. |
hey @mcsiple , because both radio button as select input are dynamic elements, they need to be updated with respective update functions from library(shiny)
library(shiny.i18n)
i18n <- Translator$new(translation_json_path = "translation.json")
ui <- fluidPage(
usei18n(i18n),
h1(i18n$t("Hello")),
actionButton("change", i18n$t("Change language")),
radioButtons("radio", i18n$t("Radio"), c("one", "two")),
selectInput("select", i18n$t("Choose"), c("one", "two", "three"))
)
server <- function(input, output, session) {
i18n_r <- reactive({
i18n
})
observeEvent(input$change, {
lang <- ifelse(as.numeric(input$change) %% 2, "pl", "en")
shiny.i18n::update_lang(session, lang)
i18n_r()$set_translation_language(lang)
})
observe({
updateRadioButtons(session, "radio", label = i18n_r()$t("Radio"),
choices = i18n_r()$t(c("one", "two")))
updateSelectInput(session, "select", label = i18n_r()$t("Choose"),
choices = i18n_r()$t(c("one", "two", "three")))
})
}
shinyApp(ui, server) Note that I create a reactive variable |
Success! It worked. Thank you @dokato , this is great. |
Hi! This works fine for unnamed choices, but what about named ones? I want to translate the names of the choices but not the actual choice itself, e.g. my choices are c("INFORMATION" = "info", "EVOLUTION" = "evol") and I want to translate INFORMATION and EVOLUTION but not info and evol. The above code does not work in that case and I can't manage to make it work. Any suggestions? Thanks! |
I solved as follows.
|
Hi shiny.i18n team,
I know I have seen questions about this before but I can't find a solution -- I need to find a way to translate the
choices
in my selectInput() andradioButtons()
inputs. If I try to wrap choice labels withi18n$t()
, the app does not run. I don't know if this is a feature in the package yet, but if it isn't, would you mind offering some best practices for how people should get by in the meantime?I am doing live translation and using
uiOutput(page_content)
in my UI to do automatic translation when the user selects a radio button with the language on it. I don't need to update the language selection radio buttons themselves, but I need it for otherradioButton
inputs and a dropdownSelectInput()
with common names of species.Thank you in advance for your help.
The text was updated successfully, but these errors were encountered: