Skip to content

Commit

Permalink
🐛 bug(index): fix merge bug
Browse files Browse the repository at this point in the history
closes #458
  • Loading branch information
kazupon committed Nov 8, 2018
1 parent 4895a2e commit 1798490
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isObject,
looseClone,
remove,
merge,
canUseDateTimeFormat,
canUseNumberFormat
} from './util'
Expand Down Expand Up @@ -460,7 +461,7 @@ export default class VueI18n {
}

mergeLocaleMessage (locale: Locale, message: LocaleMessageObject): void {
this._vm.$set(this._vm.messages, locale, Vue.util.extend(this._vm.messages[locale] || {}, message))
this._vm.$set(this._vm.messages, locale, merge(this._vm.messages[locale] || {}, message))
}

getDateTimeFormat (locale: Locale): DateTimeFormat {
Expand All @@ -472,7 +473,7 @@ export default class VueI18n {
}

mergeDateTimeFormat (locale: Locale, format: DateTimeFormat): void {
this._vm.$set(this._vm.dateTimeFormats, locale, Vue.util.extend(this._vm.dateTimeFormats[locale] || {}, format))
this._vm.$set(this._vm.dateTimeFormats, locale, merge(this._vm.dateTimeFormats[locale] || {}, format))
}

_localizeDateTime (
Expand Down Expand Up @@ -568,7 +569,7 @@ export default class VueI18n {
}

mergeNumberFormat (locale: Locale, format: NumberFormat): void {
this._vm.$set(this._vm.numberFormats, locale, Vue.util.extend(this._vm.numberFormats[locale] || {}, format))
this._vm.$set(this._vm.numberFormats, locale, merge(this._vm.numberFormats[locale] || {}, format))
}

_localizeNumber (
Expand Down
6 changes: 3 additions & 3 deletions test/unit/datetime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ desc('datetime format', () => {
locale: 'ja-JP',
dateTimeFormats
})
const short = {
const foo = {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit'
}
i18n.mergeDateTimeFormat('en-US', { short })
assert.deepEqual(short, i18n.getDateTimeFormat('en-US').short)
i18n.mergeDateTimeFormat('en-US', { foo })
assert.deepEqual(foo, i18n.getDateTimeFormat('en-US').foo)
})
})
})
40 changes: 40 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,44 @@ describe('issues', () => {
})
})
})

describe('#458', () => {
it('should be merged locale message', done => {
const vm = new Vue({
i18n: new VueI18n({
locale: 'en',
messages: {
hello: 'hello world!'
}
}),
render (h) {
return h('div', [
h('p', { ref: 'text1' }, [this.$t('key1')]),
h('p', { ref: 'text2' }, [this.$t('shared.key1')]),
h('p', { ref: 'text3' }, [this.$t('key2')]),
h('p', { ref: 'text4' }, [this.$t('shared.key2')])
])
}
}).$mount()
nextTick(() => {
vm.$i18n.mergeLocaleMessage('en', {
key1: 'Hello Module 1',
shared: {
key1: 'Hello Module 1 shared key 1'
}
})
vm.$i18n.mergeLocaleMessage('en', {
key2: 'Hello Module 2',
shared: {
key2: 'Hello Module 2 shared key 2'
}
})
}).then(() => {
assert.equal(vm.$refs.text1.textContent, 'Hello Module 1')
assert.equal(vm.$refs.text2.textContent, 'Hello Module 1 shared key 1')
assert.equal(vm.$refs.text3.textContent, 'Hello Module 2')
assert.equal(vm.$refs.text4.textContent, 'Hello Module 2 shared key 2')
}).then(done)
})
})
})

0 comments on commit 1798490

Please sign in to comment.