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.

这是我已经try 过的,并没有打破一条新的界线:

  • 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"), enter image description here
  • line: ('This is a line. <br/> This is another line. \n Yet another line'),

很明显,我会在每句话后换一行.这就是我所说的:

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

有什么主意吗?谢谢!

推荐答案

你可以用css white-space: pre-line;&;\n在翻译文本中.

const root = document.getElementById('root');

i18next.init({
  lng: 'en',
  resources: {
    en: {
      translation: {
        "key": "Hello world\nThis sentence should appear on the second line"
      }
    }
  }
}, 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>

Json相关问答推荐

如何在JMESPath中区分空和假?

PowerShell:将Invoke-WebRequest与变量一起使用

NiFi QueryRecord处理器- Select 可选的JSON属性

使用 Redis 作为键值存储

GitHub Pages无法正确显示我的项目

如何在jolt中使用shift和modify-overwrite-beta

从 json 对象中过滤掉所有出现的给定属性

如何使用 jackson 反序列化为 Kotlin 集合

避免 KeyError 的默认字典键

如何使用 Jackson 定义可选的 json 字段

在 Http Header 中使用 Json 字符串

Jackson 动态属性名称

如何在 json 编码字符串内的子数组数据周围添加方括号?

如何创建 JSON 对象 Node.js

waitUntilAllTask​​sAreFinished 错误 Swift

JSON Schema:验证数字或空值

请求返回字节,我无法解码它们

python追加到json对象中的数组

如何在 postgresql 9.3 中循环 JSON 数组

从 Ruby 中的 JSON 文件解析并从嵌套哈希中提取数字