Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

react-i18next hook vs component with translation strings

it looks like the react-i18next useTranslation hook doesn't strip out the <></> from translation strings

for example, say we have translation like this:

"some_string_with_brackets": "hello <text>world</text>."

using the Trans component like:

<Trans
  i18nKey="some_string_with_brackets"
  components={{
    text: (
      <span/>
    )
  }}
/>

the string will be displayed with the span component defined in the components object, as desired.

But if we use the same key in the t function from the useTranslation hook, the result is:

hello <text>world</text>.

What is the correct way to handle this scenario? I can add _trans to keys that need to be rendered with the Trans component, but I am wondering if I am missing something about how this should work.

question from:https://stackoverflow.com/questions/65862244/react-i18next-hook-vs-component-with-translation-strings

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...