Skip to content

Commit

Permalink
Allow colon in locale message keys used in linked locale messages (#1488
Browse files Browse the repository at this point in the history
)

* Allow colon in locale message keys

* Add unit tests for linked messages with colon and pipe in key
  • Loading branch information
ax-jmckenzie committed Mar 29, 2022
1 parent 43801e3 commit b3624fe
Show file tree
Hide file tree
Showing 4 changed files with 19 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 @@ -26,7 +26,7 @@ import I18nPath from './path'
import type { PathValue } from './path'

const htmlTagMatcher = /<\/?[\w\s="/.':;#-\/]+>/
const linkKeyMatcher = /(?:@(?:\.[a-z]+)?:(?:[\w\-_|./]+|\([\w\-_|./]+\)))/g
const linkKeyMatcher = /(?:@(?:\.[a-z]+)?:(?:[\w\-_|./]+|\([\w\-_:|./]+\)))/g
const linkKeyPrefixMatcher = /^@(?:\.([a-z]+))?:/
const bracketsMatcher = /[()]/g
const defaultModifiers = {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ describe('basic', () => {
it('should render link with custom formatting.', () => {
assert.strictEqual(i18n.t('message.linkCaseCustom'), 'hxmx Addrxss')
})

it('should translate link when keys have special characters', () => {
assert.strictEqual(i18n.t('message.linkHyphen'), messages.en['hyphen-hello'])
assert.strictEqual(i18n.t('message.linkUnderscore'), messages.en.underscore_hello)
assert.strictEqual(i18n.t('message.linkColon'), messages.en['colon:hello'])
assert.strictEqual(i18n.t('message.linkPipe'), messages.en['pipe|hello'])
})
})

describe('ja locale', () => {
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 @@ -19,6 +19,8 @@ export default {
linkBrackets: 'Hello @:(message.hoge). Isn\'t @:(message.hello) great?',
linkHyphen: '@:hyphen-hello',
linkUnderscore: '@:underscore_hello',
linkPipe: '@:pipe|hello',
linkColon: '@:(colon:hello)',
linkList: '@:message.hello: {0} {1}',
linkCaseLower: 'Please provide @.lower:message.homeAddress',
linkCaseUpper: '@.upper:message.homeAddress',
Expand All @@ -45,6 +47,8 @@ export default {
'hyphen-hello': 'hyphen the wolrd',
/* eslint-disable */
underscore_hello: 'underscore the wolrd',
'colon:hello': 'hello colon',
'pipe|hello': 'hello pipe',
/* eslint-enable */
underscore: '{helloMsg} world',
plurals: {
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 @@ -813,4 +813,11 @@ describe('issues', () => {
}).then(done)
})
})

describe('#1488', () => {
it('should be translated', () => {
assert.strictEqual(vm.$i18n.t('message.linkColon'), messages.en['colon:hello'])
assert.strictEqual(vm.$i18n.t('message.linkPipe'), messages.en['pipe|hello'])
})
})
})

0 comments on commit b3624fe

Please sign in to comment.