fix(ivy): i18n - handle translated text containing HTML comments (#32475)
Fixes FW-1536 PR Close #32475
This commit is contained in:
parent
7cc4225eb9
commit
5d8eb74634
@ -169,7 +169,7 @@ const verify = (input: string, output: string, extra: any = {}): void => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('i18n support in the view compiler', () => {
|
describe('i18n support in the template compiler', () => {
|
||||||
|
|
||||||
describe('element attributes', () => {
|
describe('element attributes', () => {
|
||||||
it('should add the meaning and description as JsDoc comments', () => {
|
it('should add the meaning and description as JsDoc comments', () => {
|
||||||
@ -943,6 +943,24 @@ describe('i18n support in the view compiler', () => {
|
|||||||
verify(input, output, {exceptions});
|
verify(input, output, {exceptions});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should ignore HTML comments within translated text', () => {
|
||||||
|
const input = `
|
||||||
|
<div i18n>Some <!-- comments --> text</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const output = String.raw `
|
||||||
|
var $I18N_0$;
|
||||||
|
if (ngI18nClosureMode) {
|
||||||
|
const $MSG_EXTERNAL_0$ = goog.getMsg("Some text");
|
||||||
|
$I18N_0$ = $MSG_EXTERNAL_0$;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$I18N_0$ = $localize \`Some text\`;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
verify(input, output);
|
||||||
|
});
|
||||||
|
|
||||||
it('should properly escape quotes in content', () => {
|
it('should properly escape quotes in content', () => {
|
||||||
const input = `
|
const input = `
|
||||||
<div i18n>Some text 'with single quotes', "with double quotes" and without quotes.</div>
|
<div i18n>Some text 'with single quotes', "with double quotes" and without quotes.</div>
|
||||||
|
@ -44,7 +44,12 @@ class PlaceholderPiece extends MessagePiece {
|
|||||||
*/
|
*/
|
||||||
class LocalizeSerializerVisitor implements i18n.Visitor {
|
class LocalizeSerializerVisitor implements i18n.Visitor {
|
||||||
visitText(text: i18n.Text, context: MessagePiece[]): any {
|
visitText(text: i18n.Text, context: MessagePiece[]): any {
|
||||||
context.push(new LiteralPiece(text.value));
|
if (context[context.length - 1] instanceof LiteralPiece) {
|
||||||
|
// Two literal pieces in a row means that there was some comment node in-between.
|
||||||
|
context[context.length - 1].text += text.value;
|
||||||
|
} else {
|
||||||
|
context.push(new LiteralPiece(text.value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitContainer(container: i18n.Container, context: MessagePiece[]): any {
|
visitContainer(container: i18n.Container, context: MessagePiece[]): any {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user