使用 React i18next 在 React Native 中换行

问题描述 投票:0回答:1

我正在

react-i18next i18next
项目中使用
react-native
。我在翻译文本中添加新行时遇到问题。

// locales_en.json
"FOO": "I am text \n that should have a new line

那个

\n
没有做任何事情。如何在翻译文件中添加换行符?

javascript react-native i18next react-i18next
1个回答
0
投票
{
  "FOO": "I am text\nthat should have a new line\nThat\nis not doing anything."
}

在 React Native 代码中,确保使用支持换行符的组件(例如文本组件)渲染翻译后的文本:

import React from 'react';
import { Text } from 'react-native';
import { useTranslation } from 'react-i18next';

const MyComponent = () => {
  const { t } = useTranslation();

  return <Text>{t('FOO')}</Text>;
};

export default MyComponent;
© www.soinside.com 2019 - 2024. All rights reserved.