/** * @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 {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'; export function main(): void { describe('XMB serializer', () => { const HTML = `

not translatable

translatable element with placeholders {{ interpolation}}

{ count, plural, =0 {

test

}}

foo

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

deeply nested

}} }}

`; const XMB = ` ]> translatable element <b>with placeholders</b> {VAR_PLURAL, plural, =0 {<p>test</p>} } foo {VAR_PLURAL, plural, =0 {{VAR_SELECT, select, 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 Xmb(); serializer.load(XMB, 'url'); }).toThrowError(/Unsupported/); }); }); } function toXmb(html: string): string { const catalog = new MessageBundle(new HtmlParser, [], {}); const serializer = new Xmb(); catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG); return catalog.write(serializer); }