From 694e6f2fe73daf6a9f8b35ef6b78624e318d49aa Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Tue, 13 Jun 2017 02:26:56 +0900 Subject: [PATCH] :bug: bug(fallback): fix cannot fallabck localization close #176 --- src/index.js | 2 +- test/unit/issues.test.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 79bc7e5ce..a9adc8035 100644 --- a/src/index.js +++ b/src/index.js @@ -262,7 +262,7 @@ export default class VueI18n { this._interpolate(locale, messages[locale], key, host, interpolateMode, args) if (!isNull(res)) { return res } - res = this._interpolate(fallback, messages[fallback], key, host, args) + res = this._interpolate(fallback, messages[fallback], key, host, interpolateMode, args) if (!isNull(res)) { if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) { warn(`Fall back to translate the keypath '${key}' with '${fallback}' locale.`) diff --git a/test/unit/issues.test.js b/test/unit/issues.test.js index ca119f28f..06d787770 100644 --- a/test/unit/issues.test.js +++ b/test/unit/issues.test.js @@ -204,4 +204,41 @@ describe('issues', () => { }).then(done) }) }) + + describe('#176', () => { + it('should be translated', done => { + vm = new Vue({ + i18n: new VueI18n({ + locale: 'xx', + fallbackLocale: 'en', + messages: { + en: { + 'alpha': '[EN] alpha {gustav} value', + 'bravo': '[EN] bravo {gustav} value', + 'charlie': '[EN] charlie {0} value', + 'delta': '[EN] delta {0} value' + }, + xx: { + 'bravo': '[XX] bravo {gustav} value', + 'delta': '[XX] delta {0} value' + } + } + }), + render (h) { + return h('div', [ + h('p', { ref: 'el1' }, [this.$t('alpha', { gustav: 'injected' })]), + h('p', { ref: 'el2' }, [this.$t('bravo', { gustav: 'injected' })]), + h('p', { ref: 'el3' }, [this.$t('charlie', ['injected'])]), + h('p', { ref: 'el4' }, [this.$t('delta', ['injected'])]) + ]) + } + }).$mount() + nextTick(() => { + assert.equal(vm.$refs.el1.textContent, '[EN] alpha injected value') + assert.equal(vm.$refs.el2.textContent, '[XX] bravo injected value') + assert.equal(vm.$refs.el3.textContent, '[EN] charlie injected value') + assert.equal(vm.$refs.el4.textContent, '[XX] delta injected value') + }).then(done) + }) + }) })