Skip to content

Commit 5967e00

Browse files
authored
Merge pull request #483 from remahmoud/add-useid-page-translation
useId page translation
2 parents 1c4f32f + a923efc commit 5967e00

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

src/content/reference/react/useId.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: useId
44

55
<Intro>
66

7-
`useId` is a React Hook for generating unique IDs that can be passed to accessibility attributes.
7+
`useId` هو خطاف react يستخدم لإنشاء معرفات فريدة يمكن تمريرها إلى سمات إمكانية الوصول.
88

99
```js
1010
const id = useId()
@@ -16,11 +16,11 @@ const id = useId()
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## المرجع {/*reference*/}
2020

2121
### `useId()` {/*useid*/}
2222

23-
Call `useId` at the top level of your component to generate a unique ID:
23+
استدع `useId` في المستوى الأعلى لمكونك لإنشاء معرف فريد
2424

2525
```js
2626
import { useId } from 'react';
@@ -30,35 +30,35 @@ function PasswordField() {
3030
// ...
3131
```
3232
33-
[See more examples below.](#usage)
33+
[يرجى الإطلاع على المزيد من الأمثلة بالأسفل.](#usage)
3434
35-
#### Parameters {/*parameters*/}
35+
#### المعاملات (parameters) {/*parameters*/}
3636
37-
`useId` does not take any parameters.
37+
`useId` لا يقبل أي معاملات.
3838
39-
#### Returns {/*returns*/}
39+
#### العائدات {/*returns*/}
4040
41-
`useId` returns a unique ID string associated with this particular `useId` call in this particular component.
41+
`useId` يعيد نص فريد مرتبط باستدعاء `useId` المستخدم في هذا المكون تحديدا.
4242
43-
#### Caveats {/*caveats*/}
43+
#### تنبيهات {/*caveats*/}
4444
45-
* `useId` is a Hook, so you can only call it **at the top level of your component** or your own Hooks. You can't call it inside loops or conditions. If you need that, extract a new component and move the state into it.
45+
* `useId` هو خطاف، لذلك يمكنك استدعائه فقط **في المستوي الأعلي من مكونك** أو من خلال الخطافات الخاصة بك. لا يمكنك استدعاء الخطاف داخل الحلقات والشروط. إذا كنت بحاجة إلي ذلك، قم بإستخراج مكون جديد وقم بنقل الحالة إليه.
4646
47-
* `useId` **should not be used to generate keys** in a list. [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)
47+
* `useId` **لا ينبغي استخدامه لتوليد المفاتيح** في القائمة. [يجب أن تتم إنشاء المفاتيح من البيانات الخاصة بك.](/learn/rendering-lists#where-to-get-your-key)
4848
4949
---
5050
51-
## Usage {/*usage*/}
51+
## الاستخدام {/*usage*/}
5252
5353
<Pitfall>
5454
55-
**Do not call `useId` to generate keys in a list.** [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)
55+
**لا تستدعِ `useId` لتوليد المفاتيح في القائمة.** [يجب أن تتم إنشاء المفاتيح من البيانات الخاصة بك.](/learn/rendering-lists#where-to-get-your-key)
5656
5757
</Pitfall>
5858
59-
### Generating unique IDs for accessibility attributes {/*generating-unique-ids-for-accessibility-attributes*/}
59+
### إنشاء معرفات فريدة لسمات إمكانية الوصول {/*generating-unique-ids-for-accessibility-attributes*/}
6060
61-
Call `useId` at the top level of your component to generate a unique ID:
61+
استدعِ `useId` في المستوي الأعلي من المكون الخاص بك لإنشاء معرف فريد:
6262
6363
```js [[1, 4, "passwordHintId"]]
6464
import { useId } from 'react';
@@ -68,7 +68,7 @@ function PasswordField() {
6868
// ...
6969
```
7070
71-
You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different attributes:
71+
يمكنك بعد ذلك تمرير <CodeStep step={1}>المعرف الذى تم إنشاؤه</CodeStep> إلى سمات مختلفة:
7272
7373
```js [[1, 2, "passwordHintId"], [1, 3, "passwordHintId"]]
7474
<>
@@ -77,11 +77,11 @@ You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different at
7777
</>
7878
```
7979
80-
**Let's walk through an example to see when this is useful.**
80+
**دعنا نستعرض مثالا لمعرفة متى يكون ذلك مفيدا.**
8181
82-
[HTML accessibility attributes](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) like [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) let you specify that two tags are related to each other. For example, you can specify that an element (like an input) is described by another element (like a paragraph).
82+
[HTML accessibility attributes](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) مثل [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) تتيح لك تحديد أن هناك علامتين مرتبطين ببعضهما البعض. على سبيل المثال، يمكنك تحديد أن العنصر (مثل صندوق الإدخال) يتم وصفه بواسطة عنصر آخر (مثل فقرة).
8383
84-
In regular HTML, you would write it like this:
84+
في HTML العادي ستكتبه بهذا الشكل:
8585
8686
```html {5,8}
8787
<label>
@@ -92,11 +92,11 @@ In regular HTML, you would write it like this:
9292
/>
9393
</label>
9494
<p id="password-hint">
95-
The password should contain at least 18 characters
95+
يجب أن تحتوي كلمة السر على 18 حرفًا على الأقل
9696
</p>
9797
```
9898
99-
However, hardcoding IDs like this is not a good practice in React. A component may be rendered more than once on the page--but IDs have to be unique! Instead of hardcoding an ID, generate a unique ID with `useId`:
99+
مع ذلك، تضمين المعرفات بهذا الشكل ليس طريقة جيدة في React. يمكن أن يتم عرض المكون أكثر من مرة على الصفحة، ولكن يجب أن تكون المعرفات فريدة! بدلا من تضمين معرف ثابت، يمكنك توليد معرف فريد باستخدام `useId`:
100100
101101
```js {4,11,14}
102102
import { useId } from 'react';
@@ -113,14 +113,14 @@ function PasswordField() {
113113
/>
114114
</label>
115115
<p id={passwordHintId}>
116-
The password should contain at least 18 characters
116+
يجب أن تحتوي كلمة السر على 18 حرفًا على الأقل
117117
</p>
118118
</>
119119
);
120120
}
121121
```
122122
123-
Now, even if `PasswordField` appears multiple times on the screen, the generated IDs won't clash.
123+
الآن، حتى إذا كان `PasswordField` يظهر عدة مرات على الشاشة، لن تحدث تعارضات بين المعرفات المولدة.
124124
125125
<Sandpack>
126126
@@ -139,7 +139,7 @@ function PasswordField() {
139139
/>
140140
</label>
141141
<p id={passwordHintId}>
142-
The password should contain at least 18 characters
142+
يجب أن تحتوي كلمة السر على 18 حرفًا على الأقل
143143
</p>
144144
</>
145145
);
@@ -148,9 +148,9 @@ function PasswordField() {
148148
export default function App() {
149149
return (
150150
<>
151-
<h2>Choose password</h2>
151+
<h2>أدخل كلمة سر</h2>
152152
<PasswordField />
153-
<h2>Confirm password</h2>
153+
<h2>تأكيد كلمة السر</h2>
154154
<PasswordField />
155155
</>
156156
);
@@ -163,33 +163,33 @@ input { margin: 5px; }
163163
164164
</Sandpack>
165165
166-
[Watch this video](https://www.youtube.com/watch?v=0dNzNcuEuOo) to see the difference in the user experience with assistive technologies.
166+
[شاهد هذا الفيديو](https://www.youtube.com/watch?v=0dNzNcuEuOo) لترى الفرق في تجربة المستخدم مع تقنيات المساعدة.
167167
168168
<Pitfall>
169169
170-
With [server rendering](/reference/react-dom/server), **`useId` requires an identical component tree on the server and the client**. If the trees you render on the server and the client don't match exactly, the generated IDs won't match.
170+
في [تصيير الخادم](/reference/react-dom/server), **يتطلب `useId` وجود نفس شجرة المكونات علي الخادم والعميل**. إذا لم تتطابق الشجرات التي تقوم بعرضها على الخادم والعميل حرفيا، فإن المعرفات المولدة لن تتطابق.
171171
172172
</Pitfall>
173173
174174
<DeepDive>
175175
176-
#### Why is useId better than an incrementing counter? {/*why-is-useid-better-than-an-incrementing-counter*/}
176+
#### لماذا يعد useId أفضل من العداد المتزايد؟ {/*why-is-useid-better-than-an-incrementing-counter*/}
177177
178-
You might be wondering why `useId` is better than incrementing a global variable like `nextId++`.
178+
قد تتساءل لماذا `useId` أفضل من زيادة متغير عالمي مثل `nextId++`.
179179
180-
The primary benefit of `useId` is that React ensures that it works with [server rendering.](/reference/react-dom/server) During server rendering, your components generate HTML output. Later, on the client, [hydration](/reference/react-dom/client/hydrateRoot) attaches your event handlers to the generated HTML. For hydration to work, the client output must match the server HTML.
180+
الفائدة الأساسية لـ `useId` هي أن React ستضمن أنه يعمل مع [تصيير الخادم.](/reference/react-dom/server) أثناء تصيير الخادم، يتم تحويل مكوناتك إلي عناصر HTML. في وقت لاحق، على العميل، [hydration](/reference/react-dom/client/hydrateRoot) يقوم بربط معالجات الأحداث الخاصة بك بعناصر HTML التي تم توليدها. لكي يعمل تحويل العناصر على العميل بشكل صحيح، يجب أن يتطابق إخراج العميل مع HTML الذي على الخادم.
181181
182-
This is very difficult to guarantee with an incrementing counter because the order in which the client components are hydrated may not match the order in which the server HTML was emitted. By calling `useId`, you ensure that hydration will work, and the output will match between the server and the client.
182+
من الصعب جدا ضمان ذلك باستخدام عداد متزايد لأن ترتيب تحويل المكونات على العميل قد لا يتطابق مع ترتيب إخراج HTML على الخادم. من خلال استدعاء `useId`، ستضمن أن عملية تحويل المكونات ستعمل بشكل صحيح، وسيتطابق الإخراج بين الخادم والعميل.
183183
184-
Inside React, `useId` is generated from the "parent path" of the calling component. This is why, if the client and the server tree are the same, the "parent path" will match up regardless of rendering order.
184+
داخل React، يتم إنشاء `useId` من الـ "مسار الأب" للمكون الذي يستدعيه. وهذا هو السبب في أنه إذا كانت شجرة العميل وشجرة الخادم متطابقتين، سيتطابق "مسار لأب" بغض النظر عن ترتيب العرض.
185185
186186
</DeepDive>
187187
188188
---
189189
190-
### Generating IDs for several related elements {/*generating-ids-for-several-related-elements*/}
190+
### توليد معرفات لعدة عناصر ذات صلة {/*generating-ids-for-several-related-elements*/}
191191
192-
If you need to give IDs to multiple related elements, you can call `useId` to generate a shared prefix for them:
192+
إذا كنت بحاجة إلى تعيين معرفات لعدة عناصر ذات صلة، يمكنك استدعاء `useId` لتوليد بادئة مشتركة لها:
193193
194194
<Sandpack>
195195
@@ -200,10 +200,10 @@ export default function Form() {
200200
const id = useId();
201201
return (
202202
<form>
203-
<label htmlFor={id + '-firstName'}>First Name:</label>
203+
<label htmlFor={id + '-firstName'}>الاسم الأول:</label>
204204
<input id={id + '-firstName'} type="text" />
205205
<hr />
206-
<label htmlFor={id + '-lastName'}>Last Name:</label>
206+
<label htmlFor={id + '-lastName'}>الاسم الأخير:</label>
207207
<input id={id + '-lastName'} type="text" />
208208
</form>
209209
);
@@ -216,20 +216,20 @@ input { margin: 5px; }
216216
217217
</Sandpack>
218218
219-
This lets you avoid calling `useId` for every single element that needs a unique ID.
219+
هذا يتيح لك تجنب استدعاء `useId` لكل عنصر يحتاج إلى معرف فريد.
220220
221221
---
222222
223-
### Specifying a shared prefix for all generated IDs {/*specifying-a-shared-prefix-for-all-generated-ids*/}
223+
### تحديد بادئة مشتركة لجميع المعرفات المولدة {/*specifying-a-shared-prefix-for-all-generated-ids*/}
224224
225-
If you render multiple independent React applications on a single page, pass `identifierPrefix` as an option to your [`createRoot`](/reference/react-dom/client/createRoot#parameters) or [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) calls. This ensures that the IDs generated by the two different apps never clash because every identifier generated with `useId` will start with the distinct prefix you've specified.
225+
إذا كنت تقوم بعرض عدة تطبيقات react مستقلة على صفحة واحدة, قم بتمرير `identifierPrefix` كخيار إلى استدعاءات [`createRoot`](/reference/react-dom/client/createRoot#parameters) أو [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) الخاصة بك. هذا يضمن عدم حدوث تعارض بين المعرفات المولدة بواسطة التطبيقين المختلفين لأن كل معرف تم إنشاؤه باستخدام `useId` سيبدأ بالبادئة المميزة التي حددتها.
226226
227227
<Sandpack>
228228
229229
```html index.html
230230
<!DOCTYPE html>
231231
<html>
232-
<head><title>My app</title></head>
232+
<head><title>تطبيقي</title></head>
233233
<body>
234234
<div id="root1"></div>
235235
<div id="root2"></div>
@@ -253,7 +253,7 @@ function PasswordField() {
253253
/>
254254
</label>
255255
<p id={passwordHintId}>
256-
The password should contain at least 18 characters
256+
يجب أن تحتوي كلمة السر على 18 حرفًا على الأقل
257257
</p>
258258
</>
259259
);
@@ -262,7 +262,7 @@ function PasswordField() {
262262
export default function App() {
263263
return (
264264
<>
265-
<h2>Choose password</h2>
265+
<h2>أدخل كلمة السر</h2>
266266
<PasswordField />
267267
</>
268268
);
@@ -274,7 +274,7 @@ import { createRoot } from 'react-dom/client';
274274
import App from './App.js';
275275
import './styles.css';
276276

277-
const root1 = createRoot(document.getElementById('root1'), {
277+
const root1 createRoot(document.getElementById('root1'), {
278278
identifierPrefix: 'my-first-app-'
279279
});
280280
root1.render(<App />);

0 commit comments

Comments
 (0)