Skip to content

Commit e701090

Browse files
ricardochlSplaktar
authored andcommitted
translate: translations for web workers guide
- Translate ecosystem service worker guides to Spanish Fixes #73
1 parent 446244a commit e701090

File tree

2 files changed

+81
-18
lines changed

2 files changed

+81
-18
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Background processing using web workers
2+
3+
[Web workers](https://developer.mozilla.org/docs/Web/API/Web_Workers_API) let you run CPU-intensive computations in a background thread, freeing the main thread to update the user interface.
4+
Application's performing a lot of computations, like generating Computer-Aided Design \(CAD\) drawings or doing heavy geometric calculations, can use web workers to increase performance.
5+
6+
HELPFUL: The Angular CLI does not support running itself in a web worker.
7+
8+
## Adding a web worker
9+
10+
To add a web worker to an existing project, use the Angular CLI `ng generate` command.
11+
12+
<docs-code language="shell">
13+
14+
ng generate web-worker <location>
15+
16+
</docs-code>
17+
18+
You can add a web worker anywhere in your application.
19+
For example, to add a web worker to the root component, `src/app/app.component.ts`, run the following command.
20+
21+
<docs-code language="shell">
22+
23+
ng generate web-worker app
24+
25+
</docs-code>
26+
27+
The command performs the following actions.
28+
29+
1. Configures your project to use web workers, if it isn't already.
30+
1. Adds the following scaffold code to `src/app/app.worker.ts` to receive messages.
31+
32+
<docs-code language="typescript" header="src/app/app.worker.ts">
33+
34+
addEventListener('message', ({ data }) => {
35+
const response = `worker response to ${data}`;
36+
postMessage(response);
37+
});
38+
39+
</docs-code>
40+
41+
1. Adds the following scaffold code to `src/app/app.component.ts` to use the worker.
42+
43+
<docs-code language="typescript" header="src/app/app.component.ts">
44+
45+
if (typeof Worker !== 'undefined') {
46+
// Create a new
47+
const worker = new Worker(new URL('./app.worker', import.meta.url));
48+
worker.onmessage = ({ data }) => {
49+
console.log(`page got message: ${data}`);
50+
};
51+
worker.postMessage('hello');
52+
} else {
53+
// Web workers are not supported in this environment.
54+
// You should add a fallback so that your program still executes correctly.
55+
}
56+
57+
</docs-code>
58+
59+
After you create this initial scaffold, you must refactor your code to use the web worker by sending messages to and from the worker.
60+
61+
IMPORTANT: Some environments or platforms, such as `@angular/platform-server` used in [Server-side Rendering](guide/ssr), don't support web workers.
62+
63+
To ensure that your application works in these environments, you must provide a fallback mechanism to perform the computations that the worker would otherwise perform.
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
# Background processing using web workers
1+
# Procesamiento en segundo plano con web workers
22

3-
[Web workers](https://developer.mozilla.org/docs/Web/API/Web_Workers_API) let you run CPU-intensive computations in a background thread, freeing the main thread to update the user interface.
4-
Application's performing a lot of computations, like generating Computer-Aided Design \(CAD\) drawings or doing heavy geometric calculations, can use web workers to increase performance.
3+
Los [web workers](https://developer.mozilla.org/es/docs/Web/API/Web_Workers_API) te permiten ejecutar cálculos con uso intensivo de CPU en un hilo en segundo plano, liberando el hilo principal para actualizar la interfaz de usuario.
4+
Las aplicaciones que realizan muchos cálculos, como generar dibujos de diseño asistido por computadora (CAD) o llevar a cabo operaciones geométricas complejas, pueden usar web workers para aumentar el rendimiento.
55

6-
HELPFUL: The Angular CLI does not support running itself in a web worker.
6+
ÚTIL: Angular CLI no permite ejecutarse a sí mismo dentro de un web worker.
77

8-
## Adding a web worker
8+
## Agregar un web worker
99

10-
To add a web worker to an existing project, use the Angular CLI `ng generate` command.
10+
Para agregar un web worker a un proyecto existente, usa el comando `ng generate` de Angular CLI.
1111

1212
<docs-code language="shell">
1313

1414
ng generate web-worker <location>
1515

1616
</docs-code>
1717

18-
You can add a web worker anywhere in your application.
19-
For example, to add a web worker to the root component, `src/app/app.component.ts`, run the following command.
18+
Puedes agregar un web worker en cualquier parte de tu aplicación.
19+
Por ejemplo, para agregar un web worker al componente raíz, `src/app/app.component.ts`, ejecuta el siguiente comando.
2020

2121
<docs-code language="shell">
2222

2323
ng generate web-worker app
2424

2525
</docs-code>
2626

27-
The command performs the following actions.
27+
El comando realiza las siguientes acciones.
2828

29-
1. Configures your project to use web workers, if it isn't already.
30-
1. Adds the following scaffold code to `src/app/app.worker.ts` to receive messages.
29+
1. Configura tu proyecto para usar web workers, si aún no lo estaba.
30+
1. Agrega el siguiente código base en `src/app/app.worker.ts` para recibir mensajes.
3131

3232
<docs-code language="typescript" header="src/app/app.worker.ts">
3333

@@ -38,26 +38,26 @@ The command performs the following actions.
3838

3939
</docs-code>
4040

41-
1. Adds the following scaffold code to `src/app/app.component.ts` to use the worker.
41+
1. Agrega el siguiente siguiente código base en `src/app/app.component.ts` para usar el worker.
4242

4343
<docs-code language="typescript" header="src/app/app.component.ts">
4444

4545
if (typeof Worker !== 'undefined') {
46-
// Create a new
46+
// Crear uno nuevo
4747
const worker = new Worker(new URL('./app.worker', import.meta.url));
4848
worker.onmessage = ({ data }) => {
4949
console.log(`page got message: ${data}`);
5050
};
5151
worker.postMessage('hello');
5252
} else {
53-
// Web workers are not supported in this environment.
54-
// You should add a fallback so that your program still executes correctly.
53+
// Web workers no están soportados en este entorno.
54+
// Debes agregar un plan alternativo para que tu programa siga funcionando correctamente.
5555
}
5656

5757
</docs-code>
5858

59-
After you create this initial scaffold, you must refactor your code to use the web worker by sending messages to and from the worker.
59+
Después de crear este siguiente código base, debes refactorizar tu código para usar el web worker enviando y recibiendo mensajes.
6060

61-
IMPORTANT: Some environments or platforms, such as `@angular/platform-server` used in [Server-side Rendering](guide/ssr), don't support web workers.
61+
IMPORTANTE: Algunos entornos o plataformas, como `@angular/platform-server` utilizado en el [renderizado del lado del servidor](guide/ssr), no soportan web workers.
6262

63-
To ensure that your application works in these environments, you must provide a fallback mechanism to perform the computations that the worker would otherwise perform.
63+
Para asegurarte de que tu aplicación funcione en estos entornos, debes proporcionar un mecanismo alternativo para realizar los cálculos que, de otro modo, ejecutaría el worker.

0 commit comments

Comments
 (0)