diff --git a/src/mixin.js b/src/mixin.js index 0190b1650..76c88e10b 100644 --- a/src/mixin.js +++ b/src/mixin.js @@ -13,7 +13,7 @@ export default { // init locale messages via custom blocks if (options.__i18n) { try { - let localeMessages = {} + let localeMessages = options.i18n && options.i18n.messages ? options.i18n.messages : {} options.__i18n.forEach(resource => { localeMessages = merge(localeMessages, JSON.parse(resource)) }) @@ -47,7 +47,7 @@ export default { // init locale messages via custom blocks if (options.__i18n) { try { - let localeMessages = {} + let localeMessages = options.i18n && options.i18n.messages ? options.i18n.messages : {} options.__i18n.forEach(resource => { localeMessages = merge(localeMessages, JSON.parse(resource)) }) diff --git a/test/unit/issues.test.js b/test/unit/issues.test.js index 384b7fd31..a97903992 100644 --- a/test/unit/issues.test.js +++ b/test/unit/issues.test.js @@ -770,4 +770,24 @@ describe('issues', () => { assert.strictEqual(componentInstanceCreatedListener.args[0][1], i18n) }) }) + + describe('#996', () => { + it('should merge __i18n and i18n', done => { + const Component = Vue.extend({ + __i18n: [JSON.stringify({ en: { custom: 'custom block!' } })], + render (h) { + return h('p') + } + }) + const vm = new Component({ + i18n: new VueI18n({ locale: 'en', messages: { en: { another: 'another block!' } } }) + }).$mount() + + Vue.nextTick().then(() => { + assert.strictEqual(vm.$t('another'), 'another block!') + assert.strictEqual(vm.$t('custom'), 'custom block!') + }).then(done) + .catch(console.error) + }) + }) })