【问题标题】:Using translation react-i18next with react-moment使用翻译 react-i18next 和 react-moment
【发布时间】:2021-01-29 17:23:39
【问题描述】:

我的 React Web 应用程序中有英语和瑞典语。

我正在使用 react-moment,在我的 App.js 中,我已经导入了 moment/locale 并为我需要有日期的每个页面放置了 import Moment from 'react-moment'。

import 'moment/locale/sv'
import 'moment/locale/en-gb'

如何将其翻译成瑞典语,但不能永久翻译?用户可以将语言从英语切换到瑞典语,反之亦然。

   <Moment format="ddd DD MMM">
     {flight.date}
   </Moment>

  <Moment format="HH:mm">{stop.arrival}</Moment>

【问题讨论】:

    标签: reactjs momentjs translation react-i18next


    【解决方案1】:

    使用 moment.locale() 更改语言环境并将本地设置为 Moment 元素

    moment.locale('sv') 
    <Moment format="ddd DD MMM" local>
     {flight.date}
    </Moment>
    

    或者你也可以这样做

    <Moment locale="sv" format="ddd DD MMM">{flight.date}</Moment>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 2022-06-12
      • 1970-01-01
      • 2021-09-18
      • 2020-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多