88
99import { registerLocaleData } from '@angular/common' ;
1010import localeRo from '@angular/common/locales/ro' ;
11- import { Component , ContentChild , ContentChildren , Directive , HostBinding , Input , LOCALE_ID , QueryList , TemplateRef , Type , ViewChild , ViewContainerRef , ɵi18nConfigureLocalize } from '@angular/core' ;
11+ import { Component , ContentChild , ContentChildren , Directive , HostBinding , Input , LOCALE_ID , QueryList , TemplateRef , Type , ViewChild , ViewContainerRef , ɵi18nConfigureLocalize , Pipe , PipeTransform } from '@angular/core' ;
1212import { setDelayProjection } from '@angular/core/src/render3/instructions/projection' ;
1313import { TestBed } from '@angular/core/testing' ;
1414import { By } from '@angular/platform-browser' ;
@@ -18,7 +18,7 @@ import {onlyInIvy} from '@angular/private/testing';
1818
1919onlyInIvy ( 'Ivy i18n logic' ) . describe ( 'runtime i18n' , ( ) => {
2020 beforeEach ( ( ) => {
21- TestBed . configureTestingModule ( { declarations : [ AppComp , DirectiveWithTplRef ] } ) ;
21+ TestBed . configureTestingModule ( { declarations : [ AppComp , DirectiveWithTplRef , UppercasePipe ] } ) ;
2222 } ) ;
2323
2424 afterEach ( ( ) => { setDelayProjection ( false ) ; } ) ;
@@ -315,6 +315,29 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
315315 }
316316 } ) ;
317317
318+ it ( 'should be able to act as child elements inside i18n block (text + pipes)' , ( ) => {
319+ // Note: for some reason keeping this key inline causes clang to reformat the entire file
320+ // in a very weird way. Keeping it separated like this seems to make it happy.
321+ const key = '{$startTagNgTemplate}Hello {$interpolation}{$closeTagNgTemplate}' +
322+ '{$startTagNgContainer}Bye {$interpolation}{$closeTagNgContainer}' ;
323+
324+ ɵi18nConfigureLocalize ( {
325+ translations : {
326+ [ key ] :
327+ '{$startTagNgTemplate}Hej {$interpolation}{$closeTagNgTemplate}{$startTagNgContainer}Vi ses {$interpolation}{$closeTagNgContainer}'
328+ }
329+ } ) ;
330+ const fixture = initWithTemplate ( AppComp , `
331+ <div i18n>
332+ <ng-template tplRef>Hello {{name | uppercase}}</ng-template>
333+ <ng-container>Bye {{name | uppercase}}</ng-container>
334+ </div>
335+ ` ) ;
336+
337+ const element = fixture . nativeElement . firstChild ;
338+ expect ( element . textContent . replace ( / \s + / g, ' ' ) . trim ( ) ) . toBe ( 'Hej ANGULARVi ses ANGULAR' ) ;
339+ } ) ;
340+
318341 it ( 'should be able to handle deep nested levels with templates' , ( ) => {
319342 ɵi18nConfigureLocalize ( {
320343 translations : {
@@ -1463,3 +1486,8 @@ class DirectiveWithTplRef {
14631486 constructor ( public vcRef : ViewContainerRef , public tplRef : TemplateRef < { } > ) { }
14641487 ngOnInit ( ) { this . vcRef . createEmbeddedView ( this . tplRef , { } ) ; }
14651488}
1489+
1490+ @Pipe ( { name : 'uppercase' } )
1491+ class UppercasePipe implements PipeTransform {
1492+ transform ( value : string ) { return value . toUpperCase ( ) ; }
1493+ }
0 commit comments