chore(i18n,curriculum): update translations (#42649)

This commit is contained in:
camperbot
2021-06-27 23:51:13 +05:30
committed by GitHub
parent 9887fb2ca2
commit 9942b595fa
65 changed files with 637 additions and 618 deletions

View File

@@ -1,6 +1,6 @@
---
id: 5a24c314108439a4d403617e
title: Add Event Listeners
title: Agrega detector de eventos (Event Listeners)
challengeType: 6
forumTopicId: 301377
dashedName: add-event-listeners
@@ -8,19 +8,19 @@ dashedName: add-event-listeners
# --description--
The `componentDidMount()` method is also the best place to attach any event listeners you need to add for specific functionality. React provides a synthetic event system which wraps the native event system present in browsers. This means that the synthetic event system behaves exactly the same regardless of the user's browser - even if the native events may behave differently between different browsers.
El método `componentDidMount()` es también el mejor lugar para adjuntar cualquier detector de eventos que necesites agregar para una funcionalidad específica. React proporciona un sistema de eventos sintético que envuelve el sistema de eventos nativo presente en los navegadores. Esto significa que el sistema de eventos sintético se comporta exactamente igual independientemente del navegador del usuario, incluso si los eventos nativos se comportan diferentes entre diferentes navegadores.
You've already been using some of these synthetic event handlers such as `onClick()`. React's synthetic event system is great to use for most interactions you'll manage on DOM elements. However, if you want to attach an event handler to the document or window objects, you have to do this directly.
Ya has estado usando algunos de estos controladores de eventos sintéticos como `onClick()`. El sistema de eventos sintéticos de React es excelente para usar en la mayoría de las interacciones que administrarás en elementos DOM. Sin embargo, si quieres adjuntar un controlador de eventos al documento o objetos de la ventana, debes hacerlo directamente.
# --instructions--
Attach an event listener in the `componentDidMount()` method for `keydown` events and have these events trigger the callback `handleKeyPress()`. You can use `document.addEventListener()` which takes the event (in quotes) as the first argument and the callback as the second argument.
Agrega un detector de eventos en el método `componentDidMount()` para los eventos `keydown` y haz que estos eventos ejecuten el callback `handleKeyPress()`. Puedes usar `document.addEventListener()` el cual toma el evento (en comillas) como primer argumento y el callback como segundo argumento.
Then, in `componentWillUnmount()`, remove this same event listener. You can pass the same arguments to `document.removeEventListener()`. It's good practice to use this lifecycle method to do any clean up on React components before they are unmounted and destroyed. Removing event listeners is an example of one such clean up action.
Posteriormente, en `componentWillUnmount()`, remueve este mismo detector de eventos. Puedes pasar los mismos argumentos al `document.removeEventListener()`. Es buena práctica usar este método del ciclo de vida para hacer cualquier limpieza en un componente de React antes de que estos sean desmontados y destruidos. Removiendo los detectores de eventos es un ejemplo de una limpieza de este tipo.
# --hints--
`MyComponent` should render a `div` element which wraps an `h1` tag.
`MyComponent` debe mostrar un elemento `div` el cual envuelva una etiqueta `h1`.
```js
assert(
@@ -31,7 +31,7 @@ assert(
);
```
A keydown listener should be attached to the document in `componentDidMount`.
Un detector `keydown` debe ser agregado al documento en `componentDidMount`.
```js
assert(
@@ -47,7 +47,7 @@ assert(
);
```
The keydown listener should be removed from the document in `componentWillUnmount`.
Un detector `keydown` debe ser removido del documento en `componentWillUnmount`.
```js
assert(
@@ -63,7 +63,7 @@ assert(
);
```
Once the component has mounted, pressing `enter` should update its state and the rendered `h1` tag.
Una vez que el componente se ha montado, pulsando `enter` debe actualizar el estado y renderizar la etiqueta `h1`.
```js
async () => {

View File

@@ -1,6 +1,6 @@
---
id: 5a24c314108439a4d4036179
title: Create a Controlled Form
title: Crea un formulario controlado
challengeType: 6
forumTopicId: 301384
dashedName: create-a-controlled-form
@@ -8,21 +8,21 @@ dashedName: create-a-controlled-form
# --description--
The last challenge showed that React can control the internal state for certain elements like `input` and `textarea`, which makes them controlled components. This applies to other form elements as well, including the regular HTML `form` element.
El último desafío mostró que React puede controlar el estado interno de ciertos elementos como `input` y `textarea`, lo que los hace componentes controlados. Esto también se aplica a otros elementos del formulario, incluyendo el elemento regular HTML `form`.
# --instructions--
The `MyForm` component is set up with an empty `form` with a submit handler. The submit handler will be called when the form is submitted.
El componente `MyForm` está configurado con un `form` vacío, con un manejador de envío. El manejador de envío será llamado cuando se envíe el formulario.
We've added a button which submits the form. You can see it has the `type` set to `submit` indicating it is the button controlling the form. Add the `input` element in the `form` and set its `value` and `onChange()` attributes like the last challenge. You should then complete the `handleSubmit` method so that it sets the component state property `submit` to the current input value in the local `state`.
Hemos añadido un botón que envía el formulario. Puedes ver que tiene el `type` establecido en `submit` indicando que es el botón que controla el formulario. Añade el elemento `input` en el formulario `form` y establece sus atributos `value` y `onChange()` como el último desafío. A continuación, debes completar el método `handleSubmit` para que establezca la propiedad de estado del componente `submit` al valor de entrada actual en el `state` local.
**Note:** You also must call `event.preventDefault()` in the submit handler, to prevent the default form submit behavior which will refresh the web page.
**Nota:** También debes llamar a `event.preventDefault()` en el controlador de envío, para evitar el comportamiento predeterminado de envío de formulario que actualizará la página web. Para la comodidad de los campistas, el comportamiento predeterminado se ha desactivado aquí para evitar que las actualizaciones restablezcan el código de desafío.
Finally, create an `h1` tag after the `form` which renders the `submit` value from the component's `state`. You can then type in the form and click the button (or press enter), and you should see your input rendered to the page.
Por último, crea una etiqueta `h1` después del `form` que renderiza el valor de `submit` del `state` del componente. A continuación, puedes escribir en el formulario y hacer clic en el botón (o pulsar intro), y deberías ver tu entrada renderizada en la página.
# --hints--
`MyForm` should return a `div` element which contains a `form` and an `h1` tag. The form should include an `input` and a `button`.
`MyForm` debe retornar un elemento `div` que contiene un `form` y una etiqueta `h1`. El formulario debe incluir un `input` y un `button`.
```js
assert(
@@ -38,7 +38,7 @@ assert(
);
```
The state of `MyForm` should initialize with `input` and `submit` properties, both set to empty strings.
El estado de `MyForm` debe inicializar con propiedades `input` y `submit`, ambos establecidos a cadenas vacías.
```js
assert(
@@ -47,7 +47,7 @@ assert(
);
```
Typing in the `input` element should update the `input` property of the component's state.
Escribir en el elemento `input` debe actualizar la propiedad `input` del estado del componente.
```js
(() => {
@@ -75,7 +75,7 @@ Typing in the `input` element should update the `input` property of the componen
})();
```
Submitting the form should run `handleSubmit` which should set the `submit` property in state equal to the current input.
El envío del formulario debe ejecutar `handleSubmit`, el cual debe establecer la propiedad `submit` en estado igual a la entrada actual.
```js
(() => {
@@ -98,7 +98,26 @@ Submitting the form should run `handleSubmit` which should set the `submit` prop
})();
```
The `h1` header should render the value of the `submit` field from the component's state.
`handleSubmit` debe llamar a `event.preventDefault`
```js
const handleSubmit = MyForm.prototype.handleSubmit.toString();
const allMatches = handleSubmit.match(/\bevent\.preventDefault\(\s*?\)/g) ?? [];
const blockCommented = handleSubmit.match(
/\/\*.*?\bevent\.preventDefault\(\s*?\).*?\*\//gs
);
const lineCommented = handleSubmit.match(
/\/\/.*?\bevent\.preventDefault\(\s*?\)/g
);
const commentedMatches = [...(blockCommented ?? []), ...(lineCommented ?? [])];
assert(
// At least one event.preventDefault() call exists and is not commented out
allMatches.length > commentedMatches.length
);
```
El encabezado `h1` debe renderizar el valor del campo `submit` del estado del componente.
```js
(() => {