/** * @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 {Catalog} from '@angular/compiler/src/i18n/catalog'; import {XmbSerializer} from '@angular/compiler/src/i18n/serializers/xmb'; import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {HtmlParser} from '../../../src/html_parser/html_parser'; import {DEFAULT_INTERPOLATION_CONFIG} from '../../../src/html_parser/interpolation_config'; export function main(): void { ddescribe('XMB serializer', () => { const HTML = `

not translatable

translatable element with placeholders {{ interpolation}}

{ count, plural, =0 {

test

}}

foo

{ count, plural, =0 { { sex, gender, other {

deeply nested

}} }}

`; const XMB = ` translatable element <b>with placeholders</b> { count, plural, =0 {<p>test</p>}} foo { count, plural, =0 {{ sex, gender, other {<p>deeply nested</p>}} }} `; it('should write a valid xmb file', () => { expect(toXmb(HTML)).toEqual(XMB); }); it('should throw when trying to load an xmb file', () => { expect(() => { const serializer = new XmbSerializer(); serializer.load(XMB); }).toThrow(); }); }); } function toXmb(html: string): string { let catalog = new Catalog(new HtmlParser, [], {}); const serializer = new XmbSerializer(); catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG); return catalog.write(serializer); } // translatable // element <b>with placeholders</b> { count, plural, =0 {<p>test</p>}}foo{ count, plural, =0 {{ sex, gender, other {<p>deeply nested</p>}} }} // translatable // element <b>with placeholders</b> { count, plural, =0 {<p>test</p>}}{ count, // plural, =0 {{ sex, gender, other {<p>deeply // nested</p>}} }}foo