Skip to content

Commit

Permalink
Merge pull request #186 from cedricvoinnet/ignore-dynamic-keypath
Browse files Browse the repository at this point in the history
Ignore dynamic keypath as dynamic path in i18n-t
  • Loading branch information
Spittal committed Nov 3, 2022
2 parents cb406ac + c39ee5c commit 382f5e5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/vue-i18n-extract.modern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function extractMethodMatches(file) {
}

function extractComponentMatches(file) {
const componentRegExp = /(?:(?:<|h\()(?:i18n|Translation))(?:.|\n)*?(?:[^:]path(?:=|: )("|'))((?:[^\\]|\\.)*?)\1/gi;
const componentRegExp = /(?:(?:<|h\()(?:i18n|Translation))(?:.|\n)*?(?:\s(?:(?:key)?)path(?:=|: )("|'))((?:[^\\]|\\.)*?)\1/gi;
return [...getMatches(file, componentRegExp, 2)];
}

Expand Down
2 changes: 1 addition & 1 deletion dist/vue-i18n-extract.modern.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-i18n-extract.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-i18n-extract.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/create-report/vue-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function* getMatches (file: SimpleFile, regExp: RegExp, captureGroup = 1): Itera
}

function extractComponentMatches (file: SimpleFile): I18NItemWithBounding[] {
const componentRegExp = /(?:(?:<|h\()(?:i18n|Translation))(?:.|\n)*?(?:[^:]path(?:=|: )("|'))((?:[^\\]|\\.)*?)\1/gi;
const componentRegExp = /(?:(?:<|h\()(?:i18n|Translation))(?:.|\n)*?(?:\s(?:(?:key)?)path(?:=|: )("|'))((?:[^\\]|\\.)*?)\1/gi;
return [ ...getMatches(file, componentRegExp, 2) ];
}

Expand Down
14 changes: 7 additions & 7 deletions tests/fixtures/expected-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ export const expectedFromParsedVueFiles = [
previousCharacter: "'",
nextCharacter: "'",
file: './tests/fixtures/vue-files/Basic.vue',
line: 12
line: 16
},
{
path: 'content.link.b',
previousCharacter: "'",
nextCharacter: "'",
file: './tests/fixtures/vue-files/Basic.vue',
line: 15
line: 23
},
{
path: 'header.title',
previousCharacter: "'",
nextCharacter: "'",
file: './tests/fixtures/vue-files/Basic.vue',
line: 19
line: 27
},
{
path: 'content.link.a',
Expand All @@ -74,28 +74,28 @@ export const expectedFromParsedVueFiles = [
previousCharacter: '"',
nextCharacter: '"',
file: './tests/fixtures/vue-files/Basic.vue',
line: 11
line: 12
},
{
path: 'content.link.a',
previousCharacter: '"',
nextCharacter: '"',
file: './tests/fixtures/vue-files/Basic.vue',
line: 14
line: 19
},
{
path: 'header.title',
previousCharacter: "'",
nextCharacter: "'",
file: './tests/fixtures/vue-files/Basic.vue',
line: 17
line: 25
},
{
path: 'header.title',
previousCharacter: "'",
nextCharacter: "'",
file: './tests/fixtures/vue-files/Basic.vue',
line: 18
line: 26
},
{
path: "single \\' quote",
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/vue-files/Basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
<i18n path="content.link.a">
<a place="link" href="#">{{ $t('content.link.b') }}</a>
</i18n>
<!-- Should not match -- dynamic path is ignored -->
<i18n :path="dynamicPath">
<span place="icon" class="icon" />
</i18n>
<i18n-t keypath="content.link.a">
<a place="link" href="#">{{ $t('content.link.b') }}</a>
</i18n-t>
<!-- Should not match -- dynamic keypath is ignored -->
<i18n-t :keypath="dynamicPath">
<span place="icon" class="icon" />
</i18n-t>
<Translation keypath="content.link.a">
<a place="link" href="#">{{ $t('content.link.b') }}</a>
</Translation>
Expand Down

0 comments on commit 382f5e5

Please sign in to comment.