javascript - 在 vue i18n 中分别使用数字和消息本地化
问题描述
我想使用 Vue I18n 为我的网络应用程序进行货币、日期和消息本地化。用户可以单独配置语言和使用的货币格式。例如:一位德国用户想要一个英文本地化网站,但货币格式应为 EUR 和“de-DE”。
是否可以使用 Vue I18n 构建它?像货币的单独语言环境配置?
我可以在模板中传递 BCP 47 语言代码,但是我必须为每个组件加载当前配置的语言代码。我想更动态地解决这个问题。
<p>{{ $n(price, 'currency', currentLanguageCode) }}</p>
const numberFormats = {
'en-US': {
currency: {
style: 'currency', currency: 'USD'
}
},
'de-DE': {
currency: {
style: 'currency', currency: 'EUR'
}
},
'de-CH': {
currency: {
style: 'currency', currency: 'CHF'
}
}
}
const i18n = new VueI18n({
numberFormats,
messages: {
en: {
test: 'test message'
},
de: {
test: 'Testnachricht'
}
},
locale: 'de',
fallbackLocale: 'de'
})
解决方案
推荐阅读
- reactjs - 类型错误:ownProps.match 未定义
- php - Laravel DB 查询 WHERE 日期大于不使用 JOIN
- flutter - 有没有一种简单的方法可以在颤振中实现底部播放器?
- javascript - 在 useEffect 钩子完成之前 ReactJS 认证路由组件渲染
- r - 如何为 R 中每个类别的最后一个值增加价值?
- windows - 我的批处理脚本不起作用,我不知道为什么
- oauth-2.0 - 在 Oauth2 身份验证代码流的 Web 浏览器中运行的单页应用程序 (SPA) 的正确重定向 URI 是什么?
- javascript - 通过 jQuery ajax 使用 Coldfusion 删除文件
- javascript - 使用节点 js 进行分页
- plugins - nuxt 在哪里存储仅用于某些组件的附加逻辑