Skip to content

Commit ad56ad5

Browse files
ricardochlSplaktar
authored andcommitted
translate: translations for migrations reference
Fixes #126
1 parent 9dbf918 commit ad56ad5

32 files changed

+1588
-352
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Clean up unused imports
2+
3+
As of version 19, Angular reports when a component's `imports` array contains symbols that aren't used in its template.
4+
5+
Running this schematic will clean up all unused imports within the project.
6+
7+
Run the schematic using the following command:
8+
9+
```shell
10+
ng generate @angular/core:cleanup-unused-imports
11+
```
12+
13+
#### Before
14+
15+
```angular-ts
16+
import {Component} from '@angular/core';
17+
import {UnusedDirective} from './unused';
18+
19+
@Component({
20+
template: 'Hello',
21+
imports: [UnusedDirective],
22+
})
23+
export class MyComp {}
24+
```
25+
26+
#### After
27+
28+
```angular-ts
29+
import {Component} from '@angular/core';
30+
31+
@Component({
32+
template: 'Hello',
33+
imports: [],
34+
})
35+
export class MyComp {}
36+
```

adev-es/src/content/reference/migrations/cleanup-unused-imports.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Clean up unused imports
1+
# Limpiar importaciones no utilizadas
22

3-
As of version 19, Angular reports when a component's `imports` array contains symbols that aren't used in its template.
3+
A partir de la versión 19, Angular reporta cuando el array `imports` de un componente contiene símbolos que no se usan en su plantilla.
44

5-
Running this schematic will clean up all unused imports within the project.
5+
Ejecutar este schematic limpiará todas las importaciones no utilizadas dentro del proyecto.
66

7-
Run the schematic using the following command:
7+
Ejecuta el schematic usando el siguiente comando:
88

99
```shell
1010
ng generate @angular/core:cleanup-unused-imports
1111
```
1212

13-
#### Before
13+
#### Antes
1414

1515
```angular-ts
1616
import {Component} from '@angular/core';
@@ -23,7 +23,7 @@ import {UnusedDirective} from './unused';
2323
export class MyComp {}
2424
```
2525

26-
#### After
26+
#### Después
2727

2828
```angular-ts
2929
import {Component} from '@angular/core';
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Convert CommonModule usage to standalone imports
2+
3+
This migration helps projects remove imports of the `CommonModule` inside components by adding the minimal set of directive and pipe imports each template requires (for example, `NgIf`, `NgFor`, `AsyncPipe`, etc.).
4+
5+
Run the schematic using the following command:
6+
7+
```shell
8+
ng generate @angular/core:common-to-standalone
9+
```
10+
11+
## Options
12+
13+
| Option | Details |
14+
| :----- | :---------------------------------------------------------------------------------------------------------------------------- |
15+
| `path` | The path (relative to project root) to migrate. Defaults to `./`. Use this to incrementally migrate a subset of your project. |
16+
17+
## Example
18+
19+
Before:
20+
21+
```angular-ts
22+
import { Component } from '@angular/core';
23+
import { CommonModule } from '@angular/common';
24+
25+
@Component({
26+
selector: 'app-example',
27+
imports: [CommonModule],
28+
template: `
29+
<div *ngIf="show">
30+
{{ data | async | json }}
31+
</div>
32+
`
33+
})
34+
export class ExampleComponent {
35+
show = true;
36+
data = Promise.resolve({ message: 'Hello' });
37+
}
38+
```
39+
40+
After running the migration (component imports added, CommonModule removed):
41+
42+
```angular-ts
43+
import { Component } from '@angular/core';
44+
import { AsyncPipe, JsonPipe, NgIf } from '@angular/common';
45+
46+
@Component({
47+
selector: 'app-example',
48+
imports: [AsyncPipe, JsonPipe, NgIf],
49+
template: `
50+
<div *ngIf="show">
51+
{{ data | async | json }}
52+
</div>
53+
`
54+
})
55+
export class ExampleComponent {
56+
show = true;
57+
data = Promise.resolve({ message: 'Hello' });
58+
}
59+
```

adev-es/src/content/reference/migrations/common-to-standalone.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# Convert CommonModule usage to standalone imports
1+
# Convertir el uso de CommonModule a importaciones standalone
22

3-
This migration helps projects remove imports of the `CommonModule` inside components by adding the minimal set of directive and pipe imports each template requires (for example, `NgIf`, `NgFor`, `AsyncPipe`, etc.).
3+
Esta migración ayuda a los proyectos a eliminar las importaciones de `CommonModule` dentro de los componentes agregando el conjunto mínimo de importaciones de directivas y pipes que cada plantilla requiere (por ejemplo, `NgIf`, `NgFor`, `AsyncPipe`, etc.).
44

5-
Run the schematic using the following command:
5+
Ejecuta el schematic usando el siguiente comando:
66

77
```shell
88
ng generate @angular/core:common-to-standalone
99
```
1010

11-
## Options
11+
## Opciones
1212

13-
| Option | Details |
14-
| :----- | :---------------------------------------------------------------------------------------------------------------------------- |
15-
| `path` | The path (relative to project root) to migrate. Defaults to `./`. Use this to incrementally migrate a subset of your project. |
13+
| Opción | Detalles |
14+
| :----- | :----------------------------------------------------------------------------------------------------------------------------------------- |
15+
| `path` | La ruta (relativa a la raíz del proyecto) a migrar. Por defecto es `./`. Úsala para migrar de forma incremental un subconjunto de tu proyecto. |
1616

17-
## Example
17+
## Ejemplo
1818

19-
Before:
19+
Antes:
2020

2121
```angular-ts
2222
import { Component } from '@angular/core';
@@ -37,7 +37,7 @@ export class ExampleComponent {
3737
}
3838
```
3939

40-
After running the migration (component imports added, CommonModule removed):
40+
Después de ejecutar la migración (importaciones del componente agregadas, CommonModule eliminado):
4141

4242
```angular-ts
4343
import { Component } from '@angular/core';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Migration to Control Flow syntax
2+
3+
[Control flow syntax](guide/templates/control-flow) is available from Angular v17. The new syntax is baked into the template, so you don't need to import `CommonModule` anymore.
4+
5+
This schematic migrates all existing code in your application to use new Control Flow Syntax.
6+
7+
Run the schematic using the following command:
8+
9+
```shell
10+
ng generate @angular/core:control-flow
11+
```

adev-es/src/content/reference/migrations/control-flow.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Migration to Control Flow syntax
1+
# Migración a la sintaxis de flujo de control
22

3-
[Control flow syntax](guide/templates/control-flow) is available from Angular v17. The new syntax is baked into the template, so you don't need to import `CommonModule` anymore.
3+
La [sintaxis de flujo de control](guide/templates/control-flow) está disponible desde Angular v17. La nueva sintaxis está integrada en la plantilla, por lo que ya no necesitas importar `CommonModule`.
44

5-
This schematic migrates all existing code in your application to use new Control Flow Syntax.
5+
Este schematic migra todo el código existente en tu aplicación para usar la nueva sintaxis de flujo de control.
66

7-
Run the schematic using the following command:
7+
Ejecuta el schematic usando el siguiente comando:
88

