@@ -357,6 +357,130 @@ describe('control flow migration', () => {
357357 ] . join ( '\n' ) ) ;
358358 } ) ;
359359
360+ it ( 'should migrate an if case with an ng-template with i18n' , async ( ) => {
361+ writeFile ( '/comp.ts' , `
362+ import {Component} from '@angular/core';
363+ import {NgIf} from '@angular/common';
364+
365+ @Component({
366+ templateUrl: './comp.html'
367+ })
368+ class Comp {
369+ show = false;
370+ }
371+ ` ) ;
372+
373+ writeFile ( '/comp.html' , [
374+ `<div>` ,
375+ `<ng-template *ngIf="show" i18n="@@something"><span>Content here</span></ng-template>` ,
376+ `</div>` ,
377+ ] . join ( '\n' ) ) ;
378+
379+ await runMigration ( ) ;
380+ const content = tree . readContent ( '/comp.html' ) ;
381+
382+ expect ( content ) . toBe ( [
383+ `<div>` ,
384+ `@if (show) {` ,
385+ `<ng-container i18n="@@something"><span>Content here</span></ng-container>` ,
386+ `}` ,
387+ `</div>` ,
388+ ] . join ( '\n' ) ) ;
389+ } ) ;
390+
391+ it ( 'should migrate an if case with an ng-template with empty i18n' , async ( ) => {
392+ writeFile ( '/comp.ts' , `
393+ import {Component} from '@angular/core';
394+ import {NgIf} from '@angular/common';
395+
396+ @Component({
397+ templateUrl: './comp.html'
398+ })
399+ class Comp {
400+ show = false;
401+ }
402+ ` ) ;
403+
404+ writeFile ( '/comp.html' , [
405+ `<div>` ,
406+ `<ng-template *ngIf="show" i18n><span>Content here</span></ng-template>` ,
407+ `</div>` ,
408+ ] . join ( '\n' ) ) ;
409+
410+ await runMigration ( ) ;
411+ const content = tree . readContent ( '/comp.html' ) ;
412+
413+ expect ( content ) . toBe ( [
414+ `<div>` ,
415+ `@if (show) {` ,
416+ `<ng-container i18n><span>Content here</span></ng-container>` ,
417+ `}` ,
418+ `</div>` ,
419+ ] . join ( '\n' ) ) ;
420+ } ) ;
421+
422+ it ( 'should migrate an if case with an ng-container with i18n' , async ( ) => {
423+ writeFile ( '/comp.ts' , `
424+ import {Component} from '@angular/core';
425+ import {NgIf} from '@angular/common';
426+
427+ @Component({
428+ templateUrl: './comp.html'
429+ })
430+ class Comp {
431+ show = false;
432+ }
433+ ` ) ;
434+
435+ writeFile ( '/comp.html' , [
436+ `<div>` ,
437+ `<ng-container *ngIf="show" i18n="@@something"><span>Content here</span></ng-container>` ,
438+ `</div>` ,
439+ ] . join ( '\n' ) ) ;
440+
441+ await runMigration ( ) ;
442+ const content = tree . readContent ( '/comp.html' ) ;
443+
444+ expect ( content ) . toBe ( [
445+ `<div>` ,
446+ `@if (show) {` ,
447+ `<ng-container i18n="@@something"><span>Content here</span></ng-container>` ,
448+ `}` ,
449+ `</div>` ,
450+ ] . join ( '\n' ) ) ;
451+ } ) ;
452+
453+ it ( 'should migrate an if case with an ng-container with empty i18n' , async ( ) => {
454+ writeFile ( '/comp.ts' , `
455+ import {Component} from '@angular/core';
456+ import {NgIf} from '@angular/common';
457+
458+ @Component({
459+ templateUrl: './comp.html'
460+ })
461+ class Comp {
462+ show = false;
463+ }
464+ ` ) ;
465+
466+ writeFile ( '/comp.html' , [
467+ `<div>` ,
468+ `<ng-container *ngIf="show" i18n><span>Content here</span></ng-container>` ,
469+ `</div>` ,
470+ ] . join ( '\n' ) ) ;
471+
472+ await runMigration ( ) ;
473+ const content = tree . readContent ( '/comp.html' ) ;
474+
475+ expect ( content ) . toBe ( [
476+ `<div>` ,
477+ `@if (show) {` ,
478+ `<ng-container i18n><span>Content here</span></ng-container>` ,
479+ `}` ,
480+ `</div>` ,
481+ ] . join ( '\n' ) ) ;
482+ } ) ;
483+
360484 it ( 'should migrate an if else case' , async ( ) => {
361485 writeFile ( '/comp.ts' , `
362486 import {Component} from '@angular/core';
@@ -2560,6 +2684,50 @@ describe('control flow migration', () => {
25602684
25612685 expect ( actual ) . toBe ( expected ) ;
25622686 } ) ;
2687+
2688+ it ( 'should preserve i18n attribute on ng-templates in an if/else' , async ( ) => {
2689+ writeFile ( '/comp.ts' , `
2690+ import {Component} from '@angular/core';
2691+ import {NgIf} from '@angular/common';
2692+
2693+ @Component({
2694+ selector: 'declare-comp',
2695+ templateUrl: 'comp.html',
2696+ })
2697+ class DeclareComp {}
2698+ ` ) ;
2699+
2700+ writeFile ( '/comp.html' , [
2701+ `<div>` ,
2702+ ` <ng-container *ngIf="cond; else testTpl">` ,
2703+ ` bla bla` ,
2704+ ` </ng-container>` ,
2705+ `</div>` ,
2706+ `<ng-template #testTpl i18n="@@test_key">` ,
2707+ ` <div class="test" *ngFor="let item of items"></div>` ,
2708+ `</ng-template>` ,
2709+ ] . join ( '\n' ) ) ;
2710+
2711+ await runMigration ( ) ;
2712+ const actual = tree . readContent ( '/comp.html' ) ;
2713+
2714+ const expected = [
2715+ `<div>` ,
2716+ ` @if (cond) {\n` ,
2717+ ` bla bla` ,
2718+ ` ` ,
2719+ `} @else {` ,
2720+ `<ng-container i18n="@@test_key">` ,
2721+ ` @for (item of items; track item) {` ,
2722+ ` <div class="test"></div>` ,
2723+ `}` ,
2724+ `</ng-container>` ,
2725+ `}` ,
2726+ `</div>\n` ,
2727+ ] . join ( '\n' ) ;
2728+
2729+ expect ( actual ) . toBe ( expected ) ;
2730+ } ) ;
25632731 } ) ;
25642732
25652733 describe ( 'no migration needed' , ( ) => {
0 commit comments