【问题标题】:moment.js change locale not workingmoment.js 更改语言环境不起作用
【发布时间】:2018-09-22 02:48:49
【问题描述】:

我的项目是一个反应项目。

当我更改网络语言时,我的网站是一个多语言网站。 moment.locale(lang) 不工作。

我的代码是:

const startDate = moment.utc(start).locale(lang);
const endDate = moment.utc(end).locale(lang);

无论我设置什么lang 我检查startDate.locale() 总是'en' startDate.format('ll') 结果总是英文。

【问题讨论】:

标签: momentjs


【解决方案1】:

如果项目是使用 create-react-app 创建的,则区域设置可能是 excluded by default

这现在记录在 create-react-app 的故障排除指南的"Moment.js locales are missing" section 中。

解决方案:在“moment”之外显式导入语言环境:

import moment from 'moment';
import 'moment/locale/fr';
import 'moment/locale/es';
// etc. as required

【讨论】:

    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多