99
```shell
1010
ng generate @angular/core:control-flow
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Migration to the `inject` function
2+
3+
Angular's `inject` function offers more accurate types and better compatibility with standard decorators, compared to constructor-based injection.
4+
5+
This schematic converts constructor-based injection in your classes to use the `inject` function instead.
6+
7+
Run the schematic using the following command:
8+
9+
```shell
10+
ng generate @angular/core:inject
11+
```
12+
13+
#### Before
14+
15+
```typescript
16+
import { Component, Inject, Optional } from '@angular/core';
17+
import { MyService } from './service';
18+
import { DI_TOKEN } from './token';
19+
20+
@Component()
21+
export class MyComp {
22+
constructor(
23+
private service: MyService,
24+
@Inject(DI_TOKEN) @Optional() readonly token: string
25+
) {}
26+
}
27+
```
28+
29+
#### After
30+
31+
```typescript
32+
import { Component, inject } from '@angular/core';
33+
import { MyService } from './service';
34+
import { DI_TOKEN } from './token';
35+
36+
@Component()
37+
export class MyComp {
38+
private service = inject(MyService);
39+
readonly token = inject(DI_TOKEN, { optional: true });
40+
}
41+
```
42+
43+
## Migration options
44+
45+
The migration includes several options to customize its output.
46+
47+
### `path`
48+
49+
Determines which sub-path in your project should be migrated. Pass in `.` or leave it blank to
50+
migrate the entire directory.
51+
52+
### `migrateAbstractClasses`
53+
54+
Angular doesn't validate that parameters of abstract classes are injectable. This means that the
55+
migration can't reliably migrate them to `inject` without risking breakages which is why they're
56+
disabled by default. Enable this option if you want abstract classes to be migrated, but note
57+
that you may have to **fix some breakages manually**.
58+
59+
### `backwardsCompatibleConstructors`
60+
61+
By default the migration tries to clean up the code as much as it can, which includes deleting
62+
parameters from the constructor, or even the entire constructor if it doesn't include any code.
63+
In some cases this can lead to compilation errors when classes with Angular decorators inherit from
64+
other classes with Angular decorators. If you enable this option, the migration will generate an
65+
additional constructor signature to keep it backwards compatible, at the expense of more code.
66+
67+
#### Before
68+
69+
```typescript
70+
import { Component } from '@angular/core';
71+
import { MyService } from './service';
72+
73+
@Component()
74+
export class MyComp {
75+
constructor(private service: MyService) {}
76+
}
77+
```
78+
79+
#### After
80+
81+
```typescript
82+
import { Component } from '@angular/core';
83+
import { MyService } from './service';
84+
85+
@Component()
86+
export class MyComp {
87+
private service = inject(MyService);
88+
89+
/\*_ Inserted by Angular inject() migration for backwards compatibility _/
90+
constructor(...args: unknown[]);
91+
92+
constructor() {}
93+
}
94+
```
95+
96+
### `nonNullableOptional`
97+
98+
If injection fails for a parameter with the `@Optional` decorator, Angular returns `null` which
99+
means that the real type of any `@Optional` parameter will be `| null`. However, because decorators
100+
cannot influence their types, there is a lot of existing code whose type is incorrect. The type is
101+
fixed in `inject()` which can cause new compilation errors to show up. If you enable this option,
102+
the migration will produce a non-null assertion after the `inject()` call to match the old type,
103+
at the expense of potentially hiding type errors.
104+
105+
**NOTE:** non-null assertions won't be added to parameters that are already typed to be nullable,
106+
because the code that depends on them likely already accounts for their nullability.
107+
108+
#### Before
109+
110+
```typescript
111+
import { Component, Inject, Optional } from '@angular/core';
112+
import { TOKEN_ONE, TOKEN_TWO } from './token';
113+
114+
@Component()
115+
export class MyComp {
116+
constructor(
117+
@Inject(TOKEN_ONE) @Optional() private tokenOne: number,
118+
@Inject(TOKEN_TWO) @Optional() private tokenTwo: string | null
119+
) {}
120+
}
121+
```
122+
123+
#### After
124+
125+
```typescript
126+
import { Component, inject } from '@angular/core';
127+
import { TOKEN_ONE, TOKEN_TWO } from './token';
128+
129+
@Component()
130+
export class MyComp {
131+
// Note the `!` at the end.
132+
private tokenOne = inject(TOKEN_ONE, { optional: true })!;
133+
134+
// Does not have `!` at the end, because the type was already nullable.
135+
private tokenTwo = inject(TOKEN_TWO, { optional: true });
136+
}
137+
```

0 commit comments

Comments
 (0)