shiny.i18n icon indicating copy to clipboard operation
shiny.i18n copied to clipboard

[Feature]: Support regex wildcards in text substitution

Open yogat3ch opened this issue 11 months ago • 0 comments

Guidelines

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

Description

It's often necessary to dynamically render values in the UI: tags$div(glue::glue("Your model has {accuracy} accuracy")) With present implementation, this must be parsed into two translation strings:

tags$div(tags$span(i18n$t("Your model has "), accuracy, i18n$t(" accuracy")))

Problem

This can grow to be extremely cumbersome the more dynamic substitution is necessary. Reflexive verbs and prepositions often need special treatment relative to the sentence subject in other languages so sentence fragments may have the same key in english, but multiple keys in other languages, further complicating implementation.

Proposed Solution

The key lookup logic could use regex lookup flags IE the key might look like:

"Your model has $x/\\d+\\.\\d+\\%/ accuracy"

which would leave the regex as is while replacing the language around it. I guess this also could be complicated depending on changes to sentence structure in other languages, but c'est la vie.

Alternatives Considered

Not really, it's a complex problem to solve.

yogat3ch avatar Sep 15 '23 16:09 yogat3ch