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

Commit c973619

Browse files
committed
🐛 bug: fix cannnot resolve linked localization with component interpolation
Close #171
1 parent 6e9f151 commit c973619

3 files changed

Lines changed: 34 additions & 16 deletions

File tree

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ export default class VueI18n {
197197
// Remove the leading @:
198198
const linkPlaceholder: string = link.substr(2)
199199
// Translate the link
200-
const translated: any = this._interpolate(message, linkPlaceholder, interpolateMode, values)
201-
if (interpolateMode === 'raw') {
202-
return translated
203-
}
200+
const translated: any = this._interpolate(
201+
message, linkPlaceholder,
202+
interpolateMode === 'raw' ? 'string' : interpolateMode,
203+
interpolateMode === 'raw' ? undefined : values
204+
)
204205
// Replace the link with the translated
205206
ret = ret.replace(link, translated)
206207
}

test/unit/fixture/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default {
1515
linkMultiple: 'Hello @:message.hoge!, isn\'t @:message.hello great?',
1616
linkHyphen: '@:hyphen-hello',
1717
linkUnderscore: '@:underscore_hello',
18+
linkList: '@:message.hello: {0} {1}',
1819
'hyphen-locale': 'hello hyphen',
1920
'1234': 'Number-based keys are found',
2021
'1mixedKey': 'Mixed keys are not found.'
@@ -23,7 +24,9 @@ export default {
2324
'Hello {0}': 'Hello {0}',
2425
'continue-with-new-account': 'continue with new account',
2526
'hyphen-hello': 'hyphen the wolrd',
27+
/* eslint-disable */
2628
underscore_hello: 'underscore the wolrd',
29+
/* eslint-enable */
2730
underscore: '{helloMsg} world',
2831
plurals: {
2932
car: 'car | cars',

test/unit/issues.test.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import messages from './fixture/index'
22

33
describe('issues', () => {
4-
let vm
4+
let vm, i18n
55
beforeEach(() => {
6-
vm = new Vue({
7-
i18n: new VueI18n({
8-
locale: 'en',
9-
messages
10-
})
6+
i18n = new VueI18n({
7+
locale: 'en',
8+
messages
119
})
10+
vm = new Vue({ i18n })
1211
})
1312

1413

@@ -81,12 +80,7 @@ describe('issues', () => {
8180
return h('p', { ref: 'custom' }, [this.$t('custom')])
8281
}
8382
})
84-
const vm = new Component({
85-
i18n: new VueI18n({
86-
locale: 'en',
87-
messages
88-
})
89-
}).$mount()
83+
const vm = new Component({ i18n }).$mount()
9084
nextTick(() => {
9185
assert.equal(vm.$refs.custom.textContent, 'custom block!')
9286
}).then(done)
@@ -99,4 +93,24 @@ describe('issues', () => {
9993
assert.equal(vm.$i18n.t('message.linkUnderscore'), messages.en.underscore_hello)
10094
})
10195
})
96+
97+
describe('#171', () => {
98+
it('should be translated', done => {
99+
vm = new Vue({
100+
i18n,
101+
render (h) {
102+
return h('i18n', { props: { path: 'message.linkList' } }, [
103+
h('strong', [this.$t('underscore_hello')]),
104+
h('strong', [this.$t('message.link')])
105+
])
106+
}
107+
}).$mount()
108+
nextTick(() => {
109+
assert.equal(
110+
vm.$el.innerHTML,
111+
'the world: <strong>underscore the wolrd</strong> <strong>the world</strong>'
112+
)
113+
}).then(done)
114+
})
115+
})
102116
})

0 commit comments

Comments
 (0)