diff --git a/modules/@angular/compiler/test/i18n/integration_spec.ts b/modules/@angular/compiler/test/i18n/integration_spec.ts index 1bcd64aad4..24e0a26717 100644 --- a/modules/@angular/compiler/test/i18n/integration_spec.ts +++ b/modules/@angular/compiler/test/i18n/integration_spec.ts @@ -8,6 +8,10 @@ import {NgLocalization} from '@angular/common'; import {ResourceLoader} from '@angular/compiler'; +import {MessageBundle} from '@angular/compiler/src/i18n/message_bundle'; +import {Xmb} from '@angular/compiler/src/i18n/serializers/xmb'; +import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser'; +import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/interpolation_config'; import {Component, DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core'; import {TestBed, async} from '@angular/core/testing'; import {By} from '@angular/platform-browser/src/dom/debug/by'; @@ -32,9 +36,16 @@ export function main() { TestBed.configureTestingModule({declarations: [I18nComponent]}); })); + it('should extract from templates', () => { + const catalog = new MessageBundle(new HtmlParser, [], {}); + const serializer = new Xmb(); + catalog.updateFromTemplate(HTML, '', DEFAULT_INTERPOLATION_CONFIG); - it('translate templates', () => { - const tb = TestBed.createComponent(I18nComponent); + expect(catalog.write(serializer)).toContain(XMB); + }); + + it('should translate templates', () => { + const tb = TestBed.overrideTemplate(I18nComponent, HTML).createComponent(I18nComponent); const cmp = tb.componentInstance; const el = tb.debugElement; @@ -105,7 +116,80 @@ function expectHtml(el: DebugElement, cssSelector: string): any { @Component({ selector: 'i18n-cmp', - template: ` + template: '', +}) +class I18nComponent { + count: number; + sex: string; + sexB: string; + response: any = {getItemsList: (): any[] => []}; +} + +class FrLocalization extends NgLocalization { + getPluralCategory(value: number): string { + switch (value) { + case 0: + case 1: + return 'one'; + default: + return 'other'; + } + } +} + +const XTB = ` + + attributs i18n sur les balises + imbriqué + imbriqué + avec des espaces réservés + sur des balises non traductibles + sur des balises traductibles + {VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup}} + + {VAR_SELECT, select, m {homme} f {femme}} + + sexe = + + dans une section traductible + + Balises dans les commentaires html + + + + ca devrait marcher + avec un ID explicite + {VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {<b>beaucoup</b>} } + {VAR_PLURAL, plural, =0 {Pas de réponse} =1 {une réponse} other {INTERPOLATION réponse} } +`; + +const XMB = ` i18n attribute on tags + nested + nested + <i>with placeholders</i> + on not translatable node + on translatable node + {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b>many</b>} } + + ICU + + {VAR_SELECT, select, m {male} f {female} } + INTERPOLATION + sex = INTERPOLATION + CUSTOM_NAME + in a translatable section + + <h1>Markers in html comments</h1> + <div></div> + <div>ICU</div> + + it <b>should</b> work + with an explicit ID + {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b>many</b>} } + {VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found INTERPOLATION results} }`; + +const HTML = `

i18n attribute on tags

@@ -156,82 +240,4 @@ function expectHtml(el: DebugElement, cssSelector: string): any { =1 {Found one result} other {Found {{response.getItemsList().length}} results} }
-` -}) -class I18nComponent { - count: number; - sex: string; - sexB: string; - response: any = {getItemsList: (): any[] => []}; -} - -class FrLocalization extends NgLocalization { - getPluralCategory(value: number): string { - switch (value) { - case 0: - case 1: - return 'one'; - default: - return 'other'; - } - } -} - -const XTB = ` - - attributs i18n sur les balises - imbriqué - imbriqué - avec des espaces réservés - sur des balises non traductibles - sur des balises traductibles - {VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup}} - - {VAR_SELECT, select, m {homme} f {femme}} - - sexe = - - dans une section traductible - - Balises dans les commentaires html - - - - ca devrait marcher - avec un ID explicite - {VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {<b>beaucoup</b>} } - {VAR_PLURAL, plural, =0 {Pas de réponse} =1 {une réponse} other {INTERPOLATION réponse} } -`; - -// unused, for reference only -// can be generated from xmb_spec as follow: -// `fit('extract xmb', () => { console.log(toXmb(HTML)); });` -const XMB = ` - - i18n attribute on tags - nested - nested - <i>with placeholders</i> - on not translatable node - on translatable node - {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b>many</b>} } - - ICU - - {VAR_SELECT, select, m {male} f {female} } - INTERPOLATION - sex = INTERPOLATION - CUSTOM_NAME - in a translatable section - - <h1>Markers in html comments</h1> - <div></div> - <div>ICU</div> - - it <b>should</b> work - with an explicit ID - {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b>many</b>} } - {VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found INTERPOLATION results} } - `;