代码之家  ›  专栏  ›  技术社区  ›  four-eyes

使用react i18next打断react native中的换行符

  •  0
  • four-eyes  · 技术社区  · 4 周前

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

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

    那个 \n 什么都没做。如何在翻译文件中添加换行符?

    1 回复  |  直到 4 周前
        1
  •  0
  •   Mike Tabag Estonanto    4 周前
    {
      "FOO": "I am text\nthat should have a new line\nThat\nis not doing anything."
    }
    

    在您的React Native代码中,确保您使用支持换行符的组件来呈现翻译后的文本,例如text组件:

    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;
    
    推荐文章