question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render html tags with component interpolation

See original GitHub issue

It’s possible to render html tags with component interpolation?

Example:

const messages = {
  en: {
    text: '<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</p><p>Lorem ipsum, dolor {email}.</p>',
    email: 'foo@acme.com'
  }
}
<i18n path="text" tag="div">
  <my-link place="email" :href="`mailto:$t('email')`">{{ $t('args.email') }}</my-link>
</i18n>

I expect two paragraphs, and in the second paragraph, one link with my custom link component, but, the paragraphs was rendering as strings and not as html tags.

Maybe it’s is a bug? Or is impossible to render an html tags inside a <i18n> component?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:14
  • Comments:14

github_iconTop GitHub Comments

12reactions
tho-masncommented, Jun 10, 2020

This has the big advantage of keeping the markup out of the translation content and in your template (where it belongs).

In general I agree with that statement. But I think there are still some use-cases where html in the translations makes sense, like if you want to highlight 1 word by using a <b> tag, or like the use-case of @leandromatos-hotmart. Would it make sense to add something like a isHtml option to the i18n tag?

4reactions
via-larscommented, Feb 1, 2022

I like to add my vote to enable HTML be output as such inside interpolation from <i18n-t>. Translated languages can have different grammar and different phrase symbols (think Quotes, Ampersand) which requires multiple paragraphs in the translation or HTML escapes.

As such, for a translation utility, I think this is a 1st class requirement.

I also like to know what the security issue is exactly. Translations are static pre-delivered and not user-generated for other users on the fly. Sanitisation would have to occur on borders, ie. first after a backend received data, not “inbetween every code line”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to give html tags inside string interpolation in reactjs?
You can do something like this: const confirmMessage = isDelete ? ( <p> You are about to delete the <em>{valueType}</em>.
Read more >
Render html tags with component interpolation #898 - Issuehunt
It's possible to render html tags with component interpolation? Example: const messages = { en: { text: '<p>Lorem ipsum, dolor sit amet consectetur ......
Read more >
JSX In Depth - React
The first part of a JSX tag determines the type of the React element. Capitalized types indicate that the JSX tag is referring...
Read more >
Angular — How to render HTML containing ... - Talentica
The dynamic components rendering factory · Find Components' HTML elements in DOM (of the dynamic HTML). · Create appropriate Angular Components ...
Read more >
Writing templates - Lit.dev
The html tag function returns a TemplateResult —a lightweight object that represents the template to be rendered. The render function actually creates DOM ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found