From d9ceddc7e73098ffc7e84da810a3f7127b0cf5ce Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 12 Jun 2017 17:04:40 +0900 Subject: [PATCH] :bug: bug(fallback): fix fallback locale issue close #174 --- src/mixin.js | 1 + test/unit/issues.test.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/mixin.js b/src/mixin.js index e0b88c75c..2bcf2ebb4 100644 --- a/src/mixin.js +++ b/src/mixin.js @@ -29,6 +29,7 @@ export default { // component local i18n if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) { options.i18n.root = this.$root.$i18n + options.i18n.fallbackLocale = this.$root.$i18n.fallbackLocale options.i18n.silentTranslationWarn = this.$root.$i18n.silentTranslationWarn } diff --git a/test/unit/issues.test.js b/test/unit/issues.test.js index 29ab810cb..9b14ac1af 100644 --- a/test/unit/issues.test.js +++ b/test/unit/issues.test.js @@ -132,4 +132,44 @@ describe('issues', () => { }).then(done) }) }) + + describe('#174', () => { + it('should be fallback', done => { + vm = new Vue({ + i18n: new VueI18n({ + locale: 'en', + fallbackLocale: 'ja', + messages: { + en: {}, + ja: { msg: 'メッセージ' } + } + }), + components: { + comp: { + i18n: { + messages: { + en: {}, + ja: { hello: 'こんにちは' } + } + }, + render (h) { + return h('div', [ + h('p', { ref: 'el1' }, [this.$t('hello')]), + h('p', { ref: 'el2' }, [this.$t('msg')]) + ]) + } + } + }, + render (h) { + return h('div', [h('comp', { ref: 'comp' })]) + } + }).$mount() + const el1 = vm.$refs.comp.$refs.el1 + const el2 = vm.$refs.comp.$refs.el2 + nextTick(() => { + assert.equal(el1.textContent, 'こんにちは') + assert.equal(el2.textContent, 'メッセージ') + }).then(done) + }) + }) })