vue.js - vue-i18n:有没有办法在 $t 方法中手动设置语言环境?
问题描述
我正在使用 Firestore 和 vue-18n 开发一个项目。我想要的是将翻译后的消息保存到 Firestore 中,并且我想在$t
方法中手动设置语言环境。我的代码是这样的。
methods: {
doSomething() {
...
db.collection('messages').add({
body: this.$t('componentName.hello'), // I want to set a locale here
})
}
}
有没有办法在$t
方法内部设置语言环境?
解决方案
...
body: this.$t('componentName.hello', locale), //for example "en"
...
来源:https ://github.com/kazupon/vue-i18n/blob/5.x/gitbook/api.md#tkeypath-lang-arguments
推荐阅读
- javascript - 是否可以在引导程序 4 中显示下一个和上一个滑块图像,而不是下一个和上一个箭头?
- java - RestTemplate GET 调用给出 422
- python - 将相同的字符放在字符串中的两个不同位置
- reactjs - React map() - 未捕获的类型错误:无法读取未定义的属性“类别”
- python - 基于python中另一个数组上的重复值合并数组?
- angular - 在数据可用之前调用 ngrx 选择器
- kotlin - 在 Kotlin、Spring Boot 和 Thymeleaf 模板中使用抽象数据类型
- python - 2个RPis(主/从)之间的蓝牙套接字上的Python双向通信
- html - 如何垂直居中水平滚动div
- python - **更新**基于用户定义方法的 Python 编程