Skip to content

Commit df5fc55

Browse files
authored
Merge pull request #473 from A7med3bdulBaset/add-react-to-an-existing-project
[DONE] Translate `Add React to an existing project`
2 parents 2e93dad + 5e13fcd commit df5fc55

File tree

2 files changed

+53
-51
lines changed

2 files changed

+53
-51
lines changed
Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,134 @@
11
---
2-
title: Add React to an Existing Project
2+
title: إضافة React إلى مشروع موجود بالفعل
33
---
44

55
<Intro>
66

7-
If you want to add some interactivity to your existing project, you don't have to rewrite it in React. Add React to your existing stack, and render interactive React components anywhere.
7+
إذا كنت تريد إضافة بعض التفاعلية إلى مشروعك الموجود بالفعل، فليس عليك إعادة كتابته في React. أضف React إلى مجموعة الأدوات الموجودة لديك، وقم بتقديم مكونات React التفاعلية في أي مكان.
88

99
</Intro>
1010

1111
<Note>
1212

13-
**You need to install [Node.js](https://nodejs.org/en/) for local development.** Although you can [try React](/learn/installation#try-react) online or with a simple HTML page, realistically most JavaScript tooling you'll want to use for development requires Node.js.
13+
**تحتاج إلى تثبيت [Node.js](https://nodejs.org/ar) إلى بيئة التطوير المحلية الخاصة بك.** على الرغم من أنه يمكنك [تجربة React](/learn/installation#try-react) عبر الإنترنت أو باستخدام صفحة HTML بسيطة، إلا أن معظم أدوات JavaScript التي تريد استخدامها للتطوير تتطلب Node.js.
1414

1515
</Note>
1616

17-
## Using React for an entire subroute of your existing website {/*using-react-for-an-entire-subroute-of-your-existing-website*/}
17+
## استخدام React لمسار فرعي كامل من موقع الويب الحالي الخاص بك {/*using-react-for-an-entire-subroute-of-your-existing-website*/}
1818

19-
Let's say you have an existing web app at `example.com` built with another server technology (like Rails), and you want to implement all routes starting with `example.com/some-app/` fully with React.
19+
لنفترض أن لديك تطبيق ويب موجود على `example.com` مبني بتقنية خادم أخرى (مثل Rails)، وتريد تنفيذ جميع المسارات التي تبدأ بـ `example.com/some-app/` بالكامل مع React.
2020

21-
Here's how we recommend to set it up:
21+
هنا ما نوصي به لإعداده:
2222

23-
1. **Build the React part of your app** using one of the [React-based frameworks](/learn/start-a-new-react-project).
24-
2. **Specify `/some-app` as the *base path*** in your framework's configuration (here's how: [Next.js](https://nextjs.org/docs/api-reference/next.config.js/basepath), [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
25-
3. **Configure your server or a proxy** so that all requests under `/some-app/` are handled by your React app.
23+
1. **بناء الجزء الخاص بـ React في تطبيقك** باستخدام إحدى [الإطارات المبنية على React](/learn/start-a-new-react-project).
24+
2. **حدد `/some-app` كـ *مسار أساسي*** في إعدادات إطار العمل الخاص بك (هنا كيف مع: [Next.js](https://nextjs.org/docs/api-reference/next.config.js/basepath), [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
25+
3. **قم بتكوين خادمك أو بروكسي** بحيث يتم التعامل مع جميع الطلبات تحت `/some-app/` من قبل تطبيق React الخاص بك.
2626

27-
This ensures the React part of your app can [benefit from the best practices](/learn/start-a-new-react-project#can-i-use-react-without-a-framework) baked into those frameworks.
27+
يضمن هذا أن الجزء الخاص بـ React من تطبيقك يمكن أن يستفيد من [أفضل الممارسات](/learn/start-a-new-react-project#can-i-use-react-without-a-framework) المدمجة في تلك الإطارات.
2828

29-
Many React-based frameworks are full-stack and let your React app take advantage of the server. However, you can use the same approach even if you can't or don't want to run JavaScript on the server. In that case, serve the HTML/CSS/JS export ([`next export` output](https://nextjs.org/docs/advanced-features/static-html-export) for Next.js, default for Gatsby) at `/some-app/` instead.
29+
العديد من الإطارات القائمة على React هي إطارات full-stack وتتيح لتطبيق React الخاص بك الاستفادة من الخادم. ومع ذلك، يمكنك استخدام نفس النهج حتى إذا لم تتمكن أو لا تريد تشغيل JavaScript على الخادم. في هذه الحالة
30+
، قم بتصدير HTML/CSS/JS ([`next export`](https://nextjs.org/docs/advanced-features/static-html-export) لـ Next.js ، هذا هو الافتراضي لـ Gatsby) في `/some-app/` بدلاً من ذلك.
3031

31-
## Using React for a part of your existing page {/*using-react-for-a-part-of-your-existing-page*/}
32+
## استخدام React لجزء من صفحتك الحالية {/*using-react-for-a-part-of-your-existing-page*/}
3233

33-
Let's say you have an existing page built with another technology (either a server one like Rails, or a client one like Backbone), and you want to render interactive React components somewhere on that page. That's a common way to integrate React--in fact, it's how most React usage looked at Meta for many years!
34+
لنفترض أن لديك صفحة موجودة على `example.com` مبنية بتقنية أخرى (إما خادم مثل Rails أو عميل مثل Backbone)، وتريد تقديم مكونات React التفاعلية في أي مكان على تلك الصفحة. هذه هي الطريقة الشائعة لدمج React - في الواقع، هذا هو شكل معظم استخدام React في [Meta](https://about.meta.com/) لسنوات عديدة!
3435

35-
You can do this in two steps:
36+
يمكنك القيام بذلك في خطوتين:
3637

37-
1. **Set up a JavaScript environment** that lets you use the [JSX syntax](/learn/writing-markup-with-jsx), split your code into modules with the [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) / [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) syntax, and use packages (for example, React) from the [npm](https://www.npmjs.com/) package registry.
38-
2. **Render your React components** where you want to see them on the page.
38+
1. **إعداد بيئة JavaScript** والتي تمكنك من استخدام [بنية JSX](/learn/writing-markup-with-jsx)، وتقسيم الكود إلى وحدات باستخدام العبارات الأساسية [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) / [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)، واستخدام الحزم (على سبيل المثال ، React) من [مدير الحزم npm](https://www.npmjs.com/).
39+
2. **قم بتصيير مكونات React** حيث تريد رؤيتها على الصفحة.
3940

40-
The exact approach depends on your existing page setup, so let's walk through some details.
41+
نفس النهج يعتمد على إعداد صفحتك الحالية، لذلك دعنا نتناول بعض التفاصيل.
4142

42-
### Step 1: Set up a modular JavaScript environment {/*step-1-set-up-a-modular-javascript-environment*/}
43+
### الخطوة 1: إعداد بيئة JavaScript معمارية (modular) {/*step-1-set-up-a-modular-javascript-environment*/}
4344

44-
A modular JavaScript environment lets you write your React components in individual files, as opposed to writing all of your code in a single file. It also lets you use all the wonderful packages published by other developers on the [npm](https://www.npmjs.com/) registry--including React itself! How you do this depends on your existing setup:
45+
بيئة JavaScript المعمارية تسمح لك بكتابة مكونات React في ملفات منفصلة، بدلاً من كتابة كل الكود في ملف واحد. كما تتيح لك استخدام جميع الحزم الرائعة التي نشرها مطورون آخرون على [مدير الحزم npm](https://www.npmjs.com/) - بما في ذلك React نفسه! كيفية القيام بذلك تعتمد على إعدادك الحالي:
4546

46-
* **If your app is already split into files that use `import` statements,** try to use the setup you already have. Check whether writing `<div />` in your JS code causes a syntax error. If it causes a syntax error, you might need to [transform your JavaScript code with Babel](https://babeljs.io/setup), and enable the [Babel React preset](https://babeljs.io/docs/babel-preset-react) to use JSX.
47+
* **إذا كان تطبيقك مقسم بالفعل إلى ملفات تستخدم عبارات `import`**، فحاول استخدام الإعداد الذي لديك بالفعل. تحقق مما إذا كان كتابة `<div />` في كود JS الخاص بك يسبب خطأ في البناء. إذا تسبب في خطأ في البناء، فقد تحتاج إلى [تحويل كود JavaScript الخاص بك باستخدام Babel](https://babeljs.io/setup)، وتمكين [Babel React preset](https://babeljs.io/docs/babel-preset-react) لاستخدام JSX.
4748

48-
* **If your app doesn't have an existing setup for compiling JavaScript modules,** set it up with [Vite](https://vitejs.dev/). The Vite community maintains [many integrations with backend frameworks](https://github.com/vitejs/awesome-vite#integrations-with-backends), including Rails, Django, and Laravel. If your backend framework is not listed, [follow this guide](https://vitejs.dev/guide/backend-integration.html) to manually integrate Vite builds with your backend.
49+
* **إذا لم يكن لتطبيقك إعداد حالي لتجميع وحدات JavaScript**، فقم بإعداده مع [Vite](https://vitejs.dev/). تحتفظ مجتمع Vite بـ [العديد من التكاملات مع إطارات العمل الخلفية](https://github.com/vitejs/) ، بما في ذلك Rails و Django و Laravel. إذا لم يتم سرد إطار عمل الخلفية الخاص بك، [اتبع هذه الإرشادات](https://vitejs.dev/guide/backend-integration.html) لدمج بناء Vite يدويًا مع إطار عملك.
4950

50-
To check whether your setup works, run this command in your project folder:
51+
للتحقق مما إذا كان إعدادك يعمل، قم بتشغيل هذا الأمر في مجلد مشروعك:
5152

5253
<TerminalBlock>
5354
npm install react react-dom
5455
</TerminalBlock>
5556

56-
Then add these lines of code at the top of your main JavaScript file (it might be called `index.js` or `main.js`):
57+
ثم أضف هذه الأسطر من الكود في أعلى ملف JavaScript الرئيسي الخاص بك (قد يسمى `index.js` أو `main.js`):
5758

5859
<Sandpack>
5960

6061
```html index.html hidden
6162
<!DOCTYPE html>
6263
<html>
63-
<head><title>My app</title></head>
64+
<head><title>تطبيقي</title></head>
6465
<body>
65-
<!-- Your existing page content (in this example, it gets replaced) -->
66+
<!-- محتوى صفحتك الحالي (في هذا المثال سيتم تبديله) -->
6667
</body>
6768
</html>
6869
```
6970

7071
```js index.js active
7172
import { createRoot } from 'react-dom/client';
7273

73-
// Clear the existing HTML content
74+
// إزالة محتوى HTML الحالي
7475
document.body.innerHTML = '<div id="app"></div>';
7576

76-
// Render your React component instead
77+
// عرض مكون React بدلاً من ذلك
7778
const root = createRoot(document.getElementById('app'));
78-
root.render(<h1>Hello, world</h1>);
79+
root.render(<h1>مرحبًا بكم!</h1>);
7980
```
8081

8182
</Sandpack>
8283

83-
If the entire content of your page was replaced by a "Hello, world!", everything worked! Keep reading.
84+
إذا تم استبدال محتوى صفحتك بالكامل بـ "مرحبًا بكم!"، فقد نجحت العملية! استمر في القراءة.
8485

8586
<Note>
8687

87-
Integrating a modular JavaScript environment into an existing project for the first time can feel intimidating, but it's worth it! If you get stuck, try our [community resources](/community) or the [Vite Chat](https://chat.vitejs.dev/).
88+
دمج بيئة JavaScript معمارية في مشروع موجود قد يبدو مرعبًا أول الأمر، ولكنه يستحق ذلك! إذا تعثرت ، جرب [السؤال في المجتمع](/community) أو [الدردشة في Vite](https://chat.vitejs.dev/).
8889

8990
</Note>
9091

91-
### Step 2: Render React components anywhere on the page {/*step-2-render-react-components-anywhere-on-the-page*/}
92+
### الخطوة 2: عرض مكونات React في أي مكان على الصفحة {/*step-2-render-react-components-anywhere-on-the-page*/}
93+
94+
في الخطوة السابقة، وضعت هذا الكود في أعلى ملفك الرئيسي:
9295

93-
In the previous step, you put this code at the top of your main file:
9496

9597
```js
9698
import { createRoot } from 'react-dom/client';
9799

98-
// Clear the existing HTML content
100+
// إزالة محتوى HTML الحالي
99101
document.body.innerHTML = '<div id="app"></div>';
100102

101-
// Render your React component instead
103+
// عرض مكون React بدلاً من ذلك
102104
const root = createRoot(document.getElementById('app'));
103-
root.render(<h1>Hello, world</h1>);
105+
root.render(<h1>مرحبًا بكم!</h1>);
104106
```
105107

106-
Of course, you don't actually want to clear the existing HTML content!
108+
بالتأكيد لا تريد حذف محتوى HTML الحالي!
107109

108-
Delete this code.
110+
احذف هذا الكود.
109111

110-
Instead, you probably want to render your React components in specific places in your HTML. Open your HTML page (or the server templates that generate it) and add a unique [`id`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) attribute to any tag, for example:
112+
بدلًا عن ذلك، ربما تريد عرض مكونات React الخاصة بك في أماكن محددة في HTML الخاص بك. افتح صفحة HTML الخاصة بك (أو قوالب الخادم التي تنشئها) وأضف معرفًا فريدًا [`id`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) إلى أي علامة، على سبيل المثال:
111113

112114
```html
113-
<!-- ... somewhere in your html ... -->
115+
<!-- ... في مكان ما في ملف html ... -->
114116
<nav id="navigation"></nav>
115-
<!-- ... more html ... -->
117+
<!-- ... المزيد من html ... -->
116118
```
117119

118-
This lets you find that HTML element with [`document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById) and pass it to [`createRoot`](/reference/react-dom/client/createRoot) so that you can render your own React component inside:
120+
هذا يتيح لك العثور على عنصر HTML باستخدام [`document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById) وتمريره إلى [`createRoot`](/reference/react-dom/client/createRoot) حتى تتمكن من عرض مكون React الخاص بك داخله:
119121

120122
<Sandpack>
121123

122124
```html index.html
123125
<!DOCTYPE html>
124126
<html>
125-
<head><title>My app</title></head>
127+
<head><title>تطبيقي</title></head>
126128
<body>
127-
<p>This paragraph is a part of HTML.</p>
129+
<p>فقرة من أجزاء HTML</p>
128130
<nav id="navigation"></nav>
129-
<p>This paragraph is also a part of HTML.</p>
131+
<p>وهذه الفقرة أيضًا من أجزاء HTML</p>
130132
</body>
131133
</html>
132134
```
@@ -135,8 +137,8 @@ This lets you find that HTML element with [`document.getElementById`](https://de
135137
import { createRoot } from 'react-dom/client';
136138

137139
function NavigationBar() {
138-
// TODO: Actually implement a navigation bar
139-
return <h1>Hello from React!</h1>;
140+
// مَهمّة: هذا المكون يعرض مكون شريط التنقل
141+
return <h1>مرحبًا من React</h1>;
140142
}
141143

142144
const domNode = document.getElementById('navigation');
@@ -146,10 +148,10 @@ root.render(<NavigationBar />);
146148

147149
</Sandpack>
148150

149-
Notice how the original HTML content from `index.html` is preserved, but your own `NavigationBar` React component now appears inside the `<nav id="navigation">` from your HTML. Read the [`createRoot` usage documentation](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) to learn more about rendering React components inside an existing HTML page.
151+
لاحظ كيف احتفظت بمحتوى HTML الحالي من `index.html`، ولكن مكون React الخاص بك `NavigationBar` الآن يظهر داخل `<nav id="navigation">` من HTML الخاص بك. اقرأ [وثائق استخدام `createRoot`](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) لمعرفة المزيد حول تصيير مكونات React داخل صفحة HTML موجودة.
150152

151-
When you adopt React in an existing project, it's common to start with small interactive components (like buttons), and then gradually keep "moving upwards" until eventually your entire page is built with React. If you ever reach that point, we recommend migrating to [a React framework](/learn/start-a-new-react-project) right after to get the most out of React.
153+
عندما تضيف React في مشروع موجود، من الشائع أن تبدأ بمكونات تفاعلية صغيرة (مثل الأزرار)، ثم تستمر تدريجيًا في "النمو" حتى تصبح صفحتك بأكملها مبنية بـ React. إذا وصلت إلى هذه النقطة، فإننا نوصي بالانتقال إلى [إطار عمل لـ React](/learn/start-a-new-react-project) مباشرة بعد ذلك للاستفادة القصوى من React.
152154

153-
## Using React Native in an existing native mobile app {/*using-react-native-in-an-existing-native-mobile-app*/}
155+
## استخدام React Native في تطبيق محمول أصلي موجود {/*using-react-native-in-an-existing-native-mobile-app*/}
154156

155-
[React Native](https://reactnative.dev/) can also be integrated into existing native apps incrementally. If you have an existing native app for Android (Java or Kotlin) or iOS (Objective-C or Swift), [follow this guide](https://reactnative.dev/docs/integration-with-existing-apps) to add a React Native screen to it.
157+
يمكن أيضًا دمج [React Native](https://reactnative.dev/) في التطبيقات الأصلية الموجودة تدريجيًا. إذا كان لديك تطبيق أصلي موجود لنظام أندرويد (Java أو Kotlin) أو iOS (Objective-C أو Swift) ، [اتبع هذا الدليل](https://reactnative.dev/docs/integration-with-existing-apps) لإضافة شاشة React Native إليه.

src/sidebarLearn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"path": "/learn/start-a-new-react-project"
3030
},
3131
{
32-
"title": "Add React to an Existing Project",
32+
"title": "إضافة React إلى مشروع موجود بالفعل",
3333
"path": "/learn/add-react-to-an-existing-project"
3434
},
3535
{

0 commit comments

Comments
 (0)