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

Commit 82543de

Browse files
committedJul 9, 2019
⭐ new(mixin): shared locale messages feature
1 parent a17660f commit 82543de

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎src/mixin.js

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export default {
5555
}
5656
}
5757

58+
const { sharedMessages } = options.i18n
59+
if (sharedMessages && isPlainObject(sharedMessages)) {
60+
options.i18n.messages = merge(options.i18n.messages, sharedMessages)
61+
}
62+
5863
this._i18n = new VueI18n(options.i18n)
5964
this._i18nWatcher = this._i18n.watchI18nData()
6065

‎test/unit/component.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ describe('component translation', () => {
3535
messages: {
3636
'en-US': { who: 'child1' },
3737
'ja-JP': { who: '子1' }
38+
},
39+
sharedMessages: { // shared messages for child1 component
40+
'en-US': { foo: { bar: 'bar' } },
41+
'ja-JP': { foo: { bar: 'バー' } }
3842
}
3943
},
4044
components: {
@@ -52,6 +56,7 @@ describe('component translation', () => {
5256
h('p', { ref: 'fallback' }, [this.$t('fallback')]),
5357
h('p', { ref: 'datetime' }, [this.$d(dt, 'short')]),
5458
h('p', { ref: 'number' }, [this.$n(money, 'currency')]),
59+
h('p', { ref: 'shared' }, [this.$t('foo.bar')]),
5560
h('sub-child1', { ref: 'sub-child1' })
5661
])
5762
}
@@ -97,6 +102,7 @@ describe('component translation', () => {
97102
const child1Fallback = vm.$refs.child1.$refs.fallback
98103
const child1DateTime = vm.$refs.child1.$refs.datetime
99104
const child1Number = vm.$refs.child1.$refs.number
105+
const child1Shared = vm.$refs.child1.$refs.shared
100106
const child2 = vm.$refs.child2.$refs.who
101107
const subChild1 = vm.$refs.child1.$refs['sub-child1'].$refs.who
102108
const subChild2 = vm.$refs.child2.$refs['sub-child2'].$refs.who
@@ -107,6 +113,8 @@ describe('component translation', () => {
107113
// NOTE: avoid webkit(phatomjs/safari) & Intl polyfill wired localization...
108114
isChrome && assert.strictEqual(child1DateTime.textContent, '12/19/2012, 10:00 PM')
109115
isChrome && assert.strictEqual(child1Number.textContent, '$101.00')
116+
assert.strictEqual(child1Shared.textContent, 'bar')
117+
110118
assert.strictEqual(child2.textContent, 'ルート')
111119
assert.strictEqual(subChild1.textContent, 'ルート')
112120
assert.strictEqual(subChild2.textContent, 'サブの子2')

0 commit comments

Comments
 (0)
This repository has been archived.