Giter Club home page Giter Club logo

shi18ny's People

Contributors

brazadas avatar jpmarindiaz avatar lenafm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

shi18ny's Issues

Should give error when langSelectorInput is not defined in UI

library(shiny)
library(shi18ny)

ui <- fluidPage(
  useShi18ny(),
  #langSelectorInput("lang", position = "fixed"),
  h1(ui_("hello")),
  uiOutput("results")
)

server <- function(input, output, session) {
  i18n <- list(
    defaultLang = "en",
    availableLangs = c("es","en")
  )
  lang <- callModule(langSelector,"lang", i18n = i18n, showSelector = TRUE)

  output$results <- renderUI({
    list(
      h2(i_("language",lang()), ": ", lang()),
      h1(i_("hello",lang()))
    )
  })

}

shinyApp(ui, server)

put locale folder in the same folder of the examples run (e.g. ex-03)

We would expect users generally not to modify the default locale folder for the app translations.

It would be easier for users to check the code of the app and how it works right in the same folder they are running the app from, and not having to navigate to the tests folder to see what is happening.

Fix uiLangUpdate for workaround of shi18ny/parmesan clash

Without the updateSelectLangInput function in langSelector (which was removed to temporarily solve the shi18ny/parmesan clash which was blocking modals from shinypanels to open) the translations of text directly in the UI of an app doesn't work, because input$shi18ny_ui_classes isn't created on time by useShi18ny.

There is a workaround for this by adding a shinyjs::delay to the observeEvent in the apps, in which the UI texts are translated (as in code below). This should probably work without the delay function.

  observeEvent(lang(),{
    shinyjs::delay(500, uiLangUpdate(input$shi18ny_ui_classes, lang()))
  })

FYI - potential useful backend support in package traduire

Full disclosure, I am one of the authors of tradiure.

We've been working on backend support for i18n work (not in the context of shiny apps) and developed a package called traduire (https://github.com/reside-ic/traduire) which wraps the i18next js library, and so includes lots of nice support (pluralisation, context specific translation, in theory support for RTL languages etc). Depending on your goals you might find it useful.

Just an FYI - if you're happier developing your own engine please disregard

Fix clash with parmesan caused in langSelector

In langSelector the updateSelectLangInput inside the initLocale reactive was causing a clash with the parmesan package and therefore blocking modals from opening. In particular, modals from shinypanels::showModalMultipleId (example to reproduce this problem can be found in inst/examples/ex07-translate_with_parmesan) were not opening. The temporary fix was to remove this updateSelectLangInput which means that shi18ny only works with language parameters from the URL, but not with the language dropdown.

The following code snippet shows the reactives initLocale and currentLocale how they are working right now, with the old code commented out. Uncomment the commented sections to reproduce issue.

initLocale <- reactive({
    selected <- queryLang() %||% config$defaultLang

    message("selected2 ", selected," config ", config$defaultLang)
    message(showSelector)

    if(showSelector){
      shinyjs::show("langContainer")
    }
    message("config_av_langs",config$availableLangs)

    # uncomment the following to reproduce problem
    # updateSelectLangInput(session, 'langInner', 
    #                       langs = config$availableLangs,
    #                       selected = selected)

    message("selected3", selected, " config ", config$defaultLang)
    selected
  })

  currentLocale <- reactive({
    initLocale()
    newLocale <- queryLang() # comment out this to reproduce problem
    # newLocale <- input$langInner # uncomment this to reproduce problem
    message("initLocale: ", initLocale())
    message("input3 ", newLocale, " is null ",is.null(newLocale))

    newLocale
  })

Language selection dropdown missing

When I run the code provided in the example below, the dropdown menu to select a language is missing.

if (interactive()) {
    
    library("shiny")
    library("shi18ny")
    
    ui <- fluidPage(
        tags$h1("shiny internationalization"),
        
        br(),
        # Initialize shi18ny
        useShi18ny(),
        
        # Language selector input
        langSelectorInput("lang", position = "fixed"),
        
        # UI elements
        # Text can be translated directly from the UI, using the ui_ function:
        h1(ui_("hello")),
        # OR by using uiOutput:
        uiOutput("results")
        
    )
    
    server <- function(input, output, session) {
        # Configure shi18ny
        i18n <- list(
            defaultLang = "en",
            availableLangs = c("es", "en", "pt")
        )
        
        # Call language module to get currently selected language and save it in a reactive
        lang <- callModule(langSelector, "lang", i18n = i18n, showSelector = TRUE)
        
        # Update UI translation
        observeEvent(lang(),{
            uiLangUpdate(input$shi18ny_ui_classes, lang())
        })
        
        # Render translations by passing the text and the active (selected) language as the lang() parameter to the i_ function
        output$results <- renderUI({
            list(
                h1(i_("world", lang())), 
                br(), 
                h4(i_("language", lang()))
            )
        })
    }
    
    shinyApp(ui, server)
    
}

Screen Shot 2021-03-02 at 4 56 10 PM

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.