/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ 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 {DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core'; import {ComponentFixture, TestBed, async} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {SpyResourceLoader} from '../spies'; import {FrLocalization, HTML, I18nComponent, validateHtml} from './integration_common'; { describe('i18n XMB/XTB integration spec', () => { beforeEach(async(() => { TestBed.configureCompiler({ providers: [ SpyResourceLoader.PROVIDE, FrLocalization.PROVIDE, {provide: TRANSLATIONS, useValue: XTB}, {provide: TRANSLATIONS_FORMAT, useValue: 'xtb'}, ] }); TestBed.configureTestingModule({declarations: [I18nComponent]}); })); it('should extract from templates', () => { const catalog = new MessageBundle(new HtmlParser, [], {}); const serializer = new Xmb(); catalog.updateFromTemplate(HTML, 'file.ts', DEFAULT_INTERPOLATION_CONFIG); expect(catalog.write(serializer)).toContain(XMB); }); it('should translate templates', () => { const tb: ComponentFixture = TestBed.overrideTemplate(I18nComponent, HTML).createComponent(I18nComponent); const cmp: I18nComponent = tb.componentInstance; const el: DebugElement = tb.debugElement; validateHtml(tb, cmp, el); }); }); } const XTB = ` attributs i18n sur les balises imbriqué imbriqué avec des espaces réservés <div>avec <div>des espaces réservés</div> imbriqués</div> sur des balises non traductibles sur des balises traductibles {VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup}} {VAR_SELECT, select, 0 {autre} m {homme} f {femme} } {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} } FOO<a>BAR</a> MAP_NAME `; const XMB = `file.ts:3i18n attribute on tags file.ts:5nested file.ts:7nested file.ts:9file.ts:10<i>with placeholders</i> file.ts:11<div>with <div>nested</div> placeholders</div> file.ts:14on not translatable node file.ts:15on translatable node file.ts:20file.ts:37{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b>many</b>} } file.ts:22,24 {sex, select, 0 {...} m {...} f {...}} file.ts:23{VAR_SELECT, select, 0 {other} m {male} f {female} } file.ts:25,27 {sexB, select, m {...} f {...}} file.ts:26{VAR_SELECT, select, m {male} f {female} } file.ts:29{{ "count = " + count }} file.ts:30sex = {{ sex }} file.ts:31{{ "custom name" //i18n(ph="CUSTOM_NAME") }} file.ts:36file.ts:54in a translatable section file.ts:34,38 <h1>Markers in html comments</h1> <div></div> <div>{count, plural, =0 {...} =1 {...} =2 {...} other {...}}</div> file.ts:40it <b>should</b> work file.ts:42with an explicit ID file.ts:43{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<b>many</b>} } file.ts:46,52{VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found {{response.getItemsList().length}} results} } file.ts:54foo<a>bar</a> file.ts:56{{ 'test' //i18n(ph="map name") }}`;