feat(i18n): pass translation config directly into ngc (#10622)
This commit is contained in:
@ -2,3 +2,4 @@
|
||||
<form><input type="button" [(ngModel)]="ctxProp" name="first"/></form>
|
||||
<my-comp *ngIf="ctxBool"></my-comp>
|
||||
<div *ngFor="let x of ctxArr" [attr.value]="x"></div>
|
||||
<p id="welcomeMessage"><!--i18n-->Welcome<!--/i18n--></p>
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {NgFor, NgIf} from '@angular/common';
|
||||
import {Component, Inject} from '@angular/core';
|
||||
import {Component, Inject, LOCALE_ID, TRANSLATIONS_FORMAT} from '@angular/core';
|
||||
import {FORM_DIRECTIVES} from '@angular/forms';
|
||||
|
||||
import {MultipleComponentsMyComp} from './a/multiple_components';
|
||||
@ -23,5 +23,9 @@ export class BasicComp {
|
||||
ctxProp: string;
|
||||
ctxBool: boolean;
|
||||
ctxArr: any[] = [];
|
||||
constructor() { this.ctxProp = 'initialValue'; }
|
||||
constructor(
|
||||
@Inject(LOCALE_ID) public localeId: string,
|
||||
@Inject(TRANSLATIONS_FORMAT) public translationsFormat: string) {
|
||||
this.ctxProp = 'initialValue';
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
<translationbundle>
|
||||
<translation id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4">käännä teksti</translation>
|
||||
<translation id="65cc4ab3b4c438e07c89be2b677d08369fb62da2">tervetuloa</translation>
|
||||
</translationbundle>
|
@ -44,24 +44,45 @@ describe('template codegen output', () => {
|
||||
it('should support ngIf', () => {
|
||||
var compFixture = createComponent(BasicComp);
|
||||
var debugElement = compFixture.debugElement;
|
||||
expect(debugElement.children.length).toBe(2);
|
||||
expect(debugElement.children.length).toBe(3);
|
||||
|
||||
compFixture.componentInstance.ctxBool = true;
|
||||
compFixture.detectChanges();
|
||||
expect(debugElement.children.length).toBe(3);
|
||||
expect(debugElement.children.length).toBe(4);
|
||||
expect(debugElement.children[2].injector.get(MultipleComponentsMyComp)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support ngFor', () => {
|
||||
var compFixture = createComponent(BasicComp);
|
||||
var debugElement = compFixture.debugElement;
|
||||
expect(debugElement.children.length).toBe(2);
|
||||
expect(debugElement.children.length).toBe(3);
|
||||
|
||||
// test NgFor
|
||||
compFixture.componentInstance.ctxArr = [1, 2];
|
||||
compFixture.detectChanges();
|
||||
expect(debugElement.children.length).toBe(4);
|
||||
expect(debugElement.children.length).toBe(5);
|
||||
expect(debugElement.children[2].attributes['value']).toBe('1');
|
||||
expect(debugElement.children[3].attributes['value']).toBe('2');
|
||||
});
|
||||
|
||||
describe('i18n', () => {
|
||||
it('should inject the locale into the component', () => {
|
||||
const compFixture = createComponent(BasicComp);
|
||||
expect(compFixture.componentInstance.localeId).toEqual('fi');
|
||||
});
|
||||
|
||||
it('should inject the translations format into the component', () => {
|
||||
const compFixture = createComponent(BasicComp);
|
||||
expect(compFixture.componentInstance.translationsFormat).toEqual('xtb');
|
||||
});
|
||||
|
||||
it('should support i18n for content tags', () => {
|
||||
const compFixture = createComponent(BasicComp);
|
||||
const debugElement = compFixture.debugElement;
|
||||
const containerElement = <any>debugElement.nativeElement;
|
||||
const pElement = <any>containerElement.children.find((c: any) => c.name == 'p');
|
||||
const pText = <string>pElement.children.map((c: any) => c.data).join('').trim();
|
||||
expect(pText).toBe('tervetuloa');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -39,6 +39,7 @@ describe('template i18n extraction output', () => {
|
||||
]>
|
||||
<messagebundle>
|
||||
<msg id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4" desc="desc" meaning="meaning">translate me</msg>
|
||||
<msg id="65cc4ab3b4c438e07c89be2b677d08369fb62da2">Welcome</msg>
|
||||
</messagebundle>`;
|
||||
|
||||
const xmbOutput = path.join(outDir, 'messages.xmb');
|
||||
|
Reference in New Issue
Block a user