alibaba / react-intl-universal

Internationalize React apps. Not only for Component but also for Vanilla JS.
1.33k stars 154 forks source link

HTML inside a variable doesn't work #168

Closed djonathas closed 3 years ago

djonathas commented 3 years ago

I realized today it is not possible to put HTML tags inside a variable, like that:

const items = ' <br />Item 1<br />Item 2';
const text = intl.getHTML('key', { items });

the result is: Test List <br />Item 1<br />Item 2

cwtuan commented 3 years ago

Yes, the variable will be a string in the result.

In your case, you could separate them into two parts.

const items = ['Item1', 'Item2'];
return (
<div>
  {intl.get('key').d('Test List ')}
  {items.map(item=>(<><br />{item}</>))}
</div>
)
djonathas commented 3 years ago

Yes, I did this for now. But I thought it was good have this feature to variable too