1

我已经vue-fb-customer-chat在我的 NuxtJS 网站上成功安装了该插件,并且聊天工作正常。

这是一个多语言网站,我需要能够以正确的语言(nuxt-i18n模块中的当前语言环境)加载聊天。如果在从网站内切换语言后聊天没有更改其语言,那没关系,但我希望在页面加载时至少有正确的语言。

这是plugins/vue-fb-customer-chat.js文件的内容:

import Vue from 'vue'
import VueFbCustomerChat from 'vue-fb-customer-chat'

Vue.use(VueFbCustomerChat, {
    page_id: null, //  change 'null' to your Facebook Page ID,
    theme_color: '#845e5c', // theme color in HEX
    locale: 'fr_FR', // default 'en_US'
})

以下均无效:

context.app.i18n.locale
this.$i18n.locale
$i18n.locale

解决这个问题的方法是什么?

提前感谢您的帮助。

4

1 回答 1

1

我的同事回答了我的问题。

import Vue from 'vue'
import VueFbCustomerChat from 'vue-fb-customer-chat'

export default function (context) {
    const locale = context.app.i18n.locale;
    const iso = context.app.i18n.locales.find(l => l.code === locale).iso;

    Vue.use(VueFbCustomerChat, {
        page_id: null, //  change 'null' to your Facebook Page ID,
        theme_color: '#845e5c', // theme color in HEX
        locale: iso.replace('-', '_'), // default 'en_US'
    })
}
于 2020-12-02T13:44:57.923 回答