Vue-i18n: props don't work in component i18n option

Created on 21 Sep 2017  路  2Comments  路  Source: kazupon/vue-i18n

"vue": "^2.4.2",
"vue-i18n": "^7.2.0",

// signup.js
let signup = {
  en: { 'signup': 'Sign up' },
  ru: { 'signup': '袪械谐懈褋褌褉邪褑懈褟' },
  kz: { 'signup': 'Tirkelw' }
}
export default signup
//component.vue
...
<script>
  export default {
    props: {
      langFileName: String // 'signup'
    },
    mounted () {
      console.log(this.langFile) // 'signup'
    },
    i18n: {messages: require('@/lang/' + this.langFile).default} // Cannot find module './undefined'
  }
</script>

or

//component.vue
...
<script>
  export default {
    props: {
      messages: Object // signup.js object
    },
    mounted () {
      console.log(this.messages) // signup.js object
    },
    i18n: {messages: this.messages} // typeof this.messages - undefined
  }
</script>

Most helpful comment

so, how to send object with messages from parent component to i18n option of child component?
i18n option of child component don't see props, but other options are seen

All 2 comments

Thank you for reporting!
sorry, for my late response.

In about i18n: {messages: require('@/lang/' + this.langFile).default}, I seem langFile prop is not inialized.

In about i18n: {messages: this.messages}, In this case, The context of this.messages is <script> tag, so you need to fix.

please, I hope you will check the code once again.

so, how to send object with messages from parent component to i18n option of child component?
i18n option of child component don't see props, but other options are seen

Was this page helpful?
0 / 5 - 0 ratings