Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add support for translations of shinyBS collapse panels #114

Open
1 task done
rjzupkoii opened this issue Mar 3, 2023 · 0 comments
Open
1 task done

Comments

@rjzupkoii
Copy link

Guidelines

  • I agree to follow this project's Contributing Guidelines.

Description

Elements such as the bsCollapsePanel from the shinyBS library are frequency used to organize UI controls. As such, for international applications, being able to translate all elements in a UI is critical.

Problem

As currently implemented, translation cannot be directly enabled for the bsCollapsePanel since it doesn't appear to expose the appropriate data context for the shiny.i18n library to access. A work around is possible as demonstrated in the Proposed Solution, which suggests that it is is likely possible to add a cleaner (e.g., shiny.i18n::translate_panels(i18n) function call or the like) version to the library.

Proposed Solution

The following snippet enables translation of bsCollapsePanel elements:

# Add the i18n class and translation key to the bsCollapsePanel
HTML('
<script>
$(document).on("shiny:sessioninitialized", function(event) {
  $("a[id^=\'ui-collapse\']").each(function() {
    $(this).addClass("i18n");
    $(this).attr("data-key", $(this).text());
  }); 
});
</script>'),

Alternatives Considered

I've actually added the above code snippet to our own application, so the support is already present. Formalizing it as part of the shiny.i18n library would just make this more accessible to others for use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant