Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x | import { chain, Rule, Tree } from '@angular-devkit/schematics';
import { getAppProjects, getWorkspace } from '../utils/backbase/package-utils';
import { addDependency } from './utils/package-json';
import { tryRule } from './utils/rules';
const manualProcess = `
## Add \`@angular/localize\` dependency
As of Angular 9 there is a new localization package that must be included to support translations.
Install the package:
ng add @angular/localize
## Initialize \`@angular/localize\`
The functionality is initialized by importing it in the \`polyfills.ts\` files:
import '@angular/localize/init';
`;
const addNgLocalize: Rule = () => {
return chain([addDependency('@angular/localize', '^10.0.0'), addPolyfillToApps]);
async function addPolyfillToApps(tree: Tree) {
const workspace = await getWorkspace(tree);
getAppProjects(workspace)
.map((project) => project.targets.get('build')?.options?.polyfills)
.filter((v): v is string => v !== undefined)
.forEach((polyfillsPath) => addPolyfillToApp(tree, polyfillsPath));
}
function addPolyfillToApp(tree: Tree, polyfillsPath: string) {
const importString = `import '@angular/localize/init';`;
const polyfills = tree.read(polyfillsPath)?.toString();
Iif (!polyfills) {
return;
}
Iif (polyfills.includes(importString)) {
return;
}
tree.overwrite(polyfillsPath, `${polyfills}\n${importString}`);
}
};
export default () => tryRule(addNgLocalize, manualProcess);
|