【问题标题】:NuxtJS - i18n - Initialize plugin (vue-fb-customer-chat) with the current localeNuxtJS - i18n - 使用当前语言环境初始化插件(vue-fb-customer-chat)
【发布时间】:2020-11-29 18:44:09
【问题描述】:

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

这是一个多语言网站,我需要能够以正确的语言加载聊天(来自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

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

提前感谢您的帮助。

【问题讨论】:

    标签: javascript internationalization nuxtjs nuxt-i18n


    【解决方案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'
        })
    }
    

    【讨论】:

      猜你喜欢
      • 2023-01-04
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 2018-12-06
      • 2011-08-31
      • 2021-10-06
      • 2019-12-17
      • 1970-01-01
      相关资源
      最近更新 更多