Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Inherit formatter #269

Merged
merged 3 commits into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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