Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Vue.extend vue-i18n instance #420

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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