【问题标题】:vue-i18n: Is there a way to set a locale manually inside $t method?vue-i18n:有没有办法在 $t 方法中手动设置语言环境?
【发布时间】:2020-01-15 08:29:50
【问题描述】:

我正在开发一个使用 Firestore 和 vue-18n 的项目。我想要将翻译后的消息保存到 Firestore 中,并且我想在 $t 方法中手动设置语言环境。我的代码是这样的。

methods: {
    doSomething() {
        ...
        db.collection('messages').add({
            body: this.$t('componentName.hello'), // I want to set a locale here
        })
    }
}

有没有办法在$t 方法中设置语言环境?

【问题讨论】:

    标签: vue.js vue-i18n


    【解决方案1】:
    ...
     body: this.$t('componentName.hello', locale), //for example "en"
    ...
    

    来源:https://github.com/kazupon/vue-i18n/blob/5.x/gitbook/api.md#tkeypath-lang-arguments

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-04-01
      • 2021-02-12
      • 1970-01-01
      • 2019-08-03
      相关资源
      最近更新 更多