| 
									
										
										
										
											2016-08-11 21:00:35 -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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {NgLocalization} from '@angular/common'; | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  | import {ResourceLoader} from '@angular/compiler'; | 
					
						
							| 
									
										
										
										
											2016-12-22 11:23:35 -08:00
										 |  |  | 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'; | 
					
						
							| 
									
										
										
										
											2017-03-13 11:40:22 +01:00
										 |  |  | import {DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core'; | 
					
						
							|  |  |  | import {ComponentFixture, TestBed, async} from '@angular/core/testing'; | 
					
						
							| 
									
										
										
										
											2017-03-02 12:12:46 -08:00
										 |  |  | import {expect} from '@angular/platform-browser/testing/src/matchers'; | 
					
						
							| 
									
										
										
										
											2016-08-19 12:51:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {SpyResourceLoader} from '../spies'; | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 11:40:22 +01:00
										 |  |  | import {FrLocalization, HTML, I18nComponent, validateHtml} from './integration_common'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2017-03-13 11:40:22 +01:00
										 |  |  |   describe('i18n XMB/XTB integration spec', () => { | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 12:51:01 -07:00
										 |  |  |     beforeEach(async(() => { | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  |       TestBed.configureCompiler({ | 
					
						
							|  |  |  |         providers: [ | 
					
						
							| 
									
										
										
										
											2016-08-17 09:24:44 -07:00
										 |  |  |           {provide: ResourceLoader, useClass: SpyResourceLoader}, | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  |           {provide: NgLocalization, useClass: FrLocalization}, | 
					
						
							| 
									
										
										
										
											2016-08-12 14:45:36 -07:00
										 |  |  |           {provide: TRANSLATIONS, useValue: XTB}, | 
					
						
							| 
									
										
										
										
											2016-08-12 22:13:54 -07:00
										 |  |  |           {provide: TRANSLATIONS_FORMAT, useValue: 'xtb'}, | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  |         ] | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-08-19 12:51:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       TestBed.configureTestingModule({declarations: [I18nComponent]}); | 
					
						
							|  |  |  |     })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-22 11:23:35 -08:00
										 |  |  |     it('should extract from templates', () => { | 
					
						
							|  |  |  |       const catalog = new MessageBundle(new HtmlParser, [], {}); | 
					
						
							|  |  |  |       const serializer = new Xmb(); | 
					
						
							| 
									
										
										
										
											2017-04-14 18:06:25 +02:00
										 |  |  |       catalog.updateFromTemplate(HTML, 'file.ts', DEFAULT_INTERPOLATION_CONFIG); | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-22 11:23:35 -08:00
										 |  |  |       expect(catalog.write(serializer)).toContain(XMB); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should translate templates', () => { | 
					
						
							| 
									
										
										
										
											2017-03-13 11:40:22 +01:00
										 |  |  |       const tb: ComponentFixture<I18nComponent> = | 
					
						
							|  |  |  |           TestBed.overrideTemplate(I18nComponent, HTML).createComponent(I18nComponent); | 
					
						
							|  |  |  |       const cmp: I18nComponent = tb.componentInstance; | 
					
						
							|  |  |  |       const el: DebugElement = tb.debugElement; | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 11:40:22 +01:00
										 |  |  |       validateHtml(tb, cmp, el); | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const XTB = `
 | 
					
						
							|  |  |  | <translationbundle> | 
					
						
							| 
									
										
										
										
											2016-11-07 16:20:05 -08:00
										 |  |  |   <translation id="615790887472569365">attributs i18n sur les balises</translation> | 
					
						
							|  |  |  |   <translation id="3707494640264351337">imbriqué</translation> | 
					
						
							|  |  |  |   <translation id="5539162898278769904">imbriqué</translation> | 
					
						
							|  |  |  |   <translation id="3780349238193953556"><ph name="START_ITALIC_TEXT"/>avec des espaces réservés<ph name="CLOSE_ITALIC_TEXT"/></translation> | 
					
						
							|  |  |  |   <translation id="5525133077318024839">sur des balises non traductibles</translation> | 
					
						
							|  |  |  |   <translation id="8670732454866344690">sur des balises traductibles</translation> | 
					
						
							|  |  |  |   <translation id="4593805537723189714">{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {<ph name="START_BOLD_TEXT"/>beaucoup<ph name="CLOSE_BOLD_TEXT"/>}}</translation> | 
					
						
							|  |  |  |   <translation id="1746565782635215"><ph name="ICU"/></translation> | 
					
						
							|  |  |  |   <translation id="5868084092545682515">{VAR_SELECT, select, m {homme} f {femme}}</translation> | 
					
						
							|  |  |  |   <translation id="4851788426695310455"><ph name="INTERPOLATION"/></translation> | 
					
						
							|  |  |  |   <translation id="9013357158046221374">sexe = <ph name="INTERPOLATION"/></translation> | 
					
						
							|  |  |  |   <translation id="8324617391167353662"><ph name="CUSTOM_NAME"/></translation> | 
					
						
							|  |  |  |   <translation id="7685649297917455806">dans une section traductible</translation> | 
					
						
							|  |  |  |   <translation id="2387287228265107305"> | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  |     <ph name="START_HEADING_LEVEL1"/>Balises dans les commentaires html<ph name="CLOSE_HEADING_LEVEL1"/>    | 
					
						
							|  |  |  |     <ph name="START_TAG_DIV"/><ph name="CLOSE_TAG_DIV"/> | 
					
						
							|  |  |  |     <ph name="START_TAG_DIV_1"/><ph name="ICU"/><ph name="CLOSE_TAG_DIV"></ph> | 
					
						
							|  |  |  | </translation> | 
					
						
							| 
									
										
										
										
											2016-11-07 16:20:05 -08:00
										 |  |  |   <translation id="1491627405349178954">ca <ph name="START_BOLD_TEXT"/>devrait<ph name="CLOSE_BOLD_TEXT"/> marcher</translation> | 
					
						
							| 
									
										
										
										
											2016-12-06 15:04:59 +01:00
										 |  |  |   <translation id="i18n16">avec un ID explicite</translation> | 
					
						
							|  |  |  |   <translation id="i18n17">{VAR_PLURAL, plural, =0 {zero} =1 {un} =2 {deux} other {<ph  | 
					
						
							|  |  |  |   name="START_BOLD_TEXT"><ex><b></ex></ph>beaucoup<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph>} }</translation> | 
					
						
							| 
									
										
										
										
											2017-01-06 11:28:09 -08:00
										 |  |  |   <translation id="4085484936881858615">{VAR_PLURAL, plural, =0 {Pas de réponse} =1 {une réponse} other {<ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph> réponse} }</translation> | 
					
						
							|  |  |  |   <translation id="4035252431381981115">FOO<ph name="START_LINK"><ex><a></ex></ph>BAR<ph name="CLOSE_LINK"><ex></a></ex></ph></translation> | 
					
						
							| 
									
										
										
										
											2017-01-17 17:36:16 -08:00
										 |  |  |   <translation id="5339604010413301604"><ph name="MAP_NAME"><ex>MAP_NAME</ex></ph></translation> | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  | </translationbundle>`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 18:06:25 +02:00
										 |  |  | const XMB = ` <msg id="615790887472569365"><source>file.ts:3</source>i18n attribute on tags</msg>
 | 
					
						
							|  |  |  |   <msg id="3707494640264351337"><source>file.ts:5</source>nested</msg> | 
					
						
							|  |  |  |   <msg id="5539162898278769904" meaning="different meaning"><source>file.ts:7</source>nested</msg> | 
					
						
							|  |  |  |   <msg id="3780349238193953556"><source>file.ts:9</source><source>file.ts:10</source><ph name="START_ITALIC_TEXT"><ex><i></ex></ph>with placeholders<ph name="CLOSE_ITALIC_TEXT"><ex></i></ex></ph></msg> | 
					
						
							|  |  |  |   <msg id="5525133077318024839"><source>file.ts:13</source>on not translatable node</msg> | 
					
						
							|  |  |  |   <msg id="8670732454866344690"><source>file.ts:14</source>on translatable node</msg> | 
					
						
							|  |  |  |   <msg id="4593805537723189714"><source>file.ts:19</source><source>file.ts:36</source>{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<ph name="START_BOLD_TEXT"><ex><b></ex></ph>many<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph>} }</msg> | 
					
						
							|  |  |  |   <msg id="1746565782635215"><source>file.ts:21,23</source><source>file.ts:24,26</source> | 
					
						
							| 
									
										
										
										
											2016-12-22 10:17:41 -08:00
										 |  |  |         <ph name="ICU"><ex>ICU</ex></ph> | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  |     </msg> | 
					
						
							| 
									
										
										
										
											2017-04-14 18:06:25 +02:00
										 |  |  |   <msg id="5868084092545682515"><source>file.ts:22</source><source>file.ts:25</source>{VAR_SELECT, select, m {male} f {female} }</msg> | 
					
						
							|  |  |  |   <msg id="4851788426695310455"><source>file.ts:28</source><ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph></msg> | 
					
						
							|  |  |  |   <msg id="9013357158046221374"><source>file.ts:29</source>sex = <ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph></msg> | 
					
						
							|  |  |  |   <msg id="8324617391167353662"><source>file.ts:30</source><ph name="CUSTOM_NAME"><ex>CUSTOM_NAME</ex></ph></msg> | 
					
						
							|  |  |  |   <msg id="7685649297917455806"><source>file.ts:35</source><source>file.ts:53</source>in a translatable section</msg> | 
					
						
							|  |  |  |   <msg id="2387287228265107305"><source>file.ts:33,37</source> | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  |     <ph name="START_HEADING_LEVEL1"><ex><h1></ex></ph>Markers in html comments<ph name="CLOSE_HEADING_LEVEL1"><ex></h1></ex></ph>    | 
					
						
							|  |  |  |     <ph name="START_TAG_DIV"><ex><div></ex></ph><ph name="CLOSE_TAG_DIV"><ex></div></ex></ph> | 
					
						
							| 
									
										
										
										
											2016-12-22 10:17:41 -08:00
										 |  |  |     <ph name="START_TAG_DIV_1"><ex><div></ex></ph><ph name="ICU"><ex>ICU</ex></ph><ph name="CLOSE_TAG_DIV"><ex></div></ex></ph> | 
					
						
							| 
									
										
										
										
											2016-08-11 21:00:35 -07:00
										 |  |  | </msg> | 
					
						
							| 
									
										
										
										
											2017-04-14 18:06:25 +02:00
										 |  |  |   <msg id="1491627405349178954"><source>file.ts:39</source>it <ph name="START_BOLD_TEXT"><ex><b></ex></ph>should<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph> work</msg> | 
					
						
							|  |  |  |   <msg id="i18n16"><source>file.ts:41</source>with an explicit ID</msg> | 
					
						
							|  |  |  |   <msg id="i18n17"><source>file.ts:42</source>{VAR_PLURAL, plural, =0 {zero} =1 {one} =2 {two} other {<ph name="START_BOLD_TEXT"><ex><b></ex></ph>many<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph>} }</msg> | 
					
						
							|  |  |  |   <msg id="4085484936881858615" desc="desc"><source>file.ts:45,51</source>{VAR_PLURAL, plural, =0 {Found no results} =1 {Found one result} other {Found <ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph> results} }</msg> | 
					
						
							|  |  |  |   <msg id="4035252431381981115"><source>file.ts:53</source>foo<ph name="START_LINK"><ex><a></ex></ph>bar<ph name="CLOSE_LINK"><ex></a></ex></ph></msg> | 
					
						
							|  |  |  |   <msg id="5339604010413301604"><source>file.ts:55</source><ph name="MAP_NAME"><ex>MAP_NAME</ex></ph></msg>`;
 |