From 5d9eee0b70e9ba8ce9e5b9bcae87600ce6cf08a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Fri, 3 Jan 2025 15:56:37 +0100 Subject: [PATCH] fix: extract `t` from custom elements (#144) --- src/extractor/parserNgx/ngxMapper.ts | 5 +++++ test/e2e/formats.test.ts | 4 ++-- test/unit/extractor/ngx/elementWithT.test.ts | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/extractor/parserNgx/ngxMapper.ts b/src/extractor/parserNgx/ngxMapper.ts index 562cd363..9021f55a 100644 --- a/src/extractor/parserNgx/ngxMapper.ts +++ b/src/extractor/parserNgx/ngxMapper.ts @@ -1,6 +1,11 @@ import { Token } from '../parser/types.js'; export const ngxMapper = (token: Token) => { + // custom tag names have dynamic token names + if (token.type?.startsWith('entity.name.tag.html.ng.')) { + return 'tag.name'; + } + switch (token.type) { // ngx template tags case 'punctuation.definition.tag.begin.html': diff --git a/test/e2e/formats.test.ts b/test/e2e/formats.test.ts index 55053e97..01bb9653 100644 --- a/test/e2e/formats.test.ts +++ b/test/e2e/formats.test.ts @@ -110,7 +110,7 @@ describe('push and pull with different formats', () => { config: 'xliff-java', inPlatform: 'You have {0} items', fileLocation: 'en.xliff', - inFile: 'You have %s items', + inFile: 'You have %1$s items', }); }); @@ -146,7 +146,7 @@ describe('push and pull with different formats', () => { config: 'android-xml', inPlatform: 'You have {0} items', fileLocation: 'values-en/strings.xml', - inFile: 'You have %s items', + inFile: 'You have %1$s items', }); }); diff --git a/test/unit/extractor/ngx/elementWithT.test.ts b/test/unit/extractor/ngx/elementWithT.test.ts index 37547539..409385b3 100644 --- a/test/unit/extractor/ngx/elementWithT.test.ts +++ b/test/unit/extractor/ngx/elementWithT.test.ts @@ -30,6 +30,18 @@ describe('element with t param', () => { expect(extracted.keys).toEqual([{ keyName: 'key1', line: 3 }]); }); + it('extracts calls to t from custom element', async () => { + const code = ` + + `; + + const extracted = await extractNgxKeys(code, 'test.component.html'); + expect(extracted.warnings).toEqual([]); + expect(extracted.keys).toEqual([{ keyName: 'key1', line: 3 }]); + }); + it('extracts keys specified binded properties', async () => { const expected = [{ keyName: 'key1', line: 3 }];