Ability to have markup in strings
See original GitHub issueWe have use cases where we would like to insert markup inside of a phrase that should be translated as a whole unit, e.g.
<a href="http://example.com>Please click here</a> to open the page
As the system currently works, we would need to construct it as, <Text id='link.pre'/><a href="http://example.com><Text id='link.text'/></a><Text id='link.post'/>
because different languages might translate this sentence akin to Please, to open the page <a href="http://example.com>click here</a>
or other variations of ordering, which forces a before, during, and after markup set of text. This gets out of control if you have more than one piece of markup in your text. It also means that a translation service has to try to translate this set of strings:
link.pre=''
link.text='Please click here'
link.post='to open the page'
I image that is difficult for a translation service.
I wonder if this could be solved by simply allowing for markup in the string, and having a boolean flag for something like <Text id="openPage" dangerouslySetInnerHTML />
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Can simplify via
Localizer
:… or without preact-markup at all:
I was messing around with this, and I had a more complex use case I thought I would share.
Say I take this one step further, and I need to do template replacement into a string that required both markup and a component, in this case
<Icon />
You can extend @developit
<MarkupText />
component to include afields
argument like this:Then use
preact-render-to-string
to pre-render that component when passing it to<MarkupText />
:Assuming that your translation string contains
{{navArrowLeft}}
.