Skip to content

Commit 0106b9e

Browse files
fix: 🐛 comments with prefix not extracted (#197) (#198)
1 parent e1b20af commit 0106b9e

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

__tests__/buildTranslationFiles/comments/comments-spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function testCommentsExtraction(fileFormat: Config['fileFormat']) {
3131
'a.some.key': defaultValue,
3232
'b.some.key': defaultValue,
3333
'c.some.key': defaultValue,
34+
'prefix_c.some.key': defaultValue,
3435
'need.transloco': defaultValue,
3536
'1.some': defaultValue,
3637
...generateKeys({ end: 8 }),

__tests__/buildTranslationFiles/comments/src/1.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ <h1>{{title}}</h1>
77
<!-- t(some.key) -->
88
<p >{{ t(title) }}</p>
99
</ng-container>
10+
11+
<ng-container *transloco="let t; prefix: 'prefix_c'">
12+
<!-- t(some.key) -->
13+
<p >{{ t(title) }}</p>
14+
</ng-container>
1015
</div>

src/keys-builder/template/comments.extractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ function extractReadValue(
120120

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

127127
if (templateType === TEMPLATE_TYPE.NG_TEMPLATE) {
128128
const attrs = Object.keys(element.attribs);
129129
const readSearch = attrs.find((attr) =>
130-
['translocoread', '[translocoread]'].includes(attr),
130+
['translocoread', '[translocoread]', 'translocoprefix', '[translocoprefix]'].includes(attr),
131131
);
132132
read = readSearch && element.attribs[readSearch].replace(/['"]/g, '');
133133
}

0 commit comments

Comments
 (0)