Skip to content

Commit

Permalink
🐛 bug(mixin): fix cannot setup VueI18n instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Aug 3, 2017
1 parent db90f2f commit 13585a4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export default {
this._i18n = this.$root.$i18n
this._i18n.subscribeDataChanging(this)
this._subscribing = true
} else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) {
// parent i18n
this._i18n = options.parent.$i18n
this._i18n.subscribeDataChanging(this)
this._subscribing = true
}
},

Expand Down
32 changes: 32 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,36 @@ describe('issues', () => {
assert.equal(tokens[1].value, '% PREPAYMENT')
})
})

describe('#203', () => {
it('should be translated', done => {
const App = {
render (h) {
return h('p', { ref: 'app' }, [this.$t('hello')])
}
}
vm = new Vue({
render (h) {
return h({
components: { App },
render (h) { return h('app') },
i18n: new VueI18n({
locale: 'en',
messages: {
en: {
'hello': 'hello 203'
},
ja: {
'hello': 'こんにちは 203'
}
}
})
})
}
}).$mount()
nextTick(() => {
assert.equal(vm.$el.innerHTML, 'hello 203')
}).then(done)
})
})
})

1 comment on commit 13585a4

@romulof
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for preferring $root.$i18n over parent.$i18n?
I think this creates a weird behavior, because normally thing kind of stuff follows the component tree.

Please sign in to comment.