Skip to content

Commit

Permalink
fix: 🐛 comments with prefix not extracted (#197) (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDabrowski authored Jun 14, 2024
1 parent e1b20af commit 0106b9e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions __tests__/buildTranslationFiles/comments/comments-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function testCommentsExtraction(fileFormat: Config['fileFormat']) {
'a.some.key': defaultValue,
'b.some.key': defaultValue,
'c.some.key': defaultValue,
'prefix_c.some.key': defaultValue,
'need.transloco': defaultValue,
'1.some': defaultValue,
...generateKeys({ end: 8 }),
Expand Down
5 changes: 5 additions & 0 deletions __tests__/buildTranslationFiles/comments/src/1.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ <h1>{{title}}</h1>
<!-- t(some.key) -->
<p >{{ t(title) }}</p>
</ng-container>

<ng-container *transloco="let t; prefix: 'prefix_c'">
<!-- t(some.key) -->
<p >{{ t(title) }}</p>
</ng-container>
</div>
4 changes: 2 additions & 2 deletions src/keys-builder/template/comments.extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ function extractReadValue(

if (templateType === TEMPLATE_TYPE.STRUCTURAL) {
const data = element.attribs.__transloco;
const readSearch = data.match(/read:\s*(['"])(?<read>[^"']*)\1/);
const readSearch = data.match(/(?:read|prefix):\s*(['"])(?<read>[^"']*)\1/);
read = readSearch?.groups?.read;
}

if (templateType === TEMPLATE_TYPE.NG_TEMPLATE) {
const attrs = Object.keys(element.attribs);
const readSearch = attrs.find((attr) =>
['translocoread', '[translocoread]'].includes(attr),
['translocoread', '[translocoread]', 'translocoprefix', '[translocoprefix]'].includes(attr),
);
read = readSearch && element.attribs[readSearch].replace(/['"]/g, '');
}
Expand Down

0 comments on commit 0106b9e

Please sign in to comment.