Closed michahell closed 3 years ago
Hi @michahell,
I tried to reproduce your issue but without success: https://codesandbox.io/s/gridsome-plugin-issue-39-7lhv2 it use the same code:
{
data: function() {
return {
currentLocale: this.$i18n.locale.toString(),
availableLocales: this.$i18n.availableLocales
};
}
}
Maybe can be related to some errors during VueI18n bootstrap: https://github.com/daaru00/gridsome-plugin-i18n/blob/master/gridsome.client.js#L14-L18
Did you see any error in the browser console?
@daaru00 thanks for taking a look! I'm a bit busy the coming week but I will have a look as soon as I can - it must be something specific related to gridsome, the sanity.io blog starter i'm building on top of or something in my gridsome config 🤔
hello @daaru00 ! I tried again to figure out what is wrong, but I don't understand what is happening. It seems that either Vuei18n or the plugin does not start or is not detected entirely - looking at the amount of errors in the console:
[Vue warn]: Error in data(): "TypeError: Cannot read property '$i18n' of undefined"
found in
---> <LocaleSwitcher> at src/components/LocaleSwitcher.vue
<Layout> at src/layouts/Default.vue
<App> at src/App.vue
<Root>
and
vue.runtime.esm.js?2b0e:619 [Vue warn]: Property or method "currentLocale" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <LocaleSwitcher> at src/components/LocaleSwitcher.vue
<Layout> at src/layouts/Default.vue
<App> at src/App.vue
<Root>
and
vue.runtime.esm.js?2b0e:619 [Vue warn]: Property or method "availableLocales" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <LocaleSwitcher> at src/components/LocaleSwitcher.vue
<Layout> at src/layouts/Default.vue
<App> at src/App.vue
<Root>
hmmm, the weird thing is, translation definitely works ánd I don't get any errors whenever I uncomment the LocaleSwitcher
component in my gridsome Layout
. But if I use the default LocaleSwitcher
component, I get all the errors listed above.. 🤔
I can't get any of this to work, now my GQL language queries are failing. I'll just go with one language for now, this is costing me too much precious time right now :( Wish I had the time and knowledge to debug this better, but I don't atm.
Describe the bug I am getting an error in the console after installing the plugin, setting up a basic config and copy pasting the language switcher example component. I feel like I am missing some part of the setup process, but I don't know which...
This is my
gridsome.config.js
plugin config:copy pasting the example language switcher on https://gridsome.org/plugins/gridsome-plugin-i18n:
I can see, after rebuilding (successfully) that my site now has language prefixes, i.e.
/{lang}/blog
etc. etc. However, the $i18n property is not available on the Vue prototype, it seems:To Reproduce Steps to reproduce the behavior: this is my current package.json (based off of the sanity gridsome starter, updating some dependencies and adding others)
Expected behavior I expected the $i18n property to be there and moreover, having a simple language switcher to demo the language switching to work.
Screenshots N/A
Environment (please complete the following information):
Plugin configuration pasted earlier, above