this.$i18n.locales undefined when specifying i18n options through component option
See original GitHub issueVersion
Reproduction link
https://nuxt-community.github.io/nuxt-i18n/lang-switcher.html
Steps to reproduce
Follow the steps on the first section of Lang Switcher
What is expected ?
this.$i18n.locales should contain an array of 3 objects which are defined in nuxt.js.config.
What is actually happening?
this.$i18n.locales
is undefined
TypeError
Cannot read property 'filter' of undefined
Additional comments?
this.$i18n.availableLocales returns an array ['en','es','fr]
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
this.$i18n.locales undefined when specifying i18n options ...
When there is custom i18n block in a component then options.__i18n is set to plain JSON object and a local $i18n property is...
Read more >nuxt-i18n: Lang Switcher Error "Object is possibly 'undefined'
I want to build a language switcher on my nuxt app with nuxt-i18n plugin. Important note is, that ...
Read more >Composition API - Vue I18n
In Legacy API mode, VueI18n instance is created by specifying the i18n component option for each component. This enables resources such as local...
Read more >API references | Vue I18n
API references. # Extension of Vue. # Vue constructor options. # i18n. Type: I18nOptions. Component based localization option.
Read more >How to Load i18n Locales Asynchronously in Vue 3 + Vite
The <select> element is populated with options by looping through the list of all available locales, allLocales , as defined in the i18n.js...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Codesandbox sample: https://codesandbox.io/s/i18n-plugin-i18nlocales-it7n5
The
$i18n
property of current component will get override withoutnuxt-i18n
augmentation if there is an<i18n>
tag exist in the SFC withvueI18nLoader
enabled innuxt.config.js
In my test, the format of i18n does not affect this bug. Whether it’s yaml or with
locale
defined will trigger this bugOne workaround (hack) would be to use parent’s
$i18n
, provided parent is not using<i18n>
tagOk thank you this is weird if I do this in your code :
I can indeed see that
this.$i18n.locales
is well defined. Something is preventing that on my side…This is part of my nuxt.config.js. Note that I have defined my locales in the i18n part not the modules one. Can it be the cause ?
edit: I tested putting locales in the modules part same problem it is still undefined edit2: I copy/pasted the i18n part on your sandbox it also works…