Add GlSprintfSimple component
GlSprintf
is flexible, but verbose for simple use cases. For instance:
<gl-sprintf :message="__('This should be %{strongStart}bolded%{strongEnd} text')">
<template #strong="{ content }">
<strong>{{ content }}</strong>
</template>
</gl-sprintf>
That's a fair amount to write (and read) to render simply This should be <strong>bolded</strong> text
.
This issue is about considering creating a new component, perhaps GlSprintfSimple
, for this use case. The API would be simpler (but less flexible as a consequence) than GlSprintf
's. It would:
- Not define/use any slots
- Use a whitelist of valid placeholder names, corresponding precisely to standard markup tags
- Use
GlSprintf
under the hood
For example, the above could be written as:
<gl-sprintf-simple :message="__('This should be %{strongStart}bolded%{strongEnd} text')" />
And produce exactly the same result as above.
It would perhaps have a whitelist of valid start/end placeholders/tags, corresponding to some common basic markup tags, e.g.:
strong
b
i
em
sup
sub
code
kbd
del
ins
wbr
and so on.
Edited by Mark Florian