From 1ef2d36a27a5074bf6e7f3bd4f9dc63c91e166c2 Mon Sep 17 00:00:00 2001 From: Olivier Combe <olivier.combe@gmail.com> Date: Fri, 24 Feb 2017 17:08:54 +0100 Subject: [PATCH] feat(compiler): add source files to xmb/xliff translations Fixes #14190 --- aio/content/images/bios/alex-eagle.jpg | Bin aio/content/images/bios/alex-rickabaugh.jpg | Bin aio/content/images/bios/alex-wolfe.jpg | Bin aio/content/images/bios/ali.jpg | Bin .../bios/angular-gde-bio-placeholder.png | Bin aio/content/images/bios/brad-green.jpg | Bin aio/content/images/bios/brandonroberts.jpg | Bin aio/content/images/bios/chuckj.jpg | Bin aio/content/images/bios/crisbeto.jpg | Bin aio/content/images/bios/david-east.jpg | Bin aio/content/images/bios/deborah.jpg | Bin aio/content/images/bios/eladbezalel.jpg | Bin aio/content/images/bios/eric.jpg | Bin aio/content/images/bios/fatima.jpg | Bin aio/content/images/bios/filipe-silva.jpg | Bin aio/content/images/bios/gkalpak.jpg | Bin aio/content/images/bios/hansl.jpg | Bin aio/content/images/bios/igor-minar.jpg | Bin aio/content/images/bios/jbedard.jpg | Bin aio/content/images/bios/jeff-cross.jpg | Bin aio/content/images/bios/jeffwhelpley.jpg | Bin aio/content/images/bios/jelbourn.jpg | Bin aio/content/images/bios/jesus-rodriguez.jpg | Bin aio/content/images/bios/john-papa.jpg | Bin aio/content/images/bios/juleskremer.jpg | Bin aio/content/images/bios/julie-ralph.jpg | Bin aio/content/images/bios/kapunahelewong.jpg | Bin aio/content/images/bios/kara-erickson.jpg | Bin aio/content/images/bios/kathy.jpg | Bin aio/content/images/bios/lucas.jpg | Bin aio/content/images/bios/marclaval.jpg | Bin aio/content/images/bios/marcy.jpg | Bin aio/content/images/bios/martin-probst.jpg | Bin aio/content/images/bios/martinstaffa.jpg | Bin aio/content/images/bios/matias.jpg | Bin aio/content/images/bios/max-sills.jpg | Bin aio/content/images/bios/michal.jpg | Bin aio/content/images/bios/misko.jpg | Bin aio/content/images/bios/naomi.jpg | Bin aio/content/images/bios/pascalprecht.jpg | Bin aio/content/images/bios/patrick-stapleton.jpg | Bin aio/content/images/bios/pawel.jpg | Bin aio/content/images/bios/pete.jpg | Bin aio/content/images/bios/rado.jpg | Bin aio/content/images/bios/ralph.jpg | Bin aio/content/images/bios/rex.jpg | Bin aio/content/images/bios/rmesserle.jpg | Bin aio/content/images/bios/rob-wormald.jpg | Bin aio/content/images/bios/ryan.jpg | Bin aio/content/images/bios/scott.jpg | Bin aio/content/images/bios/shahar.jpg | Bin aio/content/images/bios/shannon.jpg | Bin .../images/bios/shield-bio-placeholder.png | Bin aio/content/images/bios/stephenfluin.jpg | Bin aio/content/images/bios/teropa.jpg | Bin aio/content/images/bios/thomas.jpg | Bin aio/content/images/bios/tobias.jpg | Bin aio/content/images/bios/tonyc.jpg | Bin aio/content/images/bios/topherfangio.jpg | Bin aio/content/images/bios/torgeirhelgevold.jpg | Bin aio/content/images/bios/victor.jpg | Bin aio/content/images/bios/vikram.jpg | Bin aio/content/images/bios/wardbell.jpg | Bin .../logos/angular/angular-logo-banner.png | Bin .../assets/images/logos/angular/angular.png | Bin .../assets/images/logos/angular/angular.svg | 0 .../logos/angular/angular_solidBlack.png | Bin .../logos/angular/angular_solidBlack.svg | 0 .../angular/angular_whiteTransparent.png | Bin .../images/logos/angular/shield-with-beta.png | Bin .../integrationtest/src/entry_components.ts | 6 +- .../integrationtest/test/i18n_spec.ts | 28 +++++++-- .../integrationtest/test/ng_module_spec.ts | 3 +- .../third_party_src/other_comp.ts | 5 +- packages/compiler-cli/src/extractor.ts | 5 +- packages/compiler/src/i18n/i18n_ast.ts | 27 +++++++- packages/compiler/src/i18n/message_bundle.ts | 12 +++- .../compiler/src/i18n/serializers/xliff.ts | 18 +++++- packages/compiler/src/i18n/serializers/xmb.ts | 12 +++- packages/compiler/test/i18n/digest_spec.ts | 1 + .../test/i18n/serializers/xliff_spec.ts | 59 +++++++++++++++++- .../test/i18n/serializers/xmb_spec.ts | 28 +++++---- .../test/i18n/translation_bundle_spec.ts | 5 +- 83 files changed, 177 insertions(+), 32 deletions(-) mode change 100644 => 100755 aio/content/images/bios/alex-eagle.jpg mode change 100644 => 100755 aio/content/images/bios/alex-rickabaugh.jpg mode change 100644 => 100755 aio/content/images/bios/alex-wolfe.jpg mode change 100644 => 100755 aio/content/images/bios/ali.jpg mode change 100644 => 100755 aio/content/images/bios/angular-gde-bio-placeholder.png mode change 100644 => 100755 aio/content/images/bios/brad-green.jpg mode change 100644 => 100755 aio/content/images/bios/brandonroberts.jpg mode change 100644 => 100755 aio/content/images/bios/chuckj.jpg mode change 100644 => 100755 aio/content/images/bios/crisbeto.jpg mode change 100644 => 100755 aio/content/images/bios/david-east.jpg mode change 100644 => 100755 aio/content/images/bios/deborah.jpg mode change 100644 => 100755 aio/content/images/bios/eladbezalel.jpg mode change 100644 => 100755 aio/content/images/bios/eric.jpg mode change 100644 => 100755 aio/content/images/bios/fatima.jpg mode change 100644 => 100755 aio/content/images/bios/filipe-silva.jpg mode change 100644 => 100755 aio/content/images/bios/gkalpak.jpg mode change 100644 => 100755 aio/content/images/bios/hansl.jpg mode change 100644 => 100755 aio/content/images/bios/igor-minar.jpg mode change 100644 => 100755 aio/content/images/bios/jbedard.jpg mode change 100644 => 100755 aio/content/images/bios/jeff-cross.jpg mode change 100644 => 100755 aio/content/images/bios/jeffwhelpley.jpg mode change 100644 => 100755 aio/content/images/bios/jelbourn.jpg mode change 100644 => 100755 aio/content/images/bios/jesus-rodriguez.jpg mode change 100644 => 100755 aio/content/images/bios/john-papa.jpg mode change 100644 => 100755 aio/content/images/bios/juleskremer.jpg mode change 100644 => 100755 aio/content/images/bios/julie-ralph.jpg mode change 100644 => 100755 aio/content/images/bios/kapunahelewong.jpg mode change 100644 => 100755 aio/content/images/bios/kara-erickson.jpg mode change 100644 => 100755 aio/content/images/bios/kathy.jpg mode change 100644 => 100755 aio/content/images/bios/lucas.jpg mode change 100644 => 100755 aio/content/images/bios/marclaval.jpg mode change 100644 => 100755 aio/content/images/bios/marcy.jpg mode change 100644 => 100755 aio/content/images/bios/martin-probst.jpg mode change 100644 => 100755 aio/content/images/bios/martinstaffa.jpg mode change 100644 => 100755 aio/content/images/bios/matias.jpg mode change 100644 => 100755 aio/content/images/bios/max-sills.jpg mode change 100644 => 100755 aio/content/images/bios/michal.jpg mode change 100644 => 100755 aio/content/images/bios/misko.jpg mode change 100644 => 100755 aio/content/images/bios/naomi.jpg mode change 100644 => 100755 aio/content/images/bios/pascalprecht.jpg mode change 100644 => 100755 aio/content/images/bios/patrick-stapleton.jpg mode change 100644 => 100755 aio/content/images/bios/pawel.jpg mode change 100644 => 100755 aio/content/images/bios/pete.jpg mode change 100644 => 100755 aio/content/images/bios/rado.jpg mode change 100644 => 100755 aio/content/images/bios/ralph.jpg mode change 100644 => 100755 aio/content/images/bios/rex.jpg mode change 100644 => 100755 aio/content/images/bios/rmesserle.jpg mode change 100644 => 100755 aio/content/images/bios/rob-wormald.jpg mode change 100644 => 100755 aio/content/images/bios/ryan.jpg mode change 100644 => 100755 aio/content/images/bios/scott.jpg mode change 100644 => 100755 aio/content/images/bios/shahar.jpg mode change 100644 => 100755 aio/content/images/bios/shannon.jpg mode change 100644 => 100755 aio/content/images/bios/shield-bio-placeholder.png mode change 100644 => 100755 aio/content/images/bios/stephenfluin.jpg mode change 100644 => 100755 aio/content/images/bios/teropa.jpg mode change 100644 => 100755 aio/content/images/bios/thomas.jpg mode change 100644 => 100755 aio/content/images/bios/tobias.jpg mode change 100644 => 100755 aio/content/images/bios/tonyc.jpg mode change 100644 => 100755 aio/content/images/bios/topherfangio.jpg mode change 100644 => 100755 aio/content/images/bios/torgeirhelgevold.jpg mode change 100644 => 100755 aio/content/images/bios/victor.jpg mode change 100644 => 100755 aio/content/images/bios/vikram.jpg mode change 100644 => 100755 aio/content/images/bios/wardbell.jpg mode change 100644 => 100755 aio/src/assets/images/logos/angular/angular-logo-banner.png mode change 100644 => 100755 aio/src/assets/images/logos/angular/angular.png mode change 100644 => 100755 aio/src/assets/images/logos/angular/angular.svg mode change 100644 => 100755 aio/src/assets/images/logos/angular/angular_solidBlack.png mode change 100644 => 100755 aio/src/assets/images/logos/angular/angular_solidBlack.svg mode change 100644 => 100755 aio/src/assets/images/logos/angular/angular_whiteTransparent.png mode change 100644 => 100755 aio/src/assets/images/logos/angular/shield-with-beta.png diff --git a/aio/content/images/bios/alex-eagle.jpg b/aio/content/images/bios/alex-eagle.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/alex-rickabaugh.jpg b/aio/content/images/bios/alex-rickabaugh.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/alex-wolfe.jpg b/aio/content/images/bios/alex-wolfe.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/ali.jpg b/aio/content/images/bios/ali.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/angular-gde-bio-placeholder.png b/aio/content/images/bios/angular-gde-bio-placeholder.png old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/brad-green.jpg b/aio/content/images/bios/brad-green.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/brandonroberts.jpg b/aio/content/images/bios/brandonroberts.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/chuckj.jpg b/aio/content/images/bios/chuckj.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/crisbeto.jpg b/aio/content/images/bios/crisbeto.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/david-east.jpg b/aio/content/images/bios/david-east.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/deborah.jpg b/aio/content/images/bios/deborah.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/eladbezalel.jpg b/aio/content/images/bios/eladbezalel.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/eric.jpg b/aio/content/images/bios/eric.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/fatima.jpg b/aio/content/images/bios/fatima.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/filipe-silva.jpg b/aio/content/images/bios/filipe-silva.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/gkalpak.jpg b/aio/content/images/bios/gkalpak.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/hansl.jpg b/aio/content/images/bios/hansl.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/igor-minar.jpg b/aio/content/images/bios/igor-minar.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/jbedard.jpg b/aio/content/images/bios/jbedard.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/jeff-cross.jpg b/aio/content/images/bios/jeff-cross.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/jeffwhelpley.jpg b/aio/content/images/bios/jeffwhelpley.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/jelbourn.jpg b/aio/content/images/bios/jelbourn.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/jesus-rodriguez.jpg b/aio/content/images/bios/jesus-rodriguez.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/john-papa.jpg b/aio/content/images/bios/john-papa.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/juleskremer.jpg b/aio/content/images/bios/juleskremer.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/julie-ralph.jpg b/aio/content/images/bios/julie-ralph.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/kapunahelewong.jpg b/aio/content/images/bios/kapunahelewong.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/kara-erickson.jpg b/aio/content/images/bios/kara-erickson.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/kathy.jpg b/aio/content/images/bios/kathy.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/lucas.jpg b/aio/content/images/bios/lucas.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/marclaval.jpg b/aio/content/images/bios/marclaval.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/marcy.jpg b/aio/content/images/bios/marcy.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/martin-probst.jpg b/aio/content/images/bios/martin-probst.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/martinstaffa.jpg b/aio/content/images/bios/martinstaffa.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/matias.jpg b/aio/content/images/bios/matias.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/max-sills.jpg b/aio/content/images/bios/max-sills.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/michal.jpg b/aio/content/images/bios/michal.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/misko.jpg b/aio/content/images/bios/misko.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/naomi.jpg b/aio/content/images/bios/naomi.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/pascalprecht.jpg b/aio/content/images/bios/pascalprecht.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/patrick-stapleton.jpg b/aio/content/images/bios/patrick-stapleton.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/pawel.jpg b/aio/content/images/bios/pawel.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/pete.jpg b/aio/content/images/bios/pete.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/rado.jpg b/aio/content/images/bios/rado.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/ralph.jpg b/aio/content/images/bios/ralph.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/rex.jpg b/aio/content/images/bios/rex.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/rmesserle.jpg b/aio/content/images/bios/rmesserle.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/rob-wormald.jpg b/aio/content/images/bios/rob-wormald.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/ryan.jpg b/aio/content/images/bios/ryan.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/scott.jpg b/aio/content/images/bios/scott.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/shahar.jpg b/aio/content/images/bios/shahar.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/shannon.jpg b/aio/content/images/bios/shannon.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/shield-bio-placeholder.png b/aio/content/images/bios/shield-bio-placeholder.png old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/stephenfluin.jpg b/aio/content/images/bios/stephenfluin.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/teropa.jpg b/aio/content/images/bios/teropa.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/thomas.jpg b/aio/content/images/bios/thomas.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/tobias.jpg b/aio/content/images/bios/tobias.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/tonyc.jpg b/aio/content/images/bios/tonyc.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/topherfangio.jpg b/aio/content/images/bios/topherfangio.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/torgeirhelgevold.jpg b/aio/content/images/bios/torgeirhelgevold.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/victor.jpg b/aio/content/images/bios/victor.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/vikram.jpg b/aio/content/images/bios/vikram.jpg old mode 100644 new mode 100755 diff --git a/aio/content/images/bios/wardbell.jpg b/aio/content/images/bios/wardbell.jpg old mode 100644 new mode 100755 diff --git a/aio/src/assets/images/logos/angular/angular-logo-banner.png b/aio/src/assets/images/logos/angular/angular-logo-banner.png old mode 100644 new mode 100755 diff --git a/aio/src/assets/images/logos/angular/angular.png b/aio/src/assets/images/logos/angular/angular.png old mode 100644 new mode 100755 diff --git a/aio/src/assets/images/logos/angular/angular.svg b/aio/src/assets/images/logos/angular/angular.svg old mode 100644 new mode 100755 diff --git a/aio/src/assets/images/logos/angular/angular_solidBlack.png b/aio/src/assets/images/logos/angular/angular_solidBlack.png old mode 100644 new mode 100755 diff --git a/aio/src/assets/images/logos/angular/angular_solidBlack.svg b/aio/src/assets/images/logos/angular/angular_solidBlack.svg old mode 100644 new mode 100755 diff --git a/aio/src/assets/images/logos/angular/angular_whiteTransparent.png b/aio/src/assets/images/logos/angular/angular_whiteTransparent.png old mode 100644 new mode 100755 diff --git a/aio/src/assets/images/logos/angular/shield-with-beta.png b/aio/src/assets/images/logos/angular/shield-with-beta.png old mode 100644 new mode 100755 diff --git a/packages/compiler-cli/integrationtest/src/entry_components.ts b/packages/compiler-cli/integrationtest/src/entry_components.ts index f969dd25d2941f..463ba825545460 100644 --- a/packages/compiler-cli/integrationtest/src/entry_components.ts +++ b/packages/compiler-cli/integrationtest/src/entry_components.ts @@ -10,7 +10,11 @@ import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Injec import {BasicComp} from './basic'; -@Component({selector: 'cmp-entryComponents', template: '', entryComponents: [BasicComp]}) +@Component({ + selector: 'cmp-entryComponents', + template: '<p i18n>Welcome</p>', + entryComponents: [BasicComp] +}) export class CompWithEntryComponents { constructor(public cfr: ComponentFactoryResolver) {} } diff --git a/packages/compiler-cli/integrationtest/test/i18n_spec.ts b/packages/compiler-cli/integrationtest/test/i18n_spec.ts index 019b354ce9c03a..92fdc3199e6281 100644 --- a/packages/compiler-cli/integrationtest/test/i18n_spec.ts +++ b/packages/compiler-cli/integrationtest/test/i18n_spec.ts @@ -34,9 +34,10 @@ const EXPECTED_XMB = `<?xml version="1.0" encoding="UTF-8" ?> <!ELEMENT ex (#PCDATA)> ]> <messagebundle> - <msg id="8136548302122759730" desc="desc" meaning="meaning">translate me</msg> - <msg id="3492007542396725315">Welcome</msg> - <msg id="3772663375917578720">other-3rdP-component</msg> + <msg id="8136548302122759730" desc="desc" meaning="meaning"><source>src/basic.ts:1</source>translate me</msg> + <msg id="3492007542396725315"><source>src/basic.ts:5</source><source>src/entry_components.ts:1</source>Welcome</msg> + <msg id="126808141597411718"><source>node_modules/third_party/other_comp.d.ts:1,2</source>other-3rdP-component +multi-lines</msg> </messagebundle> `; @@ -47,16 +48,33 @@ const EXPECTED_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?> <trans-unit id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4" datatype="html"> <source>translate me</source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">src/basic.ts</context> + <context context-type="linenumber">1</context> + </context-group> <note priority="1" from="description">desc</note> <note priority="1" from="meaning">meaning</note> </trans-unit> <trans-unit id="65cc4ab3b4c438e07c89be2b677d08369fb62da2" datatype="html"> <source>Welcome</source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">src/basic.ts</context> + <context context-type="linenumber">5</context> + </context-group> + <context-group purpose="location"> + <context context-type="sourcefile">src/entry_components.ts</context> + <context context-type="linenumber">1</context> + </context-group> </trans-unit> - <trans-unit id="63a85808f03b8181e36a952e0fa38202c2304862" datatype="html"> - <source>other-3rdP-component</source> + <trans-unit id="b0a17f08a4bd742b2acf39780c257c2f519d33ed" datatype="html"> + <source>other-3rdP-component +multi-lines</source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">node_modules/third_party/other_comp.d.ts</context> + <context context-type="linenumber">1</context> + </context-group> </trans-unit> </body> </file> diff --git a/packages/compiler-cli/integrationtest/test/ng_module_spec.ts b/packages/compiler-cli/integrationtest/test/ng_module_spec.ts index b5b76ad41afc4b..4e8a2706dfb4b1 100644 --- a/packages/compiler-cli/integrationtest/test/ng_module_spec.ts +++ b/packages/compiler-cli/integrationtest/test/ng_module_spec.ts @@ -59,7 +59,8 @@ describe('NgModule', () => { const fixture = createComponent(ComponentUsingThirdParty); const thirdPComps = fixture.nativeElement.children; expect(thirdPComps[0].children[0].children[0].data).toEqual('3rdP-component'); - expect(thirdPComps[1].children[0].children[0].data).toEqual('other-3rdP-component'); + expect(thirdPComps[1].children[0].children[0].data).toEqual(`other-3rdP-component +multi-lines`); }); // https://github.com/angular/angular/issues/12428 diff --git a/packages/compiler-cli/integrationtest/third_party_src/other_comp.ts b/packages/compiler-cli/integrationtest/third_party_src/other_comp.ts index 553e08ba45a3fd..130baabd8f564e 100644 --- a/packages/compiler-cli/integrationtest/third_party_src/other_comp.ts +++ b/packages/compiler-cli/integrationtest/third_party_src/other_comp.ts @@ -10,7 +10,8 @@ import {Component} from '@angular/core'; @Component({ selector: 'another-third-party-comp', - template: '<div i18n>other-3rdP-component</div>', + template: `<div i18n>other-3rdP-component +multi-lines</div>`, }) export class AnotherThirdpartyComponent { -} \ No newline at end of file +} diff --git a/packages/compiler-cli/src/extractor.ts b/packages/compiler-cli/src/extractor.ts index 1d929c8e7a2145..68ee22585a2613 100644 --- a/packages/compiler-cli/src/extractor.ts +++ b/packages/compiler-cli/src/extractor.ts @@ -59,8 +59,9 @@ export class Extractor { default: serializer = new compiler.Xliff(); } - - return bundle.write(serializer); + return bundle.write( + serializer, + (sourcePath: string) => sourcePath.replace(path.join(this.options.basePath, '/'), '')); } getExtension(formatName: string): string { diff --git a/packages/compiler/src/i18n/i18n_ast.ts b/packages/compiler/src/i18n/i18n_ast.ts index 1e94ea416f7d55..c2d18649341f68 100644 --- a/packages/compiler/src/i18n/i18n_ast.ts +++ b/packages/compiler/src/i18n/i18n_ast.ts @@ -9,6 +9,8 @@ import {ParseSourceSpan} from '../parse_util'; export class Message { + sources: MessageSpan[]; + /** * @param nodes message AST * @param placeholders maps placeholder names to static content @@ -20,7 +22,28 @@ export class Message { constructor( public nodes: Node[], public placeholders: {[phName: string]: string}, public placeholderToMessage: {[phName: string]: Message}, public meaning: string, - public description: string, public id: string) {} + public description: string, public id: string) { + if (nodes.length) { + this.sources = [{ + filePath: nodes[0].sourceSpan.start.file.url, + startLine: nodes[0].sourceSpan.start.line + 1, + startCol: nodes[0].sourceSpan.start.col + 1, + endLine: nodes[nodes.length - 1].sourceSpan.end.line + 1, + endCol: nodes[0].sourceSpan.start.col + 1 + }]; + } else { + this.sources = []; + } + } +} + +// line and columns indexes are 1 based +export interface MessageSpan { + filePath: string; + startLine: number; + startCol: number; + endLine: number; + endCol: number; } export interface Node { @@ -131,4 +154,4 @@ export class RecurseVisitor implements Visitor { visitPlaceholder(ph: Placeholder, context?: any): any{}; visitIcuPlaceholder(ph: IcuPlaceholder, context?: any): any{}; -} \ No newline at end of file +} diff --git a/packages/compiler/src/i18n/message_bundle.ts b/packages/compiler/src/i18n/message_bundle.ts index 8016bc0d3f3980..54c72455800d80 100644 --- a/packages/compiler/src/i18n/message_bundle.ts +++ b/packages/compiler/src/i18n/message_bundle.ts @@ -48,7 +48,7 @@ export class MessageBundle { // The public (serialized) format might be different, see the `write` method. getMessages(): i18n.Message[] { return this._messages; } - write(serializer: Serializer): string { + write(serializer: Serializer, filterSources?: (path: string) => string): string { const messages: {[id: string]: i18n.Message} = {}; const mapperVisitor = new MapPlaceholderNames(); @@ -57,6 +57,8 @@ export class MessageBundle { const id = serializer.digest(message); if (!messages.hasOwnProperty(id)) { messages[id] = message; + } else { + messages[id].sources.push(...message.sources); } }); @@ -65,7 +67,13 @@ export class MessageBundle { const mapper = serializer.createNameMapper(messages[id]); const src = messages[id]; const nodes = mapper ? mapperVisitor.convert(src.nodes, mapper) : src.nodes; - return new i18n.Message(nodes, {}, {}, src.meaning, src.description, id); + let transformedMessage = new i18n.Message(nodes, {}, {}, src.meaning, src.description, id); + transformedMessage.sources = src.sources; + if (filterSources) { + transformedMessage.sources.forEach( + (source: i18n.MessageSpan) => source.filePath = filterSources(source.filePath)); + } + return transformedMessage; }); return serializer.write(msgList, this._locale); diff --git a/packages/compiler/src/i18n/serializers/xliff.ts b/packages/compiler/src/i18n/serializers/xliff.ts index dbc9fffb8ffe11..f64e9a58f15df2 100644 --- a/packages/compiler/src/i18n/serializers/xliff.ts +++ b/packages/compiler/src/i18n/serializers/xliff.ts @@ -25,6 +25,8 @@ const _FILE_TAG = 'file'; const _SOURCE_TAG = 'source'; const _TARGET_TAG = 'target'; const _UNIT_TAG = 'trans-unit'; +const _CONTEXT_GROUP_TAG = 'context-group'; +const _CONTEXT_TAG = 'context'; // http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html // http://docs.oasis-open.org/xliff/v1.2/xliff-profile-html/xliff-profile-html-1.2.html @@ -34,10 +36,24 @@ export class Xliff extends Serializer { const transUnits: xml.Node[] = []; messages.forEach(message => { + let contextTags: xml.Node[] = []; + message.sources.forEach((source: i18n.MessageSpan) => { + let contextGroupTag = new xml.Tag(_CONTEXT_GROUP_TAG, {purpose: 'location'}); + contextGroupTag.children.push( + new xml.CR(10), + new xml.Tag( + _CONTEXT_TAG, {'context-type': 'sourcefile'}, [new xml.Text(source.filePath)]), + new xml.CR(10), new xml.Tag( + _CONTEXT_TAG, {'context-type': 'linenumber'}, + [new xml.Text(`${source.startLine}`)]), + new xml.CR(8)); + contextTags.push(new xml.CR(8), contextGroupTag); + }); + const transUnit = new xml.Tag(_UNIT_TAG, {id: message.id, datatype: 'html'}); transUnit.children.push( new xml.CR(8), new xml.Tag(_SOURCE_TAG, {}, visitor.serialize(message.nodes)), - new xml.CR(8), new xml.Tag(_TARGET_TAG)); + new xml.CR(8), new xml.Tag(_TARGET_TAG), ...contextTags); if (message.description) { transUnit.children.push( diff --git a/packages/compiler/src/i18n/serializers/xmb.ts b/packages/compiler/src/i18n/serializers/xmb.ts index 9110b27221dc94..c9ee3eb52b7242 100644 --- a/packages/compiler/src/i18n/serializers/xmb.ts +++ b/packages/compiler/src/i18n/serializers/xmb.ts @@ -16,6 +16,7 @@ const _MESSAGES_TAG = 'messagebundle'; const _MESSAGE_TAG = 'msg'; const _PLACEHOLDER_TAG = 'ph'; const _EXEMPLE_TAG = 'ex'; +const _SOURCE_TAG = 'source'; const _DOCTYPE = `<!ELEMENT messagebundle (msg)*> <!ATTLIST messagebundle class CDATA #IMPLIED> @@ -54,8 +55,17 @@ export class Xmb extends Serializer { attrs['meaning'] = message.meaning; } + let sourceTags: xml.Tag[] = []; + message.sources.forEach((source: i18n.MessageSpan) => { + sourceTags.push(new xml.Tag(_SOURCE_TAG, {}, [ + new xml.Text( + `${source.filePath}:${source.startLine}${source.endLine !== source.startLine ? ',' + source.endLine : ''}`) + ])); + }); + rootNode.children.push( - new xml.CR(2), new xml.Tag(_MESSAGE_TAG, attrs, visitor.serialize(message.nodes))); + new xml.CR(2), + new xml.Tag(_MESSAGE_TAG, attrs, [...sourceTags, ...visitor.serialize(message.nodes)])); }); rootNode.children.push(new xml.CR()); diff --git a/packages/compiler/test/i18n/digest_spec.ts b/packages/compiler/test/i18n/digest_spec.ts index 7297f6cc76130d..532430d64f9846 100644 --- a/packages/compiler/test/i18n/digest_spec.ts +++ b/packages/compiler/test/i18n/digest_spec.ts @@ -19,6 +19,7 @@ export function main(): void { placeholderToMessage: {}, meaning: '', description: '', + sources: [], })).toEqual('i'); }); }); diff --git a/packages/compiler/test/i18n/serializers/xliff_spec.ts b/packages/compiler/test/i18n/serializers/xliff_spec.ts index f16dbc57adb536..0de2b11cfca025 100644 --- a/packages/compiler/test/i18n/serializers/xliff_spec.ts +++ b/packages/compiler/test/i18n/serializers/xliff_spec.ts @@ -19,6 +19,7 @@ const HTML = ` <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="m|d">foo</p> <p i18n="m|d@@i">foo</p> <p i18n="@@bar">foo</p> <p i18n="ph names"><br><img><div></div></p> @@ -33,10 +34,18 @@ const WRITE_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?> <trans-unit id="983775b9a51ce14b036be72d4cfd65d68d64e231" datatype="html"> <source>translatable attribute</source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">2</context> + </context-group> </trans-unit> <trans-unit id="ec1d033f2436133c14ab038286c4f5df4697484a" datatype="html"> <source>translatable element <x id="START_BOLD_TEXT" ctype="x-b"/>with placeholders<x id="CLOSE_BOLD_TEXT" ctype="x-b"/> <x id="INTERPOLATION"/></source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">3</context> + </context-group> </trans-unit> <trans-unit id="e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2" datatype="html"> <source>{VAR_PLURAL, plural, =0 {<x id="START_PARAGRAPH" ctype="x-p"/>test<x id="CLOSE_PARAGRAPH" ctype="x-p"/>} }</source> @@ -45,22 +54,42 @@ const WRITE_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?> <trans-unit id="db3e0a6a5a96481f60aec61d98c3eecddef5ac23" datatype="html"> <source>foo</source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">4</context> + </context-group> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">5</context> + </context-group> <note priority="1" from="description">d</note> <note priority="1" from="meaning">m</note> </trans-unit> <trans-unit id="i" datatype="html"> <source>foo</source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">6</context> + </context-group> <note priority="1" from="description">d</note> <note priority="1" from="meaning">m</note> </trans-unit> <trans-unit id="bar" datatype="html"> <source>foo</source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">7</context> + </context-group> </trans-unit> <trans-unit id="d7fa2d59aaedcaa5309f13028c59af8c85b8c49d" datatype="html"> <source><x id="LINE_BREAK" ctype="lb"/><x id="TAG_IMG" ctype="image"/><x id="START_TAG_DIV" ctype="x-div"/><x id="CLOSE_TAG_DIV" ctype="x-div"/></source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">8</context> + </context-group> <note priority="1" from="description">ph names</note> </trans-unit> <trans-unit id="baz" datatype="html"> @@ -83,10 +112,18 @@ const LOAD_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?> <trans-unit id="983775b9a51ce14b036be72d4cfd65d68d64e231" datatype="html"> <source>translatable attribute</source> <target>etubirtta elbatalsnart</target> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">1</context> + </context-group> </trans-unit> <trans-unit id="ec1d033f2436133c14ab038286c4f5df4697484a" datatype="html"> <source>translatable element <x id="START_BOLD_TEXT" ctype="b"/>with placeholders<x id="CLOSE_BOLD_TEXT" ctype="b"/> <x id="INTERPOLATION"/></source> <target><x id="INTERPOLATION"/> footnemele elbatalsnart <x id="START_BOLD_TEXT" ctype="x-b"/>sredlohecalp htiw<x id="CLOSE_BOLD_TEXT" ctype="x-b"/></target> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">2</context> + </context-group> </trans-unit> <trans-unit id="e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2" datatype="html"> <source>{VAR_PLURAL, plural, =0 {<x id="START_PARAGRAPH" ctype="x-p"/>test<x id="CLOSE_PARAGRAPH" ctype="x-p"/>} }</source> @@ -95,27 +132,47 @@ const LOAD_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?> <trans-unit id="db3e0a6a5a96481f60aec61d98c3eecddef5ac23" datatype="html"> <source>foo</source> <target>oof</target> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">3</context> + </context-group> <note priority="1" from="description">d</note> <note priority="1" from="meaning">m</note> </trans-unit> <trans-unit id="i" datatype="html"> <source>foo</source> <target>toto</target> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">4</context> + </context-group> <note priority="1" from="description">d</note> <note priority="1" from="meaning">m</note> </trans-unit> <trans-unit id="bar" datatype="html"> <source>foo</source> <target>tata</target> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">5</context> + </context-group> </trans-unit> <trans-unit id="d7fa2d59aaedcaa5309f13028c59af8c85b8c49d" datatype="html"> <source><x id="LINE_BREAK" ctype="lb"/><x id="TAG_IMG" ctype="image"/><x id="START_TAG_DIV" ctype="x-div"/><x id="CLOSE_TAG_DIV" ctype="x-div"/></source> <target><x id="START_TAG_DIV" ctype="x-div"/><x id="CLOSE_TAG_DIV" ctype="x-div"/><x id="TAG_IMG" ctype="image"/><x id="LINE_BREAK" ctype="lb"/></target> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">6</context> + </context-group> <note priority="1" from="description">ph names</note> </trans-unit> <trans-unit id="empty target" datatype="html"> <source><x id="LINE_BREAK" ctype="lb"/><x id="TAG_IMG" ctype="image"/><x id="START_TAG_DIV" ctype="x-div"/><x id="CLOSE_TAG_DIV" ctype="x-div"/></source> <target/> + <context-group purpose="location"> + <context context-type="sourcefile">file.ts</context> + <context context-type="linenumber">6</context> + </context-group> <note priority="1" from="description">ph names</note> </trans-unit> <trans-unit id="baz" datatype="html"> @@ -136,7 +193,7 @@ export function main(): void { function toXliff(html: string, locale: string | null = null): string { const catalog = new MessageBundle(new HtmlParser, [], {}, locale); - catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG); + catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG); return catalog.write(serializer); } diff --git a/packages/compiler/test/i18n/serializers/xmb_spec.ts b/packages/compiler/test/i18n/serializers/xmb_spec.ts index cb8c535fd52c6d..58084111b4adb9 100644 --- a/packages/compiler/test/i18n/serializers/xmb_spec.ts +++ b/packages/compiler/test/i18n/serializers/xmb_spec.ts @@ -21,7 +21,9 @@ export function main(): void { <p i18n="m|d@@i">foo</p> <p i18n="@@bar">foo</p> <p i18n="@@baz">{ count, plural, =0 { { sex, select, other {<p>deeply nested</p>}} }}</p> -<p i18n>{ count, plural, =0 { { sex, select, other {<p>deeply nested</p>}} }}</p>`; +<p i18n>{ count, plural, =0 { { sex, select, other {<p>deeply nested</p>}} }}</p> +<p i18n>multi +lines</p>`; const XMB = `<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE messagebundle [ @@ -46,20 +48,22 @@ export function main(): void { <!ELEMENT ex (#PCDATA)> ]> <messagebundle> - <msg id="7056919470098446707">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"><ex>INTERPOLATION</ex></ph></msg> - <msg id="2981514368455622387">{VAR_PLURAL, plural, =0 {<ph name="START_PARAGRAPH"><ex><p></ex></ph>test<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} }</msg> - <msg id="7999024498831672133" desc="d" meaning="m">foo</msg> - <msg id="i" desc="d" meaning="m">foo</msg> - <msg id="bar">foo</msg> - <msg id="baz">{VAR_PLURAL, plural, =0 {{VAR_SELECT, select, other {<ph name="START_PARAGRAPH"><ex><p></ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} } } }</msg> - <msg id="2015957479576096115">{VAR_PLURAL, plural, =0 {{VAR_SELECT, select, other {<ph name="START_PARAGRAPH"><ex><p></ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} } } }</msg> + <msg id="7056919470098446707"><source>file.ts:3</source>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"><ex>INTERPOLATION</ex></ph></msg> + <msg id="2981514368455622387"><source>file.ts:4</source>{VAR_PLURAL, plural, =0 {<ph name="START_PARAGRAPH"><ex><p></ex></ph>test<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} }</msg> + <msg id="7999024498831672133" desc="d" meaning="m"><source>file.ts:5</source>foo</msg> + <msg id="i" desc="d" meaning="m"><source>file.ts:6</source>foo</msg> + <msg id="bar"><source>file.ts:7</source>foo</msg> + <msg id="baz"><source>file.ts:8</source>{VAR_PLURAL, plural, =0 {{VAR_SELECT, select, other {<ph name="START_PARAGRAPH"><ex><p></ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} } } }</msg> + <msg id="2015957479576096115"><source>file.ts:9</source>{VAR_PLURAL, plural, =0 {{VAR_SELECT, select, other {<ph name="START_PARAGRAPH"><ex><p></ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex></p></ex></ph>} } } }</msg> + <msg id="2340165783990709777"><source>file.ts:10,11</source>multi +lines</msg> </messagebundle> `; it('should write a valid xmb file', () => { - expect(toXmb(HTML)).toEqual(XMB); + expect(toXmb(HTML, 'file.ts')).toEqual(XMB); // the locale is not specified in the xmb file - expect(toXmb(HTML, 'fr')).toEqual(XMB); + expect(toXmb(HTML, 'file.ts', 'fr')).toEqual(XMB); }); it('should throw when trying to load an xmb file', () => { @@ -71,11 +75,11 @@ export function main(): void { }); } -function toXmb(html: string, locale: string | null = null): string { +function toXmb(html: string, url: string, locale: string | null = null): string { const catalog = new MessageBundle(new HtmlParser, [], {}, locale); const serializer = new Xmb(); - catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG); + catalog.updateFromTemplate(html, url, DEFAULT_INTERPOLATION_CONFIG); return catalog.write(serializer); } diff --git a/packages/compiler/test/i18n/translation_bundle_spec.ts b/packages/compiler/test/i18n/translation_bundle_spec.ts index d0dff34e652ccb..1a78e89d2bb721 100644 --- a/packages/compiler/test/i18n/translation_bundle_spec.ts +++ b/packages/compiler/test/i18n/translation_bundle_spec.ts @@ -17,8 +17,9 @@ import {_extractMessages} from './i18n_parser_spec'; export function main(): void { describe('TranslationBundle', () => { const file = new ParseSourceFile('content', 'url'); - const location = new ParseLocation(file, 0, 0, 0); - const span = new ParseSourceSpan(location, null !); + const startLocation = new ParseLocation(file, 0, 0, 0); + const endLocation = new ParseLocation(file, 0, 0, 7); + const span = new ParseSourceSpan(startLocation, endLocation); const srcNode = new i18n.Text('src', span); it('should translate a plain message', () => {