Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(localize): render correct closing tag placeholder names in XLIFF 2 #41152

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
id: `${this.currentPlaceholderId++}`,
Expand Down Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,27 @@ runInEachFileSystem(() => {
'<source>a<pc id="0" equivStart="START_TAG_DIV" equivEnd="CLOSE_TAG_DIV" type="other">b</pc>c</source>',
);
});

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(
'<source>a<pc id="0" equivStart="START_LINK" equivEnd="CLOSE_LINK" type="link">b</pc>c</source>',
);
});

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(
'<source>a<pc id="0" equivStart="START_LINK" equivEnd="CLOSE_LINK" type="link">b</pc>c<pc id="1" equivStart="START_LINK_1" equivEnd="CLOSE_LINK" type="link">d</pc>e</source>',
);
});
});
});
});
Expand Down