Skip to content

Commit

Permalink
🐛 bug(install): add support for Vue.extend vue-i18n instance (#420) by
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredzhu1993 authored and kazupon committed Sep 3, 2018
1 parent 170f691 commit a60ea8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export function install (_Vue) {
Vue.directive('t', { bind, update, unbind })
Vue.component(component.name, component)

// use object-based merge strategy
// use simple mergeStrategies to prevent i18n instance lose '__proto__'
const strats = Vue.config.optionMergeStrategies
strats.i18n = strats.methods
strats.i18n = function (parentVal, childVal) {
return childVal === undefined
? parentVal
: childVal
}
}
13 changes: 13 additions & 0 deletions test/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,19 @@ describe('basic', () => {
})
})

describe('i18n#Vue.extend({ i18n })', () => {
it('should be translated', () => {
const el = document.createElement('div')
const Constructor = Vue.extend({ i18n })
const vm = new Constructor({
render (h) {
return h('p', { ref: 'text' }, [this.$t('message.hello')])
}
}).$mount(el)
assert.equal(vm.$refs.text.textContent, messages.en.message.hello)
})
})

let desc = VueI18n.availabilities.dateTimeFormat ? describe : describe.skip
desc('i18n#d', () => {
let dt
Expand Down

0 comments on commit a60ea8b

Please sign in to comment.