Issue
I'm working with i18next for react https://github.com/i18next/react-i18next. I'm struggling to break lines within the string in my JSON language file.
This is what I already tried, which doesn't break a new line:
line: "This is a line. \n This is another line. \n Yet another line",
line: ("This is a line."+ <br/> + "This is another line. \n Yet another line"),
line: ('This is a line. <br/> This is another line. \n Yet another line'),
I obviously try to make a new line after each sentence. This is how I call it:
<TooltipLink onClick={() => {
    this.toggleHelpTextDialog(t('test:test.line'));
}}/>
Any ideas? Thanks!
Solution
You can do it with css white-space: pre-line; & \n in the translation text.
const root = document.getElementById('root');
i18next.init({
  lng: 'en',
  resources: {
    en: {
      translation: {
        "key": "Hello world\nThis sentence should appear on the second line"
        // ----------------^ new line char
      }
    }
  }
}, function(err, t) {
  // initialized and ready to go!
  root.innerHTML = i18next.t('key');
});
#root {
  white-space: pre-line;
}
<script src="https://unpkg.com/i18next@15.0.9/dist/umd/i18next.min.js"></script>
<div id="root"></div>
Answered By - felixmosh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.