Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow colon in locale message keys used in linked locale messages #1488

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'])
})
})
})