Skip to content

Commit 7fdd2a7

Browse files
committed
Translation of (Reacting to input): until step 2
- Translated `intro` - Translated `What you will learn` - Translated Imperative & Declartive programming - Translated Step 1
1 parent c5d16d0 commit 7fdd2a7

File tree

1 file changed

+60
-59
lines changed

1 file changed

+60
-59
lines changed

src/content/learn/reacting-to-input-with-state.md

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
---
2-
title: Reacting to Input with State
2+
title: الاستجابة للمدخلات باستخدام الحالة
33
---
44

55
<Intro>
66

7-
React provides a declarative way to manipulate the UI. Instead of manipulating individual pieces of the UI directly, you describe the different states that your component can be in, and switch between them in response to the user input. This is similar to how designers think about the UI.
7+
React توفر طريقة تصريحيّة (declarative) لتعديل واجهة المستخدم (UI). بدلا من تعديل أجزاء منفردة من واجهة المستخدم مباشرة، يمكنك وصف الحالات المختلفة التي يأخذها مكوّنك، والانتقال بينهم كاستجابة لمدخلات المستخدم. هذا مشابه لتصور المصممين عن واجهة المستخدم.
8+
89

910
</Intro>
1011

1112
<YouWillLearn>
1213

13-
* How declarative UI programming differs from imperative UI programming
14-
* How to enumerate the different visual states your component can be in
15-
* How to trigger the changes between the different visual states from code
16-
14+
* كيف تختلف البرمجة التصريحية لواجهة المستخدم (declarative UI programming) عن البرمجة الأمرية لواجهة المستخدم (imperative UI programming)
15+
* كيفية استعراض الحالات المرئية المختلفة التي يأخذها مكوّنك
16+
* كيفية تنشيط التغييرات بين الحالات المرئية المختلفة من خلال الكود
17+
1718
</YouWillLearn>
1819

19-
## How declarative UI compares to imperative {/*how-declarative-ui-compares-to-imperative*/}
20+
## كيف تُقارَن واجهة المستخدم التصريحية (declarative UI) بالأمرية (imperative) {/*how-declarative-ui-compares-to-imperative*/}
2021

21-
When you design UI interactions, you probably think about how the UI *changes* in response to user actions. Consider a form that lets the user submit an answer:
22+
عندما تصمم تعاملات واجهة المستخدم، عليك غالبًا التفكير في كيفية *تغيّر* واجهة المستخدم كاستجابة لاجراءات المستخدم. فكر في نموذج يسمح للمستخدم بإرسال إجابة:
2223

23-
* When you type something into the form, the "Submit" button **becomes enabled.**
24-
* When you press "Submit", both the form and the button **become disabled,** and a spinner **appears.**
25-
* If the network request succeeds, the form **gets hidden,** and the "Thank you" message **appears.**
26-
* If the network request fails, an error message **appears,** and the form **becomes enabled** again.
24+
* عندما تكتب شيئًا داخل النموذج، الزر "أرسل" **يصبح مفعلًا.**
25+
* عندما تضغط على "أرسل"، كلٌ من النموذج والزر **يصبح معطلا** ومؤشر التحميل **يظهر.**
26+
* لو نجح طلب الشبكة، النموج **يبدأ بالاختفاء،** ورسالة "شكرًا لك" **تظهر.**
27+
* لو فشل طلب الشبكة، رسالة خطأٍ **تظهر،** والنموذج **يصبح مفعلًا** مجددا.
2728

28-
In **imperative programming,** the above corresponds directly to how you implement interaction. You have to write the exact instructions to manipulate the UI depending on what just happened. Here's another way to think about this: imagine riding next to someone in a car and telling them turn by turn where to go.
29+
في **البرمجة الأمرية (imperative programming)**، يتوافق ما ذُكر أعلاه مباشرة مع طريقة تطبيق التعاملات. عليك أن تكتب التعليمات التامة لتعديل واجهة المستخدم معتمدا على ما حصل للتو. إليك طريقة أخرى لتفكر في هذا الأمر: تخيل نفسك راكبا إلى جانب أحدهم في سيارة مع إخباره في كل منعطف تلو الآخر عن وجهة الذهاب.
2930

3031
<Illustration src="/images/docs/illustrations/i_imperative-ui-programming.png" alt="In a car driven by an anxious-looking person representing JavaScript, a passenger orders the driver to execute a sequence of complicated turn by turn navigations." />
3132

