diff --git a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts index a5a75f7ec5..eff40c08cf 100644 --- a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts @@ -113,7 +113,9 @@ export class Xliff2TranslationSerializer implements TranslationSerializer { const text = substitutionLocations?.[placeholderName]?.text; if (placeholderName.startsWith('START_')) { - const closingPlaceholderName = placeholderName.replace(/^START/, 'CLOSE'); + // Replace the `START` with `CLOSE` and strip off any `_1` ids from the end. + const closingPlaceholderName = + placeholderName.replace(/^START/, 'CLOSE').replace(/_\d+$/, ''); const closingText = substitutionLocations?.[closingPlaceholderName]?.text; const attrs: Record = { id: `${this.currentPlaceholderId++}`, @@ -186,7 +188,7 @@ export class Xliff2TranslationSerializer implements TranslationSerializer { * and links are special cases. */ function getTypeForPlaceholder(placeholder: string): string|null { - const tag = placeholder.replace(/^(START_|CLOSE_)/, ''); + const tag = placeholder.replace(/^(START_|CLOSE_)/, '').replace(/_\d+$/, ''); switch (tag) { case 'BOLD_TEXT': case 'EMPHASISED_TEXT': diff --git a/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts b/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts index 247184be82..fbd5ab49d5 100644 --- a/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts +++ b/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts @@ -301,6 +301,27 @@ runInEachFileSystem(() => { 'abc', ); }); + + it('should render the "type" for link elements', () => { + const serializer = new Xliff2TranslationSerializer( + 'xx', absoluteFrom('/project'), useLegacyIds, options); + const output = serializer.serialize( + [mockMessage('6', ['a', 'b', 'c'], ['START_LINK', 'CLOSE_LINK'], {})]); + expect(output).toContain( + 'abc', + ); + }); + + it('should render generic close tag placeholders for additional elements', () => { + const serializer = new Xliff2TranslationSerializer( + 'xx', absoluteFrom('/project'), useLegacyIds, options); + const output = serializer.serialize([mockMessage( + '6', ['a', 'b', 'c', 'd', 'e'], + ['START_LINK', 'CLOSE_LINK', 'START_LINK_1', 'CLOSE_LINK'], {})]); + expect(output).toContain( + 'abcde', + ); + }); }); }); });