You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/reusability/plugins.md
+30-30Lines changed: 30 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -1,70 +1,70 @@
1
-
# Plugins {#plugins}
1
+
# الملحقات {#plugins}
2
2
3
-
## Introduction {#introduction}
3
+
## مقدمة {#introduction}
4
4
5
-
Plugins are self-contained code that usually add app-level functionality to Vue. This is how we install a plugin:
5
+
الملحقات هي عبارة عن شيفرة مستقة تضيف عادةً وظائف على مستوى التطبيق إلى Vue. هذه هي طريقة تثبيت ملحق:
6
6
7
7
```js
8
8
import { createApp } from'vue'
9
9
10
10
constapp=createApp({})
11
11
12
12
app.use(myPlugin, {
13
-
/*optional options*/
13
+
/*خيارات اختيارية*/
14
14
})
15
15
```
16
16
17
-
A plugin is defined as either an object that exposes an `install()` method, or simply a function that acts as the install function itself. The install function receives the [app instance](/api/application.html)along with additional options passed to `app.use()`, if any:
17
+
يُعرَّف الملحق على أنه إما كائن يعرض التابع `()install` أو مجرد دالة تتصرف بنفسها كدالة تثبيت. تتلقى دالة التثبيت [نسخة التطبيق](/api/application.html)بالإضافة إلى خيارات إضافية مرسلة إلى `()app.use` ، إذا توفرت:
18
18
19
19
```js
20
20
constmyPlugin= {
21
21
install(app, options) {
22
-
//configure the app
22
+
//تهيئة التطبيق
23
23
}
24
24
}
25
25
```
26
26
27
-
There is no strictly defined scope for a plugin, but common scenarios where plugins are useful include:
27
+
لا يوجد نطاق محدد بالضبط للملحق، ولكن السيناريوهات الشائعة التي تكون الملحقات مفيدة فيها تشمل:
28
28
29
-
1.Register one or more global components or custom directives with [`app.component()`](/api/application.html#app-component)and[`app.directive()`](/api/application.html#app-directive).
29
+
1.تسجيل مكون أو مجموعة مكونات أو موجهات مخصصة باستخدام [`app.component()`](/api/application.html#app-component)و[`app.directive()`](/api/application.html#app-directive).
30
30
31
-
2.Make a resource [injectable](/guide/components/provide-inject.html)throughout the app by calling [`app.provide()`](/api/application.html#app-provide).
31
+
2.جعل مورد ما [قابلاً للحقن](/guide/components/provide-inject.html)في جميع أنحاء التطبيق من خلال استدعاء [`()app.provide`](/api/application.html#app-provide).
32
32
33
-
3.Add some global instance properties or methods by attaching them to[`app.config.globalProperties`](/api/application.html#app-config-globalproperties).
33
+
3.إضافة بعض الخاصيات أو التوابع العامة لنسخة التطبيق من خلال إرفاقها بـ[`app.config.globalProperties`](/api/application.html#app-config-globalproperties).
34
34
35
-
4.A library that needs to perform some combination of the above (e.g.[vue-router](https://github.com/vuejs/vue-router-next)).
35
+
4.مكتبة تحتاج إلى تنفيذ بعض التركيبات المذكورة أعلاه (على سبيل المثال[vue-router](https://github.com/vuejs/vue-router-next)).
36
36
37
-
## Writing a Plugin {#writing-a-plugin}
37
+
## كتابة ملحق {#writing-a-plugin}
38
38
39
-
In order to better understand how to create your own Vue.js plugins, we will create a very simplified version of a plugin that displays `i18n` (short for [Internationalization](https://en.wikipedia.org/wiki/Internationalization_and_localization)) strings.
39
+
من أجل فهم أفضل لكيفية إنشاء ملحقات Vue.js الخاصة بك، سنقوم بإنشاء إصدار مبسط جدًا من ملحق يعرض السلاسل النصية لـ`i18n` (الإختصار لـ [تدويل (Internationalization)](https://en.wikipedia.org/wiki/Internationalization_and_localization)).
40
40
41
-
Let's begin by setting up the plugin object. It is recommended to create it in a separate file and export it, as shown below to keep the logic contained and separate.
41
+
لنبدأ بإعداد كائن الملحق. يُفضَّل إنشاءه في ملف منفصل وتصديره، كما هو موضح أدناه للحفاظ على تجميع الشيفرة والفصل بينها.
42
42
43
43
```js
44
44
// plugins/i18n.js
45
45
exportdefault {
46
46
install: (app, options) => {
47
-
//Plugin code goes here
47
+
//هنا شيفرة الملحق
48
48
}
49
49
}
50
50
```
51
51
52
-
We want to create a translation function. This function will receive a dot-delimited `key`string, which we will use to look up the translated string in the user-provided options. This is the intended usage in templates:
52
+
نريد إنشاء دالة ترجمة. ستتلقى هذه الدالة سلسلة نصية `key`مفصولة بنقطة، والتي سنستخدمها للبحث عن السلسلة المترجمة في خيارات المستخدم. هذا هو الاستخدام المقصود في القوالب:
53
53
54
54
```vue-html
55
55
<h1>{{ $translate('greetings.hello') }}</h1>
56
56
```
57
57
58
-
Since this function should be globally available in all templates, we will make it so by attaching it to `app.config.globalProperties`in our plugin:
58
+
نظرًا لأن هذه الدالة يجب أن تكون متاحة على جميع القوالب، سنجعلها متاحة على مستوى النسخة من خلال إرفاقها بـ `app.config.globalProperties`في ملحقنا:
59
59
60
60
```js{4-11}
61
61
// plugins/i18n.js
62
62
export default {
63
63
install: (app, options) => {
64
-
// inject a globally available $translate() method
Our `$translate` function will take a string such as `greetings.hello`, look inside the user provided configuration and return the translated value.
76
+
الدالة `translate$` ستأخذ سلسلة نصية مثل `greetings.hello`، وستبحث في الإعدادات الموفرة وستعيد القيمة المترجمة.
77
77
78
-
The object containing the translated keys should be passed to the plugin during installation via additional parameters to `app.use()`:
78
+
يجب إرسال كائن يحتوي على مفاتيح الترجمة إلى الملحق خلال التثبيت عبر وسائط إضافية لـلتابع `()app.use`:
79
79
80
80
```js
81
81
importi18nPluginfrom'./plugins/i18n'
82
82
83
83
app.use(i18nPlugin, {
84
84
greetings: {
85
-
hello:'Bonjour!'
85
+
hello:'مرحبا!'
86
86
}
87
87
})
88
88
```
89
89
90
-
Now, our initial expression `$translate('greetings.hello')` will be replaced by `Bonjour!`at runtime.
90
+
الآن، سيستبدل التعبير الأولي `translate('greetings.hello')$` بـ `مرحبا!`عند تشغيل التطبيق.
91
91
92
-
See also: [Augmenting Global Properties](/guide/typescript/options-api.html#augmenting-global-properties) <supclass="vt-badge ts" />
92
+
اطلع أيضا على: [تعزيز الخاصيات العامة](/guide/typescript/options-api.html#augmenting-global-properties) <supclass="vt-badge ts" />
93
93
94
-
:::tip
95
-
Use global properties scarcely, since it can quickly become confusing if too many global properties injected by different plugins are used throughout an app.
94
+
:::tip ملاحظة
95
+
استخدم الخاصيات العامة في حالة الضرورة فقط، لأنه يمكن أن يصبح الأمر مربكًا بسرعة إذا استخدمت العديد من الخاصيات العامة المدخلة من قبل ملحقات مختلفة مستخدمة عبر التطبيق.
96
96
:::
97
97
98
-
### Provide / Inject with Plugins {#provide-inject-with-plugins}
98
+
### الحقن/التزويد عبر الملحقات {#provide-inject-with-plugins}
99
99
100
-
Plugins also allow us to use `inject`to provide a function or attribute to the plugin's users. For example, we can allow the application to have access to the `options`parameter to be able to use the translations object.
100
+
الملحقات تسمح لنا أيضًا باستخدام `inject`لتزويد دالة أو سمة لمستخدمي الملحق. على سبيل المثال، يمكننا السماح للتطبيق بالوصول إلى الوسيط `options`لكي يتمكن من استخدام كائن الترجمات.
101
101
102
102
```js{10}
103
103
// plugins/i18n.js
@@ -114,7 +114,7 @@ export default {
114
114
}
115
115
```
116
116
117
-
Plugin users will now be able to inject the plugin options into their components using the `i18n` key:
117
+
سيتمكن مستخدمو الملحق الآن من إدخال خيارات الملحق في مكوناتهم باستخدام مفتاح `i18n`:
0 commit comments