32-
They don't know where you want to go, they just follow your commands. (And if you get the directions wrong, you end up in the wrong place!) It's called *imperative* because you have to "command" each element, from the spinner to the button, telling the computer *how* to update the UI.
33+
هم لا يعلمون إلى أين تريد أن تذهب، هم يتبعون أوامرك فقط. (ولو أنك أعطيتهم الاتجاهات الخاطئة، سوف ينتهي بك المطاف لوجهة خاطئة!) هذا يطلق عليه *أمري (imperative)* لأن عليك أن "تأمر" كل عنصر، بداية من مؤشر التحميل إلى الزر، مخبرًا
34+
الكمبيوتر عن *كيفية* تحديث واجهة المستخدم (UI).
3335

34-
In this example of imperative UI programming, the form is built *without* React. It only uses the browser [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model):
36+
في هذا المثال للبرمجة الأمرية لواجهة المستخدم، النموذج مبنيّ *بدون* React. إنه يستخدم [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model) المتصفح فقط:
3537

3638
<Sandpack>
3739

@@ -84,10 +86,10 @@ function submitForm(answer) {
8486
// Pretend it's hitting the network.
8587
return new Promise((resolve, reject) => {
8688
setTimeout(() => {
87-
if (answer.toLowerCase() == 'istanbul') {
89+
if (answer.toLowerCase() == 'إسطنبول') {
8890
resolve();
8991
} else {
90-
reject(new Error('Good guess but a wrong answer. Try again!'));
92+
reject(new Error('توقع جيد ولكن إجابة خاطئة. حاول مرة أخرى!'));
9193
}
9294
}, 1500);
9395
});
@@ -111,17 +113,17 @@ textarea.oninput = handleTextareaChange;
111113

112114
```html public/index.html
113115
<form id="form">
114-
<h2>City quiz</h2>
116+
<h2>اختبار المدينة</h2>
115117
<p>
116-
What city is located on two continents?
118+
ما هي المدينة الواقعة على قارتين؟
117119
</p>
118120
<textarea id="textarea"></textarea>
119121
<br />
120-
<button id="button" disabled>Submit</button>
121-
<p id="loading" style="display: none">Loading...</p>
122+
<button id="button" disabled>أرسل</button>
123+
<p id="loading" style="display: none">جارٍ التحميل...</p>
122124
<p id="error" style="display: none; color: red;"></p>
123125
</form>
124-
<h1 id="success" style="display: none">That's right!</h1>
126+
<h1 id="success" style="display: none">هذا صحيح!</h1>
125127

126128
<style>
127129
* { box-sizing: border-box; }
@@ -131,37 +133,36 @@ body { font-family: sans-serif; margin: 20px; padding: 0; }
131133

132134
</Sandpack>
133135

134-
Manipulating the UI imperatively works well enough for isolated examples, but it gets exponentially more difficult to manage in more complex systems. Imagine updating a page full of different forms like this one. Adding a new UI element or a new interaction would require carefully checking all existing code to make sure you haven't introduced a bug (for example, forgetting to show or hide something).
136+
تعديل واجهة المستخدم (UI) أمريًّا يعمل بشكل جيد كفاية للأمثلة المعزولة، ولكنه يصبح أكثر صعوبة بشكل استثنائي عندما تدير أنظمة أكثر تعقيدًا. تخيل تحديث صفحة مليئة بالنماذج المختلفة مثل هذه هنا. إضافة عنصر واجهة مستخدم جديد سيتطلب فحص كامل الكود الموجود بحرص للتأكد من أنك لم تقم بعمل خطأ(على سبيل المثال، نسيان إظهار أو إخفاء شيء ما).
135137

136-
React was built to solve this problem.
138+
React صُنعت لحل هذه المشكلة.
137139

138-
In React, you don't directly manipulate the UI--meaning you don't enable, disable, show, or hide components directly. Instead, you **declare what you want to show,** and React figures out how to update the UI. Think of getting into a taxi and telling the driver where you want to go instead of telling them exactly where to turn. It's the driver's job to get you there, and they might even know some shortcuts you haven't considered!
140+
في React، لن تقوم بتعديل واجهة المستخدم مباشرة -- يعني أنك لن تقوم بتفعيل، تعطيل، إظهار، أو إخفاء مكوّنات مباشرة. بدلا عن ذلك، سوف **تصف ما تريده أن يظهر،** و React سوف تدبر كيفية تحديث واجهة المستخدم. فكر في أخذ سيارة أجرة وإخبار السائق إلي أين تريد أنت تذهب بدلا من إخباره إلي أين ينعطف. وظيفة السائق هي أن يوصلك إلى هناك، وربما قد يعرف اختصارات لم تأخذها أنت بالحسبان.
139141

140142
<Illustration src="/images/docs/illustrations/i_declarative-ui-programming.png" alt="In a car driven by React, a passenger asks to be taken to a specific place on the map. React figures out how to do that." />
141143

142-
## Thinking about UI declaratively {/*thinking-about-ui-declaratively*/}
144+
## التفكير في واجهة المستخدم (UI) تصريحيًا {/*thinking-about-ui-declaratively*/}
143145

144-
You've seen how to implement a form imperatively above. To better understand how to think in React, you'll walk through reimplementing this UI in React below:
146+
لقد رأيت كيفية تنفيذ نموذج أمريَّا أعلاه. لفهم أفضل لكيفية التفكير في React، سوف تمر بإعادة تنفيذ واجهة المستخدم (UI) هذه باستخدام React أدناه:
145147

146-
1. **Identify** your component's different visual states
147-
2. **Determine** what triggers those state changes
148-
3. **Represent** the state in memory using `useState`
149-
4. **Remove** any non-essential state variables
150-
5. **Connect** the event handlers to set the state
148+
1. **عيّن** الحالات المرئية المختلفة لمكوّنك
149+
2. **حدد** ما ينشط تغيرات تلك الحالات
150+
3. **مثّل** الحالة في الذاكرة باستخدام `useState`
151+
4. **احذف** أيّ متغيرات حالة غير ضرورية
152+
5. **اربط** معالجات الأحداث لتعيين الحالة
151153

152-
### Step 1: Identify your component's different visual states {/*step-1-identify-your-components-different-visual-states*/}
154+
### الخطوة 1: عين الحالات المرئية المختلفة لمكوّنك {/*step-1-identify-your-components-different-visual-states*/}
153155

154-
In computer science, you may hear about a ["state machine"](https://en.wikipedia.org/wiki/Finite-state_machine) being in one of several “states”. If you work with a designer, you may have seen mockups for different "visual states". React stands at the intersection of design and computer science, so both of these ideas are sources of inspiration.
156+
في علوم الحاسب، ربما تسمع عن ["آلة حالة (state machine)"](https://en.wikipedia.org/wiki/Finite-state_machine) كونها واحدة من ضمن "حالات" متعددة.إذا كنت تعمل مع مصمم، لربما رأيت نماذج تجريبية لـ"الحالات المرئية" المختلفة
155157

156-
First, you need to visualize all the different "states" of the UI the user might see:
158+
أولًا، أنت تحتاج لتصور جميع "الحالات" المختلفة لواجهة المستخدم (UI) التي قد يراها المستخدم:
159+
* **فارغة**: النموذج يحتوي زر "إرسال" معطل.
160+
* **كتابة**: النموذج يحتوي زر "إرسال" مفعّل.
161+
* **إرسال**: النموذج معطل تمامًا. يتم عرض مؤشر التحميل.
162+
* **نجاح**: يتم عرض رسالة "شكرًا لك" بدلًا من النموذج.
163+
* **خطأ**: مثل حالة الكتابة، ولكن مع رسالة خطأ إضافية
157164

158-
* **Empty**: Form has a disabled "Submit" button.
159-
* **Typing**: Form has an enabled "Submit" button.
160-
* **Submitting**: Form is completely disabled. Spinner is shown.
161-
* **Success**: "Thank you" message is shown instead of a form.
162-
* **Error**: Same as Typing state, but with an extra error message.
163-
164-
Just like a designer, you'll want to "mock up" or create "mocks" for the different states before you add logic. For example, here is a mock for just the visual part of the form. This mock is controlled by a prop called `status` with a default value of `'empty'`:
165+
تمامًا مثل المصمم، سترغب في "تجربة" أو إنشاء "نماذج تجريبية" للحالات المختلفة قبل أن تضيف المنطق. على سبيل المثال، ها هو نموذج تجريبي للجزء المرئي فقط من النموذج. هذا النموذج التجريبي متحكم به بواسطة خاصيّة تدعى `statue` مع قيمة افتراضية `'empty'`:
165166

166167
<Sandpack>
167168

@@ -170,19 +171,19 @@ export default function Form({
170171
status = 'empty'
171172
}) {
172173
if (status === 'success') {
173-
return <h1>That's right!</h1>
174+
return <h1>هذا صحيح!</h1>
174175
}
175176
return (
176177
<>
177-
<h2>City quiz</h2>
178+
<h2>اختبار المدينة</h2>
178179
<p>
179-
In which city is there a billboard that turns air into drinkable water?
180+
في أي مدينة يوجد لوحة إعلانية تقوم بتحويل الهواء لمياه صالحة للشرب؟
180181
</p>
181182
<form>
182183
<textarea />
183184
<br />
184185
<button>
185-
Submit
186+
أرسل
186187
</button>
187188
</form>
188189
</>
@@ -192,23 +193,23 @@ export default function Form({
192193

193194
</Sandpack>
194195

195-
You could call that prop anything you like, the naming is not important. Try editing `status = 'empty'` to `status = 'success'` to see the success message appear. Mocking lets you quickly iterate on the UI before you wire up any logic. Here is a more fleshed out prototype of the same component, still "controlled" by the `status` prop:
196+
يمكنك تسمية الخاصيّة أيّ شيء تريد، التسمية ليست مهمة. جرب تعديل `status = 'empty'` إلى `status = 'success'` لترى رسالة النجاح تظهر. التجربة تتيح لك التكرار السريع على واجهة المستخدم قبل ربط أي منطق. ها هو نموذج تجريبي أكثر تفصيلًا لنفس المكوّن، يظل "متحكم" بواسطة الخاصية `status`:
196197

197198
<Sandpack>
198199

199200
```js
200201
export default function Form({
201-
// Try 'submitting', 'error', 'success':
202+
// جرب 'submitting'، 'error'، 'success':
202203
status = 'empty'
203204
}) {
204205
if (status === 'success') {
205-
return <h1>That's right!</h1>
206+
return <h1>هذا صحيح!</h1>
206207
}
207208
return (
208209
<>
209210
<h2>City quiz</h2>
210211
<p>
211-
In which city is there a billboard that turns air into drinkable water?
212+
في أي مدينة يوجد لوحة إعلانية تقوم بتحويل الهواء لمياه صالحة للشرب؟
212213
</p>
213214
<form>
214215
<textarea disabled={
@@ -219,11 +220,11 @@ export default function Form({
219220
status === 'empty' ||
220221
status === 'submitting'
221222
}>
222-
Submit
223+
أرسل
223224
</button>
224225
{status === 'error' &&
225226
<p className="Error">
226-
Good guess but a wrong answer. Try again!
227+
توقع جيد ولكن إجابة خاطئة. حاول مرة أخرى!
227228
</p>
228229
}
229230
</form>
@@ -240,9 +241,9 @@ export default function Form({
240241

241242
<DeepDive>
242243

243-
#### Displaying many visual states at once {/*displaying-many-visual-states-at-once*/}
244+
#### عرض عديد من الحالات المرئية مرة واحدة {/*displaying-many-visual-states-at-once*/}
244245

245-
If a component has a lot of visual states, it can be convenient to show them all on one page:
246+
لو أن لمكون العديد من الحالات المرئية، قد يكون ملائما عرضها جميعها في صفحة واحدة:
246247

247248
<Sandpack>
248249

@@ -262,7 +263,7 @@ export default function App() {
262263
<>
263264
{statuses.map(status => (
264265
<section key={status}>
265-
<h4>Form ({status}):</h4>
266+
<h4>نموذج ({status}):</h4>
266267
<Form status={status} />
267268
</section>
268269
))}
@@ -274,7 +275,7 @@ export default function App() {
274275
```js Form.js
275276
export default function Form({ status }) {
276277
if (status === 'success') {
277-
return <h1>That's right!</h1>
278+
return <h1>هذا صحيح!</h1>
278279
}
279280
return (
280281
<form>
@@ -286,11 +287,11 @@ export default function Form({ status }) {
286287
status === 'empty' ||
287288
status === 'submitting'
288289
}>
289-
Submit
290+
أرسل
290291
</button>
291292
{status === 'error' &&
292293
<p className="Error">
293-
Good guess but a wrong answer. Try again!
294+
توقع جيد ولكن إجابة خاطئة. حاول مرة أخرى!
294295
</p>
295296
}
296297
</form>
@@ -307,7 +308,7 @@ body { margin: 0; }
307308

308309
</Sandpack>
309310

310-
Pages like this are often called "living styleguides" or "storybooks".
311+
صفحات مثل هذه غالبًا يطلق عليها "living styleguides" أو "storybooks"
311312

312313
</DeepDive>
313314

0 commit comments

Comments
 (0)