Skip to content

Commit

Permalink
🐛 bug(fallback): fix cannot fallabck localization
Browse files Browse the repository at this point in the history
close #176
  • Loading branch information
kazupon committed Jun 12, 2017
1 parent 0c572f3 commit 694e6f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand Down
37 changes: 37 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})

0 comments on commit 694e6f2

Please sign in to comment.