To translate SelectInputs (Dropdown) using shiny.i18n package

Hello Guys,

I am trying to translate as per language select and everthing in my code is getting translated except the selectInput dropdown values.

library(shiny)

# Define UI for app that draws a histogram ----
ui <- fluidPage(
  
  sidebarLayout(

    sidebarPanel(
 selectInput("selected_language", 
paste0(translator$t("Language"), ":"), 
choices = c("Deutsch"="de", "English"="en"), selected = "de"),
               
selectInput("kpi",     label = NULL,
                           selected = "costs",
  choices=c(         i18n()$t("Costs")= "costs",
                     i18n()$t("Impressions") = "impressions",
                     i18n()$t("Interactions")= "interactions",
                     i18n()$t("Video Views") ="video_total_views"
                               )

      

    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Histogram ----
      

    )
  )
)
server <- function(input,output,session){
i18n <- reactive({
  selected <- input$selected_language
  if (length(selected) > 0 && selected %in% translator$languages) {
    translator$set_translation_language(selected)
  }
  translator
})

}

Everything except choices list of selectinput is getting translated
I have already added the translation in csv file and there is some UpdateSelectInput logic required which i am not able to apply!!

Hi,

Welcome to the RStudio community!

I don't have all the data in order for me to run the app, but I think I know what you're looking for and made a dummy example. Next time, try and generate a reprex so we can actually build on top of your first attempt. Shiny debugging and reprex guide

Here is an example I made that might help:

library(shiny)

ui <- fluidPage(
  titlePanel("Welcome to my app!"),
  
  radioButtons("langChoice", "Language", choices = c("Lang X" = "langx", "Lang Y" = "langy")),
  
  #Dropdown to translate
  selectInput("myDropdown", "Choose", choices = "")
)

#Make sure the 'session' argument is set
server <- function(input, output, session) {
  
  translations = data.frame(
    id = paste("id", 1:5, sep = "_"),
    langx = paste("XXX", 1:5, sep = " "),
    langy = paste("YYY", 1:5, sep = " ")
    )
  
  observeEvent(input$langChoice, {
    # Call the "updateSelectInput" and edit what needed
    updateSelectInput(session, "myDropdown", 
                      label = input$langChoice,
                      choices = setNames(translations$id, translations[,input$langChoice]))
  })
  
  
}

shinyApp(ui, server)

Hope this helps,
PJ