【问题标题】:Timeago.js use locale configsTimeago.js 使用语言环境配置
【发布时间】:2022-01-22 22:22:40
【问题描述】:

我正在使用 timeago.js 将存储在数据库中的信息显示为“...小时前”。 我的问题是我需要把它翻译成 pt_BR,我在文档上看到他们有这个选项并尝试在我的 ReactJS 代码上实现它,但我什么也没得到,它仍然是英文的。

import { format } from 'timeago.js'

export default function Post({post}) {

...

<span className="postDate">{format(post.createdAt, 'pt_BR')}</span>

...

要知道,我正在使用 MongoDB。

我的错误在哪里?

【问题讨论】:

    标签: javascript reactjs mongodb timeago


    【解决方案1】:

    我想出了怎么做:

    import * as timeago from 'timeago.js'
    import TimeAgo from 'timeago-react'
    import pt_BR from 'timeago.js/lib/lang/pt_BR'
    
    timeago.register('pt_BR', pt_BR)
    
    <span className="postDate">
    <TimeAgo datetime={post.createdAt} locale='pt_BR' />
    </span>
    

    【讨论】:

      猜你喜欢
      • 2022-12-10
      • 2019-02-21
      • 2015-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-01
      • 2021-10-14
      • 1970-01-01
      相关资源
      最近更新 更多