Skip to content

Commit

Permalink
🐛 bug: fix cannnot resolve linked localization with component interpo…
Browse files Browse the repository at this point in the history
…lation

Close #171
  • Loading branch information
kazupon committed Jun 4, 2017
1 parent 6e9f151 commit c973619
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ export default class VueI18n {
// Remove the leading @:
const linkPlaceholder: string = link.substr(2)
// Translate the link
const translated: any = this._interpolate(message, linkPlaceholder, interpolateMode, values)
if (interpolateMode === 'raw') {
return translated
}
const translated: any = this._interpolate(
message, linkPlaceholder,
interpolateMode === 'raw' ? 'string' : interpolateMode,
interpolateMode === 'raw' ? undefined : values
)
// Replace the link with the translated
ret = ret.replace(link, translated)
}
Expand Down
3 changes: 3 additions & 0 deletions test/unit/fixture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
linkMultiple: 'Hello @:message.hoge!, isn\'t @:message.hello great?',
linkHyphen: '@:hyphen-hello',
linkUnderscore: '@:underscore_hello',
linkList: '@:message.hello: {0} {1}',
'hyphen-locale': 'hello hyphen',
'1234': 'Number-based keys are found',
'1mixedKey': 'Mixed keys are not found.'
Expand All @@ -23,7 +24,9 @@ export default {
'Hello {0}': 'Hello {0}',
'continue-with-new-account': 'continue with new account',
'hyphen-hello': 'hyphen the wolrd',
/* eslint-disable */
underscore_hello: 'underscore the wolrd',
/* eslint-enable */
underscore: '{helloMsg} world',
plurals: {
car: 'car | cars',
Expand Down
38 changes: 26 additions & 12 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import messages from './fixture/index'

describe('issues', () => {
let vm
let vm, i18n
beforeEach(() => {
vm = new Vue({
i18n: new VueI18n({
locale: 'en',
messages
})
i18n = new VueI18n({
locale: 'en',
messages
})
vm = new Vue({ i18n })
})


Expand Down Expand Up @@ -81,12 +80,7 @@ describe('issues', () => {
return h('p', { ref: 'custom' }, [this.$t('custom')])
}
})
const vm = new Component({
i18n: new VueI18n({
locale: 'en',
messages
})
}).$mount()
const vm = new Component({ i18n }).$mount()
nextTick(() => {
assert.equal(vm.$refs.custom.textContent, 'custom block!')
}).then(done)
Expand All @@ -99,4 +93,24 @@ describe('issues', () => {
assert.equal(vm.$i18n.t('message.linkUnderscore'), messages.en.underscore_hello)
})
})

describe('#171', () => {
it('should be translated', done => {
vm = new Vue({
i18n,
render (h) {
return h('i18n', { props: { path: 'message.linkList' } }, [
h('strong', [this.$t('underscore_hello')]),
h('strong', [this.$t('message.link')])
])
}
}).$mount()
nextTick(() => {
assert.equal(
vm.$el.innerHTML,
'the world: <strong>underscore the wolrd</strong> <strong>the world</strong>'
)
}).then(done)
})
})
})

0 comments on commit c973619

Please sign in to comment.