Coder Social home page Coder Social logo

Comments (1)

jakubsob avatar jakubsob commented on June 9, 2024 5

Hello @Miracle-90! Thanks for using the package and submitting an issue. The reason why you're getting 3 elements is that browser side translation wraps translated elements with a span tag with information on currently selected language. Out-of-the-box shiny::selectInput doesn't allow you to use html tags as choices. In this case you could either use server side translation or use shinyWidgets::pickerInput which allows you to do so. Please check out the following example with both approaches to see whether this solves your issue.

library(shiny)
library(shiny.i18n)
library(shinyWidgets)
i18n <- Translator$new(translation_csvs_path = ".")
# Set translation language of your choice
i18n$set_translation_language("pl")

ui <- fluidPage(
  usei18n(i18n),
  tabsetPanel(
    id = "tabs",
    type = "tabs",
    tabPanel(
      "Browser side translation",
      value = 1,
      pickerInput(
        inputId = "browser_translation",
        label = "", 
        choices = c("pdregion"),
        width = "500px",
        choicesOpt = list(
          content = c(as.character(i18n$t("Population density of the region")))
        )
      )
    ),
    tabPanel(
      "Server-side translation",
      value = 2,
      uiOutput("tab_content")
    )
  )
)

server <- function(input, output, session) {
  output$tab_content <- renderUI({
    selectInput(
      inputId = "server_translation",
      label = "",
      width = "500px",
      choices = setNames(c('pdregion'), i18n$t("Population density of the region"))
    )
  })
}

shinyApp(ui = ui, server = server)

With a translation dictionary being:

en,pl
Population density of the region,Y

from shiny.i18n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.