Skip to content

Commit 2da85b8

Browse files
filipesilvamgechev
authored andcommitted
test: add second language to aot-i18n e2e (#15798)
1 parent 08bc4df commit 2da85b8

File tree

1 file changed

+72
-40
lines changed

1 file changed

+72
-40
lines changed
Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,77 @@
1+
import { appendToFile, createDir, expectFileToMatch, writeFile } from '../../../utils/fs';
12
import { ng } from '../../../utils/process';
2-
import { expectFileToMatch, writeFile, createDir, appendToFile, readFile } from '../../../utils/fs';
3+
import { updateJsonFile } from '../../../utils/project';
34
import { expectToFail } from '../../../utils/utils';
4-
import { Version } from '../../../../../packages/@angular/cli/upgrade/version';
5-
import { SemVer } from 'semver';
65

7-
// tslint:disable:max-line-length
8-
export default function () {
9-
// TODO(architect): Delete this test. It is now in devkit/build-angular.
6+
export default async function () {
7+
const enDir = 'dist/test-project';
8+
const frDist = `${enDir}-fr`;
9+
const deDir = `${enDir}-de`;
1010

11-
return Promise.resolve()
12-
.then(() => createDir('src/locale'))
13-
.then(() => writeFile('src/locale/messages.fr.xlf', `
14-
<?xml version="1.0" encoding="UTF-8" ?>
15-
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
16-
<file source-language="en" datatype="plaintext" original="ng2.template">
17-
<body>
18-
<trans-unit id="8def8481e91291a52f9baa31cbdb313e6a6ca02b" datatype="html">
19-
<source>Hello i18n!</source>
20-
<target>Bonjour i18n!</target>
21-
<note priority="1" from="description">An introduction header for this sample</note>
22-
</trans-unit>
23-
</body>
24-
</file>
25-
</xliff>`))
26-
.then(() => appendToFile('src/app/app.component.html',
27-
'<h1 i18n="An introduction header for this sample">Hello i18n!</h1>'))
28-
.then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf', '--i18n-format',
29-
'xlf', '--i18n-locale', 'fr'))
30-
.then(() => expectFileToMatch('dist/test-project/main-es5.js', /Bonjour i18n!/))
31-
.then(() => expectFileToMatch('dist/test-project/main-es2015.js', /Bonjour i18n!/))
32-
.then(() => ng('build', '--aot'))
33-
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main-es5.js', /Bonjour i18n!/)))
34-
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main-es2015.js', /Bonjour i18n!/)))
35-
.then(() => expectFileToMatch('dist/test-project/main-es2015.js', /Hello i18n!/))
36-
.then(() => expectFileToMatch('dist/test-project/main-es5.js', /Hello i18n!/))
37-
.then(() => appendToFile('src/app/app.component.html',
38-
'<p i18n>Other content</p>'))
39-
.then(() => ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf', '--i18nFormat',
40-
'xlf', '--i18n-locale', 'fr', '--i18n-missing-translation', 'ignore'))
41-
.then(() => expectFileToMatch('dist/test-project/main-es5.js', /Other content/))
42-
.then(() => expectFileToMatch('dist/test-project/main-es2015.js', /Other content/))
43-
.then(() => expectToFail(() => ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf',
44-
'--i18nFormat', 'xlf', '--i18n-locale', 'fr', '--i18n-missing-translation', 'error')));
11+
await updateJsonFile('angular.json', workspaceJson => {
12+
const appArchitect = workspaceJson.projects['test-project'].architect;
13+
const browserConfigs = appArchitect['build'].configurations;
14+
browserConfigs['fr'] = {
15+
outputPath: frDist,
16+
aot: true,
17+
i18nFile: 'src/locale/messages.fr.xlf',
18+
i18nFormat: 'xlf',
19+
i18nLocale: 'fr',
20+
};
21+
browserConfigs['de'] = {
22+
outputPath: deDir,
23+
aot: true,
24+
i18nFile: 'src/locale/messages.de.xlf',
25+
i18nFormat: 'xlf',
26+
i18nLocale: 'de',
27+
};
28+
});
29+
30+
await createDir('src/locale');
31+
await writeFile('src/locale/messages.fr.xlf', `
32+
<?xml version="1.0" encoding="UTF-8" ?>
33+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
34+
<file source-language="en" datatype="plaintext" original="ng2.template">
35+
<body>
36+
<trans-unit id="8def8481e91291a52f9baa31cbdb313e6a6ca02b" datatype="html">
37+
<source>Hello i18n!</source>
38+
<target>Bonjour i18n!</target>
39+
<note priority="1" from="description">An introduction header for this sample</note>
40+
</trans-unit>
41+
</body>
42+
</file>
43+
</xliff>`);
44+
await writeFile('src/locale/messages.de.xlf', `
45+
<?xml version="1.0" encoding="UTF-8" ?>
46+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
47+
<file source-language="en" datatype="plaintext" original="ng2.template">
48+
<body>
49+
<trans-unit id="8def8481e91291a52f9baa31cbdb313e6a6ca02b" datatype="html">
50+
<source>Hello i18n!</source>
51+
<target>Hallo i18n!</target>
52+
<note priority="1" from="description">An introduction header for this sample</note>
53+
</trans-unit>
54+
</body>
55+
</file>
56+
</xliff>`);
57+
await appendToFile('src/app/app.component.html',
58+
'<h1 i18n="An introduction header for this sample">Hello i18n!</h1>');
59+
await ng('build', '--configuration=fr');
60+
await expectFileToMatch(`${frDist}/main-es5.js`, /Bonjour i18n!/);
61+
await expectFileToMatch(`${frDist}/main-es2015.js`, /Bonjour i18n!/);
62+
await ng('build', '--configuration=de');
63+
await expectFileToMatch(`${deDir}/main-es5.js`, /Hallo i18n!/);
64+
await expectFileToMatch(`${deDir}/main-es2015.js`, /Hallo i18n!/);
65+
await ng('build', '--aot');
66+
await expectToFail(() => expectFileToMatch(`${enDir}/main-es5.js`, /Bonjour i18n!/));
67+
await expectToFail(() => expectFileToMatch(`${enDir}/main-es2015.js`, /Bonjour i18n!/));
68+
await expectToFail(() => expectFileToMatch(`${enDir}/main-es5.js`, /Hallo i18n!/));
69+
await expectToFail(() => expectFileToMatch(`${enDir}/main-es2015.js`, /Hallo i18n!/));
70+
await expectFileToMatch(`${enDir}/main-es2015.js`, /Hello i18n!/);
71+
await expectFileToMatch(`${enDir}/main-es5.js`, /Hello i18n!/);
72+
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
73+
await ng('build', '--configuration=fr', '--i18n-missing-translation', 'ignore');
74+
await expectFileToMatch(`${frDist}/main-es5.js`, /Other content/);
75+
await expectFileToMatch(`${frDist}/main-es2015.js`, /Other content/);
76+
await expectToFail(() => ng('build', '--configuration=fr', '--i18n-missing-translation', 'error'));
4577
}

0 commit comments

Comments
 (0)