| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 13:56:58 -07:00
										 |  |  | import {Xmb} from '@angular/compiler/src/i18n/serializers/xmb'; | 
					
						
							| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  | import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 13:56:58 -07:00
										 |  |  | import {MessageBundle} from '../../../src/i18n/message_bundle'; | 
					
						
							| 
									
										
										
										
											2016-08-01 12:19:09 -07:00
										 |  |  | import {HtmlParser} from '../../../src/ml_parser/html_parser'; | 
					
						
							|  |  |  | import {DEFAULT_INTERPOLATION_CONFIG} from '../../../src/ml_parser/interpolation_config'; | 
					
						
							| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main(): void { | 
					
						
							| 
									
										
										
										
											2016-07-21 13:56:58 -07:00
										 |  |  |   describe('XMB serializer', () => { | 
					
						
							| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  |     const HTML = `
 | 
					
						
							|  |  |  | <p>not translatable</p> | 
					
						
							|  |  |  | <p i18n>translatable element <b>with placeholders</b> {{ interpolation}}</p> | 
					
						
							|  |  |  | <!-- i18n -->{ count, plural, =0 {<p>test</p>}}<!-- /i18n --> | 
					
						
							|  |  |  | <p i18n="m|d">foo</p> | 
					
						
							|  |  |  | <p i18n>{ count, plural, =0 { { sex, gender, other {<p>deeply nested</p>}} }}</p>`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 21:26:03 -07:00
										 |  |  |     const XMB = `<?xml version="1.0" encoding="UTF-8" ?>
 | 
					
						
							| 
									
										
										
										
											2016-07-29 13:07:01 -07:00
										 |  |  | <!DOCTYPE messagebundle [ | 
					
						
							|  |  |  | <!ELEMENT messagebundle (msg)*> | 
					
						
							|  |  |  | <!ATTLIST messagebundle class CDATA #IMPLIED> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <!ELEMENT msg (#PCDATA|ph|source)*> | 
					
						
							|  |  |  | <!ATTLIST msg id CDATA #IMPLIED> | 
					
						
							|  |  |  | <!ATTLIST msg seq CDATA #IMPLIED> | 
					
						
							|  |  |  | <!ATTLIST msg name CDATA #IMPLIED> | 
					
						
							|  |  |  | <!ATTLIST msg desc CDATA #IMPLIED> | 
					
						
							|  |  |  | <!ATTLIST msg meaning CDATA #IMPLIED> | 
					
						
							|  |  |  | <!ATTLIST msg obsolete (obsolete) #IMPLIED> | 
					
						
							|  |  |  | <!ATTLIST msg xml:space (default|preserve) "default"> | 
					
						
							|  |  |  | <!ATTLIST msg is_hidden CDATA #IMPLIED> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <!ELEMENT source (#PCDATA)> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <!ELEMENT ph (#PCDATA|ex)*> | 
					
						
							|  |  |  | <!ATTLIST ph name CDATA #REQUIRED> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <!ELEMENT ex (#PCDATA)> | 
					
						
							|  |  |  | ]> | 
					
						
							| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  | <messagebundle> | 
					
						
							| 
									
										
										
										
											2016-08-08 12:44:48 -07:00
										 |  |  |   <msg id="ec1d033f2436133c14ab038286c4f5df4697484a">translatable element <ph name="START_BOLD_TEXT"><ex><b></ex></ph>with placeholders<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph> <ph name="INTERPOLATION"/></msg> | 
					
						
							| 
									
										
										
										
											2016-08-11 14:49:53 -07:00
										 |  |  |   <msg id="e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2">{ count, plural, =0 {<ph name="START_PARAGRAPH"><ex><p></ex></ph>test<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} }</msg> | 
					
						
							| 
									
										
										
										
											2016-08-08 12:44:48 -07:00
										 |  |  |   <msg id="db3e0a6a5a96481f60aec61d98c3eecddef5ac23" desc="d" meaning="m">foo</msg> | 
					
						
							| 
									
										
										
										
											2016-08-11 14:49:53 -07:00
										 |  |  |   <msg id="83dd87699b8c1779dd72277ef6e2d46ca58be042">{ count, plural, =0 {{ sex, gender, other {<ph name="START_PARAGRAPH"><ex><p></ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} } } }</msg> | 
					
						
							| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  | </messagebundle>`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should write a valid xmb file', () => { expect(toXmb(HTML)).toEqual(XMB); }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should throw when trying to load an xmb file', () => { | 
					
						
							|  |  |  |       expect(() => { | 
					
						
							| 
									
										
										
										
											2016-07-21 13:56:58 -07:00
										 |  |  |         const serializer = new Xmb(); | 
					
						
							| 
									
										
										
										
											2016-08-09 21:05:04 -07:00
										 |  |  |         serializer.load(XMB, 'url', null); | 
					
						
							|  |  |  |       }).toThrowError(/Unsupported/); | 
					
						
							| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function toXmb(html: string): string { | 
					
						
							| 
									
										
										
										
											2016-07-21 13:56:58 -07:00
										 |  |  |   let catalog = new MessageBundle(new HtmlParser, [], {}); | 
					
						
							|  |  |  |   const serializer = new Xmb(); | 
					
						
							| 
									
										
										
										
											2016-07-15 09:42:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return catalog.write(serializer); | 
					
						
							| 
									
										
										
										
											2016-08-04 19:35:41 +02:00
										 |  |  | } |