我正在
react-i18next i18next
项目中使用 react-native
。我在翻译文本中添加新行时遇到问题。
// locales_en.json
"FOO": "I am text \n that should have a new line
那个
\n
没有做任何事情。如何在翻译文件中添加换行符?
{
"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;