在此链接上,https://www.i18next.com/formatting.html它说我们可以使用 Intl api 进行格式化,但没有显示如何使用它。
我们如何配置 i18next 以将 Intl api 用于所有日期、时间和数字格式?该示例说它应该很简单,但没有显示引用示例。
最佳答案
你可以:
i18next.init({
interpolation: {
format: function(value, format, lng) {
if (format === 'intlDate') return new Intl.DateTimeFormat().format(value); // -> "12/20/2012" if run in en-US locale with time zone America/Los_Angeles
return value;
}
}
});
json: key: 今天是 {{now, intlDate}}
调用 t:i18next.t('key', { now: new Date() })
关于i18next 使用 Intl Api 格式化日期、数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44401102/