Skip to content

Commit

Permalink
🐛 bug(formatter): Inherit formatter (#269) by @podkot
Browse files Browse the repository at this point in the history
* root.formatter should be inherited by components

* codestyle

* test on formatter inheritance
  • Loading branch information
podkot authored and kazupon committed Jan 7, 2018
1 parent fc1a267 commit 26a33ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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.formatter = this.$root.$i18n.formatter
options.i18n.fallbackLocale = this.$root.$i18n.fallbackLocale
options.i18n.silentTranslationWarn = this.$root.$i18n.silentTranslationWarn
}
Expand Down
43 changes: 43 additions & 0 deletions test/unit/format_custom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,49 @@ describe('custom formatter', () => {
})
})

describe('via vue instance calling (mounted)', () => {
let el

beforeEach(done => {
el = document.createElement('div')
done()
})

it('should be inherited by components', done => {
new Vue({
i18n: new VueI18n({
locale: 'en',
formatter: {
interpolate: (message, values) => {
assert.deepEqual({ name: 'user' }, values)
done()
return ['pass']
}
}
}),
components: {
'child-1': {
render (h) {
return h('div', {}, [
h('p', {}, [this.$t('message', { name: 'user' })])
])
},
i18n: {
messages: {
en: { message: 'hello {name}' }
}
}
}
},
render (h) {
return h('div', {}, [
h('child-1')
])
}
}).$mount(el)
})
})

describe('i18n format getter/settter', () => {
it('should be worked', done => {
const i18n = new VueI18n({
Expand Down

0 comments on commit 26a33ad

Please sign in to comment.