最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - i18next translation being displayed as unicode hex character - Stack Overflow

programmeradmin4浏览0评论

I'm using i18next to handle translations in a project I'm working on and I'm finding that when I hand a string to the translation that contains /, it is being converted to the unicode hex code /

I am setting title as:

const title = '2/Double/Twin/Triple/Quadrupple'

The translation is called as follows:

{i18n.t('foo', {
  title,
  amount: '$18'
})}

And the translation is setup like:

{
  "foo": "foo bar {{title}} howdee {{amount}}"
}

However the output is:

Foo bar 2/Double/Twin/Triple/Quadrupple howdee $18

How do I ensure that characters are not converted to their hex code equivalents?

I'm using i18next to handle translations in a project I'm working on and I'm finding that when I hand a string to the translation that contains /, it is being converted to the unicode hex code /

I am setting title as:

const title = '2/Double/Twin/Triple/Quadrupple'

The translation is called as follows:

{i18n.t('foo', {
  title,
  amount: '$18'
})}

And the translation is setup like:

{
  "foo": "foo bar {{title}} howdee {{amount}}"
}

However the output is:

Foo bar 2/Double/Twin/Triple/Quadrupple howdee $18

How do I ensure that characters are not converted to their hex code equivalents?

Share Improve this question asked Jul 17, 2017 at 9:30 oldo.nichooldo.nicho 2,2894 gold badges29 silver badges42 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 24

By default i18next escapes content to avoid xss attacks based on user input. You can turn off escaping by prepending - or provide escape flag.

{
  "foo": "foo bar {{- title}} howdee {{amount}}"
}

or

{i18n.t('foo', {
  title,
  amount: '$18',
  interpolation: { escapeValue: false }
})}

https://www.i18next.com/interpolation.html#unescape

发布评论

评论列表(0)

  1. 暂无评论