Appsilon / shiny.i18n

Shiny applications internationalization made easy
https://appsilon.github.io/shiny.i18n/
Other
168 stars 38 forks source link

[Feature]: Support regex wildcards in text substitution #130

Open yogat3ch opened 1 year ago

yogat3ch commented 1 year ago

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.