【问题标题】:react native moment updateLocal fr crush android为crush android反应原生时刻updateLocale
【发布时间】:2020-05-15 00:19:43
【问题描述】:

我想使用时刻库​​将日期翻译成法语。

我创建了一个 android 版本,但是当我打开组件时它崩溃了。

我的代码是:

import Moment from 'moment';

// i fixed the error 
// var moment = require('moment');
//require('moment/locale/fr');
//moment.locale('fr');



    render() {
....
{
this.state.notifications.map((notification, i) => (     
    Moment.updateLocale('fr', {
        // the config here
        // translate to french
    }),
    notification.type === 'Partage de contact' ?
        <ListItem
            key={i}
            ...
            subtitle={`Date : ${Moment(notification.date).format('dddd D MMMM,  YYYY')}`}
            bottomDivider
        />
        :
        <ListItem
            ...
            subtitle={`Date : ${Moment(notification.date).format('dddd D MMMM,  YYYY')}`}
            bottomDivider
        />
))
}
...

}

【问题讨论】:

    标签: android react-native build momentjs expo


    【解决方案1】:

    使用moment.local()将日期翻译成任何(法语)语言

    import moment from 'moment';
    
    
    render() {
    
      var march = moment('2017-03')
    
      console.log(march.format('MMMM')) 
    
      moment.locale('fr') // you can set here 
    
      console.log(march.format('MMMM'))
    
      ................
    
    }
    

    【讨论】:

    • 我使用 moment.local('fr') 但我有一个英文日期
    • 你确定要登录
    • 我用这个修复了:var moment = require('moment');要求(“时刻/语言环境/法国”); moment.locale('fr');
    • 干得好,继续努力
    猜你喜欢
    • 2019-11-02
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    • 2017-02-06
    • 2018-02-08
    • 1970-01-01
    相关资源
    最近更新 更多