bundle-tools icon indicating copy to clipboard operation
bundle-tools copied to clipboard

Compatibility with nuxt-i18n

Open arambert opened this issue 6 years ago • 3 comments

The problem

nuxt-i18n creates an augmented VueI18n instance in this.$root.$i18n and expects vue-i18n to use it as value in _i18n (https://github.com/kazupon/vue-i18n/blob/d28e3b25d9bd9eac51fc3714a4a2940772d85c3d/src/mixin.js#L69)

But when one uses custom i18n blocks in the component with vue-i18n-loader, it fills this.$options.__i18n in the component which is picked up by https://github.com/kazupon/vue-i18n/blob/master/src/mixin.js#L9 and the this.$root.$i18n instance is never set in this._i18n.

The consequence is that this.$i18n in the component is a new basic VueI18n instance and not the nuxt-i18n augmented VueI18n instance. Such attributes as "locales" or "differentDomains" are therefore not accessible from the component and the nuxt-i18n method "switchLocalePath" is broken when using differentDomains with nuxt-i18n.

Here is the link to the comment I posted in the nuxt-i18n project: https://github.com/nuxt-community/nuxt-i18n/issues/205#issuecomment-498763751.

Suggested solution

vue-i18n-loader could use an explicit key instead of the cryptic __i18n, like _i18n_translations for instance. Then vue-i18n would handle the key specifically when present (independently from the different scenarii for setting up this._i18n), as opposed to seed option.i18n with __i18n

What are your thoughts on this?

arambert avatar Jun 05 '19 07:06 arambert

I just ran into this issue, also (not being able to access this.$i18n.locales.

sustained avatar Jul 12 '19 13:07 sustained

This should be fixed in nuxt-i18n. It uses a hook provided by vue-i18n the extend the local vue-i18n instance.

rchl avatar Apr 07 '21 19:04 rchl

I'd say this is fixed in nuxt-i18n already.

rchl avatar Jul 04 '21 18:07 rchl

close in-activity

kazupon avatar Nov 16 '22 01:11 kazupon