Appsilon/shiny.i18n

Problem with translating the options for Shiny Widgets

Closed this issue · 2 comments

Hello,
I was trying to create an instance of the Live language change on the browser side by following the examples.
It works very well with the "label" elements of the widgets, but the option texts are not getting translated.

I'm attaching an example where I was trying to create a Likert scale widget using the "shinyWidgets" package, and the options are not playing well.

Code snippet below:

# Not Working
shiny.i18n::usei18n(i18n)
likert.choices = c(i18n$t("Strongly disagree"), i18n$t("Disagree"), i18n$t("Neither agree nor disagree"), i18n$t("Agree"), i18n$t("Strongly agree"))
...
#Input: Slider  ----
            sliderTextInput( 
                inputId = "Id102",
                label = i18n$t("Your choice:"),  # This works
                grid = TRUE,
                force_edges = TRUE,
                choices = likert.choices # this doesn't work
            )

The complete code and translation files are pasted below for reference.
Archive.zip

If you could suggest some way of fixing this problem, that would be great!

hey @tapjdey , thanks for using the package. To enable dynamic translations, we decided to wrap the text with a span that has a class that contains information about the current language. So they become non-character, but shiny tag objects that may cause some troubles when given as input to the objects that expect text.

Your may try to use the server-side translation instead:
https://github.com/Appsilon/shiny.i18n/blob/master/examples/live_language_change/server_app.R
This should help in your scenario.

BTW Also i18n$t method should handle translations of vectors, so no need to call it separately for every entry ;)

Hi @dokato
Thank you very much for your reply. Yes, that solved my problem :)