fix(ivy): proper i18n postprocessing in case of nested templates (#28209)
Prior to this change the postprocess step relied on the order of placeholders combined in one group (e.g. [�#1�|�*1:1�]). The order is not guaranteed in case we have nested templates (since we use BFS to process templates) and some tags are represented using same placeholders. This change performs postprocessing more accurate by keeping track of currently active template and searching for matching placeholder. PR Close #28209
This commit is contained in:

committed by
Jason Aden

parent
7421534873
commit
2da82db3bc
@ -1777,7 +1777,7 @@ describe('Runtime i18n', () => {
|
||||
|
||||
describe('i18nPostprocess', () => {
|
||||
it('should handle valid cases', () => {
|
||||
const arr = ['<27>*1:1<><31>#2:1<>', '<27>#4:2<EFBFBD>', '<27>6:4<EFBFBD>', '<27>/#2:1<><31>/*1:1<>'];
|
||||
const arr = ['<27>*1:1<><31>#2:1<>', '<27>#4:1<EFBFBD>', '<27>6:1<EFBFBD>', '<27>/#2:1<><31>/*1:1<>'];
|
||||
const str = `[${arr.join('|')}]`;
|
||||
|
||||
const cases = [
|
||||
@ -1855,6 +1855,57 @@ describe('Runtime i18n', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle nested template represented by multi-value placeholders', () => {
|
||||
/**
|
||||
* <div i18n>
|
||||
* <span>
|
||||
* Hello - 1
|
||||
* </span>
|
||||
* <span *ngIf="visible">
|
||||
* Hello - 2
|
||||
* <span *ngIf="visible">
|
||||
* Hello - 3
|
||||
* <span *ngIf="visible">
|
||||
* Hello - 4
|
||||
* </span>
|
||||
* </span>
|
||||
* </span>
|
||||
* <span>
|
||||
* Hello - 5
|
||||
* </span>
|
||||
* </div>
|
||||
*/
|
||||
const generated = `
|
||||
[<5B>#2<>|<7C>#4<>] Bonjour - 1 [<5B>/#2<>|<7C>/#1:3<><33>/*2:3<>|<7C>/#1:2<><32>/*2:2<>|<7C>/#1:1<><31>/*3:1<>|<7C>/#4<>]
|
||||
[<5B>*3:1<><31>#1:1<>|<7C>*2:2<><32>#1:2<>|<7C>*2:3<><33>#1:3<>]
|
||||
Bonjour - 2
|
||||
[<5B>*3:1<><31>#1:1<>|<7C>*2:2<><32>#1:2<>|<7C>*2:3<><33>#1:3<>]
|
||||
Bonjour - 3
|
||||
[<5B>*3:1<><31>#1:1<>|<7C>*2:2<><32>#1:2<>|<7C>*2:3<><33>#1:3<>] Bonjour - 4 [<5B>/#2<>|<7C>/#1:3<><33>/*2:3<>|<7C>/#1:2<><32>/*2:2<>|<7C>/#1:1<><31>/*3:1<>|<7C>/#4<>]
|
||||
[<5B>/#2<>|<7C>/#1:3<><33>/*2:3<>|<7C>/#1:2<><32>/*2:2<>|<7C>/#1:1<><31>/*3:1<>|<7C>/#4<>]
|
||||
[<5B>/#2<>|<7C>/#1:3<><33>/*2:3<>|<7C>/#1:2<><32>/*2:2<>|<7C>/#1:1<><31>/*3:1<>|<7C>/#4<>]
|
||||
[<5B>#2<>|<7C>#4<>] Bonjour - 5 [<5B>/#2<>|<7C>/#1:3<><33>/*2:3<>|<7C>/#1:2<><32>/*2:2<>|<7C>/#1:1<><31>/*3:1<>|<7C>/#4<>]
|
||||
`;
|
||||
const final = `
|
||||
<20>#2<> Bonjour - 1 <20>/#2<>
|
||||
<20>*3:1<>
|
||||
<20>#1:1<>
|
||||
Bonjour - 2
|
||||
<20>*2:2<>
|
||||
<20>#1:2<>
|
||||
Bonjour - 3
|
||||
<20>*2:3<>
|
||||
<20>#1:3<> Bonjour - 4 <20>/#1:3<>
|
||||
<20>/*2:3<>
|
||||
<20>/#1:2<>
|
||||
<20>/*2:2<>
|
||||
<20>/#1:1<>
|
||||
<20>/*3:1<>
|
||||
<20>#4<> Bonjour - 5 <20>/#4<>
|
||||
`;
|
||||
expect(i18nPostprocess(generated.replace(/\s+/g, ''))).toEqual(final.replace(/\s+/g, ''));
|
||||
});
|
||||
|
||||
it('should throw in case we have invalid string', () => {
|
||||
const arr = ['<27>*1:1<><31>#2:1<>', '<27>#4:2<>', '<27>6:4<>', '<27>/#2:1<><31>/*1:1<>'];
|
||||
const str = `[${arr.join('|')}]`;
|
||||
|
Reference in New Issue
Block a user