Skip to content

Commit bac89b4

Browse files
authored
Translation for the page 'Basics -> Forms' (#117)
* wip * wip: forms * forms: wip * Translation for the page 'Basics -> Forms' * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/forms.md Co-Authored-By: deblasis <[email protected]>
1 parent 45cdfc1 commit bac89b4

File tree

6 files changed

+233
-76
lines changed

6 files changed

+233
-76
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.cache
22
.DS_STORE
33
.idea
4+
.vscode
45
node_modules
56
public
67
yarn-error.log

Diff for: GLOSSARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Glossary of the translations of technical and React-specific terms.
1818
- tag
1919
- lifecycle
2020
- callback
21+
- form/forms
2122

2223

2324
# Common Translations

Diff for: content/docs/forms.md

+87-76
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@ redirect_from:
99
- "docs/forms-zh-CN.html"
1010
---
1111

12-
HTML form elements work a little bit differently from other DOM elements in React, because form elements naturally keep some internal state. For example, this form in plain HTML accepts a single name:
12+
Gli elementi HTML `form` funzionano in un modo un po' differente rispetto agli altri elementi DOM in React, la motivazione sta nel fatto che gli elementi form mantengono naturalmente uno stato interno. Ad esempio, questo form in puro HTML accetta un singolo nome:
1313

1414
```html
1515
<form>
1616
<label>
17-
Name:
18-
<input type="text" name="name" />
17+
Nome:
18+
<input type="text" name="nome" />
1919
</label>
2020
<input type="submit" value="Submit" />
2121
</form>
2222
```
2323

24-
This form has the default HTML form behavior of browsing to a new page when the user submits the form. If you want this behavior in React, it just works. But in most cases, it's convenient to have a JavaScript function that handles the submission of the form and has access to the data that the user entered into the form. The standard way to achieve this is with a technique called "controlled components".
24+
Questo form si comporta come di consueto, facendo navigare l'utente in una nuova pagina quando viene inviato. In React, se vuoi avere lo stesso comportamento, non c'è bisogno di fare alcuna modifica. Ad ogni modo, potrebbe essere più conveniente avere una funzione JavaScript che gestisce l'invio del form e che ha accesso ai dati inseriti dall'utente. La tecnica standard con cui si può ottenere ciò prende il nome di "componenti controllati".
2525

26-
## Controlled Components {#controlled-components}
26+
## Componenti Controllati {#controlled-components}
2727

28-
In HTML, form elements such as `<input>`, `<textarea>`, and `<select>` typically maintain their own state and update it based on user input. In React, mutable state is typically kept in the state property of components, and only updated with [`setState()`](/docs/react-component.html#setstate).
28+
In HTML, gli elementi di un form come `<input>`, `<textarea>` e `<select>` mantengono tipicamente il proprio stato e lo aggiornano in base all'input dell'utente. In React, lo stato mutabile viene tipicamente mantenuto nella proprietà `state` dei componenti e viene poi aggiornato solo mediante [`setState()`](/docs/react-component.html#setstate).
2929

30-
We can combine the two by making the React state be the "single source of truth". Then the React component that renders a form also controls what happens in that form on subsequent user input. An input form element whose value is controlled by React in this way is called a "controlled component".
30+
Possiamo combinare le due cose rendendo lo _state_ in React la "singola fonte attendibile" ([SSOT](https://en.wikipedia.org/wiki/Single_source_of_truth)). Possiamo poi fare in modo che il componente React che renderizza il form controlli anche cosa succede all'interno del form in risposta agli input dell'utente. In un form, un elemento di input il cui valore è controllato da React viene così chiamato "componente controllato".
3131

32-
For example, if we want to make the previous example log the name when it is submitted, we can write the form as a controlled component:
32+
Ad esempio, se vogliamo far sì che l'esempio precedente registri il nome inserito, possiamo riscrivere il form sotto forma di componente controllato:
3333

3434
```javascript{4,10-12,24}
35-
class NameForm extends React.Component {
35+
class FormNome extends React.Component {
3636
constructor(props) {
3737
super(props);
3838
this.state = {value: ''};
@@ -46,15 +46,15 @@ class NameForm extends React.Component {
4646
}
4747
4848
handleSubmit(event) {
49-
alert('A name was submitted: ' + this.state.value);
49+
alert('E\' stato inserito un nome: ' + this.state.value);
5050
event.preventDefault();
5151
}
5252
5353
render() {
5454
return (
5555
<form onSubmit={this.handleSubmit}>
5656
<label>
57-
Name:
57+
Nome:
5858
<input type="text" value={this.state.value} onChange={this.handleChange} />
5959
</label>
6060
<input type="submit" value="Submit" />
@@ -64,36 +64,38 @@ class NameForm extends React.Component {
6464
}
6565
```
6666

67-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/VmmPgp?editors=0010)
67+
**[Prova su CodeSandbox](codesandbox://forms/1.js)**
6868

69-
Since the `value` attribute is set on our form element, the displayed value will always be `this.state.value`, making the React state the source of truth. Since `handleChange` runs on every keystroke to update the React state, the displayed value will update as the user types.
69+
Dato che l'attributo `value` viene impostato nel nostro elemento form, il valore visualizzato sarà sempre `this.state.value`, rendendo lo stato in React l'unica fonte di dati attendibile. Dato che la funzione `handleChange` viene eseguita ad ogni battitura per aggiornare lo stato di React, il valore visualizzato verrà aggiornato man mano che l'utente preme i tasti.
7070

71-
With a controlled component, every state mutation will have an associated handler function. This makes it straightforward to modify or validate user input. For example, if we wanted to enforce that names are written with all uppercase letters, we could write `handleChange` as:
71+
Con un componente controllato, ogni mutazione dello stato deve aver associata una funzione _handler_. Tutto ciò rende il processo di modifica e la validazione dell'input dell'utente semplice e lineare. Ad esempio, se volessimo definire una regola che vuole che i nomi vengano sempre scritti tutti in maiuscolo, possiamo definire `handleChange` così:
7272

7373
```javascript{2}
7474
handleChange(event) {
7575
this.setState({value: event.target.value.toUpperCase()});
7676
}
7777
```
7878

79-
## The textarea Tag {#the-textarea-tag}
79+
## Il Tag Textarea {#the-textarea-tag}
8080

81-
In HTML, a `<textarea>` element defines its text by its children:
81+
In HTML, l'elemento `<textarea>` definisce il testo in esso contenuto con i suoi elementi figli:
8282

8383
```html
8484
<textarea>
85-
Hello there, this is some text in a text area
85+
Nel mezzo del cammin di nostra vita
86+
mi ritrovai per una selva oscura
87+
ché la diritta via era smarrita.
8688
</textarea>
8789
```
8890

89-
In React, a `<textarea>` uses a `value` attribute instead. This way, a form using a `<textarea>` can be written very similarly to a form that uses a single-line input:
91+
In React, invece, `<textarea>` utilizza l'attributo `value`. Per questo, un form che utilizza una `<textarea>` può essere scritto in modo molto simile a come verrebbe scritto se utilizzasse un semplice input di una sola riga:
9092

9193
```javascript{4-6,12-14,26}
92-
class EssayForm extends React.Component {
94+
class FormTema extends React.Component {
9395
constructor(props) {
9496
super(props);
9597
this.state = {
96-
value: 'Please write an essay about your favorite DOM element.'
98+
value: 'Per favore scrivi un tema riguardo il tuo elemento DOM preferito.'
9799
};
98100
99101
this.handleChange = this.handleChange.bind(this);
@@ -105,15 +107,15 @@ class EssayForm extends React.Component {
105107
}
106108
107109
handleSubmit(event) {
108-
alert('An essay was submitted: ' + this.state.value);
110+
alert('Un tema è stato inviato: ' + this.state.value);
109111
event.preventDefault();
110112
}
111113
112114
render() {
113115
return (
114116
<form onSubmit={this.handleSubmit}>
115117
<label>
116-
Essay:
118+
Tema:
117119
<textarea value={this.state.value} onChange={this.handleChange} />
118120
</label>
119121
<input type="submit" value="Submit" />
@@ -123,25 +125,25 @@ class EssayForm extends React.Component {
123125
}
124126
```
125127

126-
Notice that `this.state.value` is initialized in the constructor, so that the text area starts off with some text in it.
128+
Nota come `this.state.value` viene inizializzato nel costruttore, cosìcche la casella di testo è inizializzata con del testo al suo interno.
127129

128-
## The select Tag {#the-select-tag}
130+
## Il Tag Select {#the-select-tag}
129131

130-
In HTML, `<select>` creates a drop-down list. For example, this HTML creates a drop-down list of flavors:
132+
In HTML, `<select>` crea una lista a discesa. Per esempio, questo HTML crea una lista a discesa di gusti:
131133

132134
```html
133135
<select>
134-
<option value="grapefruit">Grapefruit</option>
135-
<option value="lime">Lime</option>
136-
<option selected value="coconut">Coconut</option>
136+
<option value="pompelmo">Pompelmo</option>
137+
<option value="limone">Limone</option>
138+
<option selected value="cocco">Cocco</option>
137139
<option value="mango">Mango</option>
138140
</select>
139141
```
140142

141-
Note that the Coconut option is initially selected, because of the `selected` attribute. React, instead of using this `selected` attribute, uses a `value` attribute on the root `select` tag. This is more convenient in a controlled component because you only need to update it in one place. For example:
143+
Nota come l'opzione Cocco venga preselezionata grazie all'attributo `selected`. React, piuttosto che usare l'attributo `selected`, usa l'attributo `value` dell'elemento radice `select`. Ciò facilita le cose in un componente controllato in quanto bisogna aggiornare lo stato in un posto solo. Ad esempio:
142144

143145
```javascript{4,10-12,24}
144-
class FlavorForm extends React.Component {
146+
class FormGusti extends React.Component {
145147
constructor(props) {
146148
super(props);
147149
this.state = {value: 'coconut'};
@@ -155,19 +157,21 @@ class FlavorForm extends React.Component {
155157
}
156158
157159
handleSubmit(event) {
158-
alert('Your favorite flavor is: ' + this.state.value);
160+
alert('Il tuo gusto preferito è: ' + this.state.value);
159161
event.preventDefault();
160162
}
161163
162164
render() {
163165
return (
164166
<form onSubmit={this.handleSubmit}>
165167
<label>
166-
Pick your favorite flavor:
167-
<select value={this.state.value} onChange={this.handleChange}>
168-
<option value="grapefruit">Grapefruit</option>
169-
<option value="lime">Lime</option>
170-
<option value="coconut">Coconut</option>
168+
Seleziona il tuo gusto preferito:
169+
<select
170+
value={this.state.value}
171+
onChange={this.handleChange}>
172+
<option value="pompelmo">Pompelmo</option>
173+
<option value="limone">Limone</option>
174+
<option value="cocco">Cocco</option>
171175
<option value="mango">Mango</option>
172176
</select>
173177
</label>
@@ -178,121 +182,128 @@ class FlavorForm extends React.Component {
178182
}
179183
```
180184

181-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/JbbEzX?editors=0010)
185+
**[Prova su CodeSandbox](codesandbox://forms/2.js)**
182186

183-
Overall, this makes it so that `<input type="text">`, `<textarea>`, and `<select>` all work very similarly - they all accept a `value` attribute that you can use to implement a controlled component.
187+
Ricapitolando, ciò fa sì che `<input type="text">`, `<textarea>` e `<select>` funzionino in modo molto simile - tutti accettano un attributo `value` che puoi utilizzare per implementare un componente controllato.
184188

185-
> Note
189+
> **Nota bene**
186190
>
187-
> You can pass an array into the `value` attribute, allowing you to select multiple options in a `select` tag:
191+
> Puoi passare un array nell'attributo `value`, permettendoti di selezionare opzioni multiple in un tag `select`:
188192
>
189193
>```js
190194
><select multiple={true} value={['B', 'C']}>
191195
>```
192196
193-
## The file input Tag {#the-file-input-tag}
197+
## Il Tag Input File {#the-file-input-tag}
194198
195-
In HTML, an `<input type="file">` lets the user choose one or more files from their device storage to be uploaded to a server or manipulated by JavaScript via the [File API](https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications).
199+
In HTML, un `<input type="file">` permette all'utente di selezionare uno o più file da disco e di inviarli al server o manipolarli in JavaScript mediante le [File API](https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications).
196200
197201
```html
198202
<input type="file" />
199203
```
200204
201-
Because its value is read-only, it is an **uncontrolled** component in React. It is discussed together with other uncontrolled components [later in the documentation](/docs/uncontrolled-components.html#the-file-input-tag).
205+
Dato che il suo valore è in sola-lettura, è un componente **non controllato** in React. Riprenderemo il discorso riguardo questo ed altri componenti non controllati [in seguito](/docs/uncontrolled-components.html#the-file-input-tag).
202206

203-
## Handling Multiple Inputs {#handling-multiple-inputs}
207+
## Gestione di Input Multipli {#handling-multiple-inputs}
204208

205-
When you need to handle multiple controlled `input` elements, you can add a `name` attribute to each element and let the handler function choose what to do based on the value of `event.target.name`.
209+
Quando devi gestire diversi elementi `input`, puoi aggiungere un attributo `name` ad ognuno di essi e far sì che la funzione handler controlli cosa fare in base al valore di `event.target.name`.
206210

207-
For example:
211+
Ad esempio:
208212

209-
```javascript{15,18,28,37}
210-
class Reservation extends React.Component {
213+
```javascript{20,23,33,43}
214+
class Prenotazione extends React.Component {
211215
constructor(props) {
212216
super(props);
213217
this.state = {
214-
isGoing: true,
215-
numberOfGuests: 2
218+
presente: true,
219+
numeroOspiti: 2,
216220
};
217221
218-
this.handleInputChange = this.handleInputChange.bind(this);
222+
this.handleInputChange = this.handleInputChange.bind(
223+
this
224+
);
219225
}
220226
221227
handleInputChange(event) {
222228
const target = event.target;
223-
const value = target.type === 'checkbox' ? target.checked : target.value;
229+
const value =
230+
target.type === 'checkbox'
231+
? target.checked
232+
: target.value;
224233
const name = target.name;
225234
226235
this.setState({
227-
[name]: value
236+
[name]: value,
228237
});
229238
}
230239
231240
render() {
232241
return (
233242
<form>
234243
<label>
235-
Is going:
244+
Sarà presente:
236245
<input
237-
name="isGoing"
246+
name="presente"
238247
type="checkbox"
239-
checked={this.state.isGoing}
240-
onChange={this.handleInputChange} />
248+
checked={this.state.presente}
249+
onChange={this.handleInputChange}
250+
/>
241251
</label>
242252
<br />
243253
<label>
244-
Number of guests:
254+
Numero di ospiti:
245255
<input
246-
name="numberOfGuests"
256+
name="numeroOspiti"
247257
type="number"
248-
value={this.state.numberOfGuests}
249-
onChange={this.handleInputChange} />
258+
value={this.state.numeroOspiti}
259+
onChange={this.handleInputChange}
260+
/>
250261
</label>
251262
</form>
252263
);
253264
}
254265
}
255266
```
256267

257-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/wgedvV?editors=0010)
268+
**[Prova su CodeSandbox](codesandbox://forms/3.js)**
258269

259-
Note how we used the ES6 [computed property name](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names) syntax to update the state key corresponding to the given input name:
270+
Nota come abbiamo utilizzato la sintassi ES6 [_computed property name_ ("nome proprietà calcolato")](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names) per aggiornare la rispettiva chiave nello stato a seconda dell'attributo `name` dell'input:
260271

261272
```js{2}
262273
this.setState({
263274
[name]: value
264275
});
265276
```
266277

267-
It is equivalent to this ES5 code:
278+
Il che in ES5 corrisponde al codice:
268279

269280
```js{2}
270-
var partialState = {};
271-
partialState[name] = value;
272-
this.setState(partialState);
281+
var statoParziale = {};
282+
statoParziale[name] = value;
283+
this.setState(statoParziale);
273284
```
274285

275-
Also, since `setState()` automatically [merges a partial state into the current state](/docs/state-and-lifecycle.html#state-updates-are-merged), we only needed to call it with the changed parts.
286+
Inoltre, dato che `setState()` [unisce uno stato parziale nello stato corrente](/docs/state-and-lifecycle.html#state-updates-are-merged) automaticamente, dobbiamo chiamarla con le sole parti modificate.
276287

277-
## Controlled Input Null Value {#controlled-input-null-value}
288+
## Valore Null in Input Controllati {#controlled-input-null-value}
278289

279-
Specifying the value prop on a [controlled component](/docs/forms.html#controlled-components) prevents the user from changing the input unless you desire so. If you've specified a `value` but the input is still editable, you may have accidentally set `value` to `undefined` or `null`.
290+
Specificare la prop `value` in un [componente controllato](/docs/forms.html#controlled-components) fa sì che l'utente possa cambiare l'input solo quando lo desideri. Se hai specificato un `value` ma l'input è ancora editabile, potresti aver accidentalmente impostato `value` come `undefined` o `null`.
280291

281-
The following code demonstrates this. (The input is locked at first but becomes editable after a short delay.)
292+
Il codice seguente lo dimostra. (L'input è inizialmente bloccato ma diventa editabile dopo un secondo)
282293

283294
```javascript
284-
ReactDOM.render(<input value="hi" />, mountNode);
295+
ReactDOM.render(<input value="ciao" />, mountNode);
285296

286297
setTimeout(function() {
287298
ReactDOM.render(<input value={null} />, mountNode);
288299
}, 1000);
289300

290301
```
291302

292-
## Alternatives to Controlled Components {#alternatives-to-controlled-components}
303+
## Alternative ai Componenti Controllati {#alternatives-to-controlled-components}
293304

294-
It can sometimes be tedious to use controlled components, because you need to write an event handler for every way your data can change and pipe all of the input state through a React component. This can become particularly annoying when you are converting a preexisting codebase to React, or integrating a React application with a non-React library. In these situations, you might want to check out [uncontrolled components](/docs/uncontrolled-components.html), an alternative technique for implementing input forms.
305+
Utilizzare componenti controllati può sembrare laborioso a volte, soprattutto perché è necessario scrivere un _event handler_ per ogni modo in cui i tuoi dati possono cambiare e perchè si deve collegare lo stato di tutti gli input a quello di un componente React. Il tutto diventa particolarmente noioso quando bisogna convertire progetti preesistenti in React, o integrare un'applicazione React con una libreria non-React. In queste situazioni, si potrebbe ricorrere ai [componenti non controllati](/docs/uncontrolled-components.html), una tecnica alternativa per implementare forms ed i relativi campi di input.
295306

296-
## Fully-Fledged Solutions {#fully-fledged-solutions}
307+
## Soluzioni Chiavi In Mano {#fully-fledged-solutions}
297308

298-
If you're looking for a complete solution including validation, keeping track of the visited fields, and handling form submission, [Formik](https://jaredpalmer.com/formik) is one of the popular choices. However, it is built on the same principles of controlled components and managing stateso don't neglect to learn them.
309+
Se stai cercando una soluzione che include la validazione dei dati, il tener traccia dei campi visitati e la sottomissione del form, [Formik](https://jaredpalmer.com/formik) è una delle scelte popolari. Comunque, si basa sugli stessi principi dei componenti controllati e della gestione dello statoecco perché è bene essere familiari con questi concetti.

0 commit comments

Comments
 (0)