diff --git a/src/install.js b/src/install.js index 8066afd57..a93ce41ce 100644 --- a/src/install.js +++ b/src/install.js @@ -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 + } } diff --git a/test/unit/basic.test.js b/test/unit/basic.test.js index 78b88e9b1..44c7598bb 100644 --- a/test/unit/basic.test.js +++ b/test/unit/basic.test.js @@ -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