/** * @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 {Xliff} from '@angular/compiler/src/i18n/serializers/xliff'; 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'; export function main() { describe('i18n XLIFF integration spec', () => { beforeEach(async(() => { TestBed.configureCompiler({ providers: [ {provide: ResourceLoader, useClass: SpyResourceLoader}, {provide: NgLocalization, useClass: FrLocalization}, {provide: TRANSLATIONS, useValue: XLIFF_TOMERGE}, {provide: TRANSLATIONS_FORMAT, useValue: 'xliff'}, ] }); TestBed.configureTestingModule({declarations: [I18nComponent]}); })); it('should extract from templates', () => { const catalog = new MessageBundle(new HtmlParser, [], {}); const serializer = new Xliff(); catalog.updateFromTemplate(HTML, 'file.ts', DEFAULT_INTERPOLATION_CONFIG); expect(catalog.write(serializer)).toContain(XLIFF_EXTRACTED); }); 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 XLIFF_TOMERGE = ` i18n attribute on tags attributs i18n sur les balises nested imbriqué nested imbriqué different meaning with placeholders avec des espaces réservés on not translatable node sur des balises non traductibles on translatable node sur des balises traductibles {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} } {VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup} } {VAR_SELECT, select, 0 {other} m {male} f {female} } {VAR_SELECT, select, 0 {autre} m {homme} f {femme}} {VAR_SELECT, select, m {male} f {female} } {VAR_SELECT, select, m {homme} f {femme} } sex = sexe = in a translatable section dans une section traductible Markers in html comments Balises dans les commentaires html it should work ca devrait marcher with an explicit ID avec un ID explicite {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} } {VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {beaucoup} } {VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found results} } {VAR_PLURAL, plural, =0 {Pas de réponse} =1 {une réponse} other {Found réponse} } desc foobar FOOBAR `; const XLIFF_EXTRACTED = ` i18n attribute on tags file.ts 3 nested file.ts 5 nested file.ts 7 different meaning with placeholders file.ts 9 file.ts 10 on not translatable node file.ts 13 on translatable node file.ts 14 {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} } file.ts 19 file.ts 36 file.ts 21 {VAR_SELECT, select, 0 {other} m {male} f {female} } file.ts 22 file.ts 24 {VAR_SELECT, select, m {male} f {female} } file.ts 25 file.ts 28 sex = file.ts 29 file.ts 30 in a translatable section file.ts 35 file.ts 53 Markers in html comments file.ts 33 it should work file.ts 39 with an explicit ID file.ts 41 {VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {many} } file.ts 42 {VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found results} } file.ts 45 desc foobar file.ts 53 file.ts 55 `;