-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathivy-localize-locale-data.ts
More file actions
68 lines (57 loc) · 2.15 KB
/
ivy-localize-locale-data.ts
File metadata and controls
68 lines (57 loc) · 2.15 KB
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
/**
* @license
* Copyright Google LLC 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.dev/license
*/
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { setupI18nConfig } from './setup';
export default async function () {
// Setup i18n tests and config.
await setupI18nConfig();
// Update angular.json
await updateJsonFile('angular.json', (workspaceJson) => {
const appProject = workspaceJson.projects['test-project'];
// tslint:disable-next-line: no-any
const i18n: Record<string, any> = appProject.i18n;
i18n.sourceLocale = 'fr-Abcd';
appProject.architect['build'].options.localize = ['fr-Abcd'];
});
const { stderr: err1 } = await ng('build');
if (!err1.includes(`Locale data for 'fr-Abcd' cannot be found. Using locale data for 'fr'.`)) {
throw new Error('locale data fallback warning not shown');
}
// Update angular.json
await updateJsonFile('angular.json', (workspaceJson) => {
const appProject = workspaceJson.projects['test-project'];
// tslint:disable-next-line: no-any
const i18n: Record<string, any> = appProject.i18n;
i18n.sourceLocale = 'en-US';
appProject.architect['build'].options.localize = ['en-US'];
});
const { stderr: err2 } = await ng('build');
if (
err2.includes(
`Locale data for 'en-US' cannot be found. No locale data will be included for this locale.`,
)
) {
throw new Error('locale data not found warning shown');
}
// Update angular.json
await updateJsonFile('angular.json', (workspaceJson) => {
const appProject = workspaceJson.projects['test-project'];
const i18n: Record<string, any> = appProject.i18n;
i18n.sourceLocale = 'en-x-abc';
appProject.architect['build'].options.localize = ['en-x-abc'];
});
const { stderr: err3 } = await ng('build', '--configuration=development');
if (
err3.includes(
`Locale data for 'en-x-abc' cannot be found. No locale data will be included for this locale.`,
)
) {
throw new Error('locale data not found warning shown');
}
}