i18next 使用 Intl Api 格式化日期、数字

标签 i18next

在此链接上,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/

相关文章:

javascript - React 中 i18next 翻译文件中的 HTML 标签

vue.js - Vue3 - i18n - 您正在运行 vue-i18n 的 esm-bundler 构建

Angular 国际化 ( ngx-translate/i18n OR i18next )

javascript - 如何等待 Angular 模块加载?

typescript - 未捕获的 TypeError : i18next. init 不是一个函数

javascript - 使用 I18Next 和 Aurelia 进行动态翻译

jquery 以编程方式使用 i18n 值

reactjs - 从数据库而不是浏览器 i18next 获取语言环境

jquery - i18next 不与 RequireJS 一起使用