Skip to content

Commit 64f340d

Browse files
committed
feat(@angular-devkit/build-angular): extract i18n messages from libraries
Closes #18871
1 parent cb2b308 commit 64f340d

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export async function execute(
141141
},
142142
sourceMap: {
143143
scripts: true,
144+
styles: false,
145+
vendor: true,
144146
},
145147
buildOptimizer: false,
146148
i18nLocale: options.i18nLocale || i18n.sourceLocale,
@@ -187,7 +189,7 @@ export async function execute(
187189
module: {
188190
rules: [
189191
{
190-
test: /\.ts$/,
192+
test: /\.[t|j]s$/,
191193
loader: require.resolve('./ivy-extract-loader'),
192194
options: {
193195
messageHandler: (messages: LocalizeMessage[]) => ivyMessages.push(...messages),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { getGlobalVariable } from '../../utils/env';
2+
import { expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs';
3+
import { ng, npm } from '../../utils/process';
4+
import { expectToFail } from '../../utils/utils';
5+
import { readNgVersion } from '../../utils/version';
6+
7+
export default async function() {
8+
// Ivy only test
9+
if (getGlobalVariable('argv')['ve']) {
10+
return;
11+
}
12+
13+
// Setup a library
14+
await ng('generate', 'library', 'i18n-lib-test');
15+
await replaceInFile(
16+
'projects/i18n-lib-test/src/lib/i18n-lib-test.component.ts',
17+
'<p>',
18+
'<p i18n>',
19+
);
20+
21+
// Build library
22+
await ng('build', 'i18n-lib-test');
23+
24+
// Consume library in application
25+
await writeFile(
26+
'src/app/app.module.ts',
27+
`
28+
import { BrowserModule } from '@angular/platform-browser';
29+
import { NgModule } from '@angular/core';
30+
import { AppComponent } from './app.component';
31+
import { I18nLibTestModule } from 'i18n-lib-test';
32+
33+
@NgModule({
34+
declarations: [
35+
AppComponent
36+
],
37+
imports: [
38+
BrowserModule,
39+
I18nLibTestModule,
40+
],
41+
providers: [],
42+
bootstrap: [AppComponent]
43+
})
44+
export class AppModule { }
45+
`,
46+
);
47+
48+
await writeFile(
49+
'src/app/app.component.html',
50+
`
51+
<p i18n>Hello world</p>
52+
<lib-i18n-lib-test></lib-i18n-lib-test>
53+
`,
54+
);
55+
56+
// Install correct version
57+
let localizeVersion = '@angular/localize@' + readNgVersion();
58+
if (getGlobalVariable('argv')['ng-snapshots']) {
59+
localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize'];
60+
}
61+
await npm('install', `${localizeVersion}`);
62+
63+
// Extract messages
64+
await ng('xi18n', '--ivy');
65+
await expectFileToMatch('messages.xlf', 'src/app/app.component.html');
66+
await expectFileToMatch('messages.xlf', 'Hello world');
67+
await expectFileToMatch('messages.xlf', 'i18n-lib-test works!');
68+
await expectFileToMatch(
69+
'messages.xlf',
70+
`projects/i18n-lib-test/src/lib/i18n-lib-test.component.ts`,
71+
);
72+
}

0 commit comments

Comments
 (0)