-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathi18n_spec_large.ts
130 lines (111 loc) · 4.53 KB
/
i18n_spec_large.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* @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 { Architect } from '@angular-devkit/architect';
import { join, normalize, virtualFs } from '@angular-devkit/core';
import { BrowserBuilderOutput } from '../../src/browser';
import { createArchitect, host, veEnabled } from '../utils';
// DISABLED_FOR_IVY - These should pass but are currently not supported
(veEnabled ? describe : xdescribe)('Browser Builder i18n', () => {
const emptyTranslationFile = `
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
</body>
</file>
</xliff>`;
const targetSpec = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('uses translations', async () => {
host.writeMultipleFiles({
'src/locale/messages.fr.xlf': `
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="8def8481e91291a52f9baa31cbdb313e6a6ca02b" datatype="html">
<source>Hello i18n!</source>
<target>Bonjour i18n!</target>
<note priority="1" from="description">An introduction header for this sample</note>
</trans-unit>
</body>
</file>
</xliff>
`,
});
host.appendToFile(
'src/app/app.component.html',
'<h1 i18n="An introduction header for this sample">Hello i18n!</h1>',
);
const overrides = {
aot: true,
i18nFile: 'src/locale/messages.fr.xlf',
i18nFormat: 'true',
i18nLocale: 'fr',
};
const run = await architect.scheduleTarget(targetSpec, overrides);
const output = (await run.result) as BrowserBuilderOutput;
expect(output.success).toBe(true);
const outputPath = output.outputPath;
const fileName = join(normalize(outputPath), 'main.js');
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
expect(content).toMatch(/Bonjour i18n!/);
await run.stop();
});
it('ignores missing translations', async () => {
const overrides = {
aot: true,
i18nFile: 'src/locale/messages.fr.xlf',
i18nFormat: 'true',
i18nLocale: 'fr',
i18nMissingTranslation: 'ignore',
};
host.writeMultipleFiles({ 'src/locale/messages.fr.xlf': emptyTranslationFile });
host.appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
const run = await architect.scheduleTarget(targetSpec, overrides);
const output = (await run.result) as BrowserBuilderOutput;
expect(output.success).toBe(true);
const outputPath = output.outputPath;
const fileName = join(normalize(outputPath), 'main.js');
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
expect(content).toMatch(/Other content/);
await run.stop();
});
it('reports errors for missing translations', async () => {
const overrides = {
aot: true,
i18nFile: 'src/locale/messages.fr.xlf',
i18nFormat: 'true',
i18nLocale: 'fr',
i18nMissingTranslation: 'error',
};
host.writeMultipleFiles({ 'src/locale/messages.fr.xlf': emptyTranslationFile });
host.appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
const run = await architect.scheduleTarget(targetSpec, overrides);
const output = (await run.result) as BrowserBuilderOutput;
expect(output.success).toBe(false);
await run.stop();
});
it('register locales', async () => {
const overrides = { aot: true, i18nLocale: 'fr_FR' };
const run = await architect.scheduleTarget(targetSpec, overrides);
const output = (await run.result) as BrowserBuilderOutput;
expect(output.success).toBe(true);
const outputPath = output.outputPath;
const fileName = join(normalize(outputPath), 'main.js');
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
expect(content).toMatch(/registerLocaleData/);
expect(content).toMatch(/angular_common_locales_fr/);
await run.stop();
});
});