2017-08-24 48 views
0

我正在处理i18next中的反应https://github.com/i18next/react-i18next。我正努力在我的JSON语言文件中的字符串内划线。在JSON字符串中反应i18n中断线

这是我已经尝试过,不闯出了一条新线:

  • line: "This is a line. \n This is another line. \n Yet another line"enter image description here
  • line: ("This is a line."+ <br/> + "This is another line. \n Yet another line")enter image description here
  • line: ('This is a line. <br/> This is another line. \n Yet another line')enter image description here

我很明显尝试在每个句子后写一个新的句子。这就是我所说的:

<TooltipLink onClick={() => { 
    this.toggleHelpTextDialog(t('test:test.line')); 
}}/> 

任何想法?谢谢!

+0

这完全取决于组件上。它可能会或可能不支持换行符。您是否尝试在没有i18n翻译的情况下直接设置文本? –

+0

我没有直接设置文本,也没有工作。我通过道具设置对话框的文字。你认为这可能会导致问题? – Nocebo

+0

只是看看这个问题,它可能会帮助你: https://stackoverflow.com/questions/2392766/multiline-strings-in-json – emma93

回答

1

<br />是正确的方式,但它不会进入文本或翻译。例如:

<div> 
    {'my text line 1'} 
    <br /> 
    {'my text line 2'} 
</div> 

不过,如果你想保持换行符(\ n)的文本中,然后再去做这样的使用dangerouslySetInnerHTML:

const text = "This is a line. \n This is another line. \n Yet another line"; 
<div dangerouslySetInnerHTML={text} /> 
+0

不幸的是,我不能这样做在我的情况,因为我不仅设置字符串,但也是整个组件。不过谢谢你! – Nocebo