【问题标题】:i18next to do formatting of dates, numbers with the Intl Apii18next 使用 Intl Api 对日期、数字进行格式化
【发布时间】:2017-06-08 01:14:26
【问题描述】:

在这个链接上,https://www.i18next.com/formatting.html 说我们可以使用 Intl api 进行格式化,但没有说明如何使用它。

我们如何配置 i18next 以将 Intl api 用于所有日期、时间和数字格式?该示例说它应该很简单,但没有显示参考示例。

【问题讨论】:

标签: i18next


【解决方案1】:

你可以:

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: today is the {{now, intlDate}}

拨打电话:i18next.t('key', { now: new Date() })

【讨论】:

    猜你喜欢
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2019-05-28
    • 2013-06-18
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多