feat(compiler): add source files to xmb/xliff translations (#14705)
Fixes #14190
This commit is contained in:

committed by
Tobias Bosch

parent
09c4cb2540
commit
4054055d0d
@ -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) {}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,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 {
|
||||
|
Reference in New Issue
Block a user