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

Commit 6e9f151

Browse files
committed
🐛 bug: fix linked translation with using hyphen or underscore keypath
Close #170
1 parent 687d406 commit 6e9f151

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export default class VueI18n {
191191
// Match all the links within the local
192192
// We are going to replace each of
193193
// them with its translation
194-
const matches: any = ret.match(/(@:[\w|.]+)/g)
194+
const matches: any = ret.match(/(@:[\w\-_|.]+)/g)
195195
for (const idx in matches) {
196196
const link: string = matches[idx]
197197
// Remove the leading @:

test/unit/fixture/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ export default {
1313
linkEnd: 'This is a linked translation to @:message.hello',
1414
linkWithin: 'Isn\'t @:message.hello we live in great?',
1515
linkMultiple: 'Hello @:message.hoge!, isn\'t @:message.hello great?',
16+
linkHyphen: '@:hyphen-hello',
17+
linkUnderscore: '@:underscore_hello',
1618
'hyphen-locale': 'hello hyphen',
1719
'1234': 'Number-based keys are found',
1820
'1mixedKey': 'Mixed keys are not found.'
1921
},
2022
'hello world': 'Hello World',
2123
'Hello {0}': 'Hello {0}',
2224
'continue-with-new-account': 'continue with new account',
25+
'hyphen-hello': 'hyphen the wolrd',
26+
underscore_hello: 'underscore the wolrd',
2327
underscore: '{helloMsg} world',
2428
plurals: {
2529
car: 'car | cars',

test/unit/issues.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,11 @@ describe('issues', () => {
9292
}).then(done)
9393
})
9494
})
95+
96+
describe('#170', () => {
97+
it('should be translated', () => {
98+
assert.equal(vm.$i18n.t('message.linkHyphen'), messages.en['hyphen-hello'])
99+
assert.equal(vm.$i18n.t('message.linkUnderscore'), messages.en.underscore_hello)
100+
})
101+
})
95102
})

0 commit comments

Comments
 (0)