yariksav / vuetify-dialog

Easy dialogs in Vuetify.js framework
MIT License
195 stars 48 forks source link

$i18n not available with custom Dialog #121

Closed emulienfou closed 3 years ago

emulienfou commented 3 years ago

Hello there, just create a custom dialog an I cannot use this.$t() or this.$i18n.t() inside the custom Dialog component.

Here is an exemple on how I create a custom dialog:

await this.$dialog.show(CustomDialog, {
   $i18n: this.$i18n // Workaround
})
<template>
  <DialogCard>
      {{ $t('test') }} <!-- Not working without the workaround -->
   </DialogCard>
</template>
<script>
import DialogCard from 'vuetify-dialog/src/components/DialogCard'
export default {
   props: {
     $i18n: Object // Workaround
   }
}
</script>

Without this workaround, I receive the message: "TypeError: Cannot read property 't' of undefined"

yariksav commented 3 years ago

You need to set i18n into context param https://github.com/yariksav/vuetify-dialog#vuetify-2

Vue.use(VuetifyDialog, {
  context: {
    vuetify
  }
})

if you use nuxt, you need to setup through plugin vuetify-dialog/nuxt

if you use native vue, then setup 
Vue.use(VuetifyDialog, {
  context: {
    i18n,
   ...
    vuetify
  }
})
emulienfou commented 3 years ago

Thanks @yariksav working fine