Skip to content

Commit

Permalink
🐛 bug: fix linked translation with using hyphen or underscore keypath
Browse files Browse the repository at this point in the history
Close #170
  • Loading branch information
kazupon committed Jun 4, 2017
1 parent 687d406 commit 6e9f151
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class VueI18n {
// Match all the links within the local
// We are going to replace each of
// them with its translation
const matches: any = ret.match(/(@:[\w|.]+)/g)
const matches: any = ret.match(/(@:[\w\-_|.]+)/g)
for (const idx in matches) {
const link: string = matches[idx]
// Remove the leading @:
Expand Down
4 changes: 4 additions & 0 deletions test/unit/fixture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ export default {
linkEnd: 'This is a linked translation to @:message.hello',
linkWithin: 'Isn\'t @:message.hello we live in great?',
linkMultiple: 'Hello @:message.hoge!, isn\'t @:message.hello great?',
linkHyphen: '@:hyphen-hello',
linkUnderscore: '@:underscore_hello',
'hyphen-locale': 'hello hyphen',
'1234': 'Number-based keys are found',
'1mixedKey': 'Mixed keys are not found.'
},
'hello world': 'Hello World',
'Hello {0}': 'Hello {0}',
'continue-with-new-account': 'continue with new account',
'hyphen-hello': 'hyphen the wolrd',
underscore_hello: 'underscore the wolrd',
underscore: '{helloMsg} world',
plurals: {
car: 'car | cars',
Expand Down
7 changes: 7 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ describe('issues', () => {
}).then(done)
})
})

describe('#170', () => {
it('should be translated', () => {
assert.equal(vm.$i18n.t('message.linkHyphen'), messages.en['hyphen-hello'])
assert.equal(vm.$i18n.t('message.linkUnderscore'), messages.en.underscore_hello)
})
})
})

0 comments on commit 6e9f151

Please sign in to comment.