bootstrap-vue / bootstrap-vue

BootstrapVue provides one of the most comprehensive implementations of Bootstrap v4 for Vue.js. With extensive and automated WAI-ARIA accessibility markup.
https://bootstrap-vue.org
MIT License
14.52k stars 1.88k forks source link

BVConfigPlugin and i18n #7092

Closed chWagnr closed 3 months ago

chWagnr commented 1 year ago

Describe the bug

I define the default settings like it is described in example 3 from the documentation (https://bootstrap-vue.org/docs/reference/settings#setting-config-via-individual-component-group-plugin-imports). For localization I use vue-i18n, also in the default settings. Changing the language by an user does not show any effect in the bootstrap components.

Steps to reproduce the bug

Vue.use(VueI18n);

const i18n = new VueI18n({
    messages: {
        de: {
            no_items_found: 'Keine Eintrage gefunden'
        },
        en: {
            no_items_found: 'No items found'
        }
    },
    locale: 'de',
    fallbackLocale: 'en'
});

Vue.use(BVConfigPlugin, {
    BTable: {
        emptyText: i18n.t('no_items_found')
    }
});

when calling i18n.locale = 'en' the emptyText will remain in German

Expected behavior

Components should show the correct translations.

Versions

Libraries:

Am I doing something wrong? Changing the language is working for the rest of the frontend, but for the defaults. Or is there a better way to set the defaults?

Hiws commented 1 year ago

I'd say this behavior is expected.

What you could try to fix it is to make it computed.

import { computed } from "vue"
Vue.use(VueI18n);

const i18n = new VueI18n({
    messages: {
        de: {
            no_items_found: 'Keine Eintrage gefunden'
        },
        en: {
            no_items_found: 'No items found'
        }
    },
    locale: 'de',
    fallbackLocale: 'en'
});

Vue.use(BVConfigPlugin, {
    BTable: {
        emptyText: computed(() => i18n.t('no_items_found'))
    }
});

If that doesn't work, then you'll likely have to make a wrapper component instead which has your basic configs.

chWagnr commented 1 year ago

Hi, thanks for your help. computed didn't work, but just a simple function like this: emptyText: () => i18n.t('no_items_found')