From 6e9f151a18789777762c90af006d48446d62d501 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 4 Jun 2017 10:28:20 +0900 Subject: [PATCH] :bug: bug: fix linked translation with using hyphen or underscore keypath Close #170 --- src/index.js | 2 +- test/unit/fixture/index.js | 4 ++++ test/unit/issues.test.js | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index ab1097e22..121a998e0 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @: diff --git a/test/unit/fixture/index.js b/test/unit/fixture/index.js index 4f1b345fd..e9e86d476 100644 --- a/test/unit/fixture/index.js +++ b/test/unit/fixture/index.js @@ -13,6 +13,8 @@ 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.' @@ -20,6 +22,8 @@ export default { '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', diff --git a/test/unit/issues.test.js b/test/unit/issues.test.js index 1b3d8f0cd..af9e03f25 100644 --- a/test/unit/issues.test.js +++ b/test/unit/issues.test.js @@ -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) + }) + }) })