我正在尝试将 Intl 与 pt-BR 语言环境一起使用,但无法使其与 Node 0.12 一起使用。
代码:
global.Intl = require('intl/Intl');
require('intl/locale-data/jsonp/pt-BR.js');
var options = { year: 'numeric', month: 'long' };
var dateTimeFormat = new Intl.DateTimeFormat('pt-BR', options);
console.log(dateTimeFormat.format(new Date()));
此代码输出:
May, 2015
我希望那是:'Maio,2015'。
然后,如果我决定创建一个新变量,一切正常:
工作代码:
global.NewIntl = require('intl/Intl');
require('intl/locale-data/jsonp/pt-BR.js');
var options = { year: 'numeric', month: 'long' };
var dateTimeFormat = new NewIntl.DateTimeFormat('pt-BR', options);
console.log(dateTimeFormat.format(new Date()));
这将打印出期望值。问题:为什么 Intl 全局变量没有被替换?