Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.$i18n.locales is undefined when using yaml-loader #205

Closed
jovanmaric opened this issue Jan 30, 2019 · 10 comments
Closed

this.$i18n.locales is undefined when using yaml-loader #205

jovanmaric opened this issue Jan 30, 2019 · 10 comments

Comments

@jovanmaric
Copy link

Version

v5.3.0

Reproduction link

https://github.com/jovanmaric/nuxti18n-yaml

Steps to reproduce

  • Start with yarn dev.
  • Open console to see this.$i18n.locales outputting an array
  • Stop server
  • Uncomment the build configuration in nuxt.config.js
  • Start with yarn dev
  • Open console to see undefined

What is expected ?

That this.$i18n.locales returns the locales array even when using component tags.

What is actually happening?

It seems like either vue-i18n-loader or yaml-loader are polluting the this.$i18n namespace

Additional comments?

I've looked at the src, but im not sure how to fix this without side effects. this.i18n seems to be where Vue-i18n is bound to by default, and nuxt-i18n extends on this behaviour.

This bug report is available on Nuxt community (#c195)
@ghost ghost added the cmty:bug-report label Jan 30, 2019
@jovanmaric
Copy link
Author

jovanmaric commented Feb 7, 2019

On second inspection, it seems that enabling @kazupon/vue-i18n-loader makes this.$i18n unreadable.

Edit:
I can access the locales with:
console.log(this.$parent.$i18n.locales);

@iliyaZelenko
Copy link

@jovanmaric, I watched your code and library code, it's hard to say why this happens, try asking a question in their repository.

@smesterheide
Copy link

The same problem occurs when using Component based localization with vue-i18n. I don't think it's related to YAML.

@smesterheide
Copy link

I just came back to this issue and this time it works. I could be totally off here, but in my code I am no longer using the locales.name property for the lang-switcher.

@jovanmaric
Copy link
Author

jovanmaric commented Apr 18, 2019

I'm unable to test this unfortunately, as I switched to app wide localization, to improve reusability. This issue can be closed as both @iliyaZelenko and @sambrezo are referring to the vue-i18n as the major culprit.

Edit: Hope github delegates the closing of an issue to cmty...... it does

@arambert
Copy link

arambert commented Jun 4, 2019

I'm facing the same issue:

It does not matter if it's YAML or JSON.

I don't know if this bug should be nuxt-i18n responsability or vue-i18n responsability, but there is a bug.

@arambert
Copy link

arambert commented Jun 4, 2019

When I remove the custom i18n block from the component it works again... magic isn't it? ;)

@arambert
Copy link

arambert commented Jun 5, 2019

As a temporary workaround I add these lines in a beforeMount function in the components where I need locales or switchLocalePath:

this.$i18n['differentDomains'] = this.$root.$i18n['differentDomains']
this.$i18n['locales'] = this.$root.$i18n['locales']

@sustained
Copy link

Thanks for the workaround.

@mateusz-owczarek
Copy link

Thanks for the workaround! Just for future reference, if you're using SSR, you should put those two lines in the beforeCreate method. The other lifecycle hooks, except created, are not called server-side. Otherwise, simply use this.$root.$i18n.locales directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants