Closed KHwong12 closed 2 years ago
I also noticed that the texts that could be translated are span
HTML elements with the class of i18n
. The title and menu items texts, meanwhile, do not have a i18n
class.
Issue solved with this StackOverflow answer.
The use_js
method for the translator class (i18n
) should be called before any call to the translate
method.
Cross-posted from StackOverflow (https://stackoverflow.com/questions/73509710/items-inside-header-and-sidebar-of-shinydashboard-are-not-translated-with-shi).
Guidelines
Project Version
0.2.0
Platform and OS Version
macOS 12.3.1, R 4.2.1, RStudio 2022.07.1
Existing Issues
No response
What happened?
When using
{shiny.i18n}
for live language translations in an{shinydashboard}
app, the contents insidedashboardHeader()
anddashboardSidebar()
are not translated. Contents insidedashboardBody()
are translated though.Steps to reproduce
In the sample app below, the title of the Dashboard ("Basic dashboard") and the two menu items ("Dashboard Tab" and "Widgets Tab") are all wrapped in the
i18n$t()
function, with traditional Chinese translation (zh) provided intranslation_zh.csv
.shiny::runApp()
shiny.i18n::usei18n(i18n)
Expected behavior
When the user changes the language from en to zh, the text of the menu items and dashboard title do not change. Meanwhile, other items inside
dashboardBody()
(e.g. "Number of observations:") are successfully translated.The title (
i18n$t("Basic dashboard")
) and menu items (i18n$t("Dashboard Tab")
andi18n$t("Widgets Tab")
) will change from English to the respective traditional Chinese language word after changing the language.Attachments
The app code is merged from the sample app of {shinydashboard} and sample app of {shiny.i18n}.
app.R
data/translation_zh.csv
Screenshots or Videos
Default view
After selecting zh as the language
Screen recording
Additional Information
I am also not sure if this issue should be posted here or on the repo of {shinydashboard}. Feel free to close this issue if this issue is related to {shinydashboard} instead of {shiny.i18n}.