Skip to content

Commit bf1c516

Browse files
committed
translate plugins vuejs#27
1 parent 7d75ddc commit bf1c516

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

glossary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@
7272
| url | عنوان محدد الموارد |
7373
| mixin | مخلوط |
7474
| renderless | عديمة تصيير |
75+
| argument | وسيط |
76+
| parameter | معامل |

src/guide/reusability/plugins.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
# Plugins {#plugins}
1+
# الملحقات {#plugins}
22

3-
## Introduction {#introduction}
3+
## مقدمة {#introduction}
44

5-
Plugins are self-contained code that usually add app-level functionality to Vue. This is how we install a plugin:
5+
الملحقات هي عبارة عن شيفرة مستقة تضيف عادةً وظائف على مستوى التطبيق إلى Vue. هذه هي طريقة تثبيت ملحق:
66

77
```js
88
import { createApp } from 'vue'
99

1010
const app = createApp({})
1111

1212
app.use(myPlugin, {
13-
/* optional options */
13+
/* خيارات اختيارية */
1414
})
1515
```
1616

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` ، إذا توفرت:
1818

1919
```js
2020
const myPlugin = {
2121
install(app, options) {
22-
// configure the app
22+
// تهيئة التطبيق
2323
}
2424
}
2525
```
2626

27-
There is no strictly defined scope for a plugin, but common scenarios where plugins are useful include:
27+
لا يوجد نطاق محدد بالضبط للملحق، ولكن السيناريوهات الشائعة التي تكون الملحقات مفيدة فيها تشمل:
2828

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).
3030

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).
3232

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).
3434

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)).
3636

37-
## Writing a Plugin {#writing-a-plugin}
37+
## كتابة ملحق {#writing-a-plugin}
3838

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)).
4040

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+
لنبدأ بإعداد كائن الملحق. يُفضَّل إنشاءه في ملف منفصل وتصديره، كما هو موضح أدناه للحفاظ على تجميع الشيفرة والفصل بينها.
4242

4343
```js
4444
// plugins/i18n.js
4545
export default {
4646
install: (app, options) => {
47-
// Plugin code goes here
47+
// هنا شيفرة الملحق
4848
}
4949
}
5050
```
5151

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` مفصولة بنقطة، والتي سنستخدمها للبحث عن السلسلة المترجمة في خيارات المستخدم. هذا هو الاستخدام المقصود في القوالب:
5353

5454
```vue-html
5555
<h1>{{ $translate('greetings.hello') }}</h1>
5656
```
5757

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` في ملحقنا:
5959

6060
```js{4-11}
6161
// plugins/i18n.js
6262
export default {
6363
install: (app, options) => {
64-
// inject a globally available $translate() method
64+
// احقن بشكل عام دالة $translate()
6565
app.config.globalProperties.$translate = (key) => {
66-
// retrieve a nested property in `options`
67-
// using `key` as the path
66+
// استرجاع خاصية متداخلة في `options`
67+
// باستخدام `key` كمسار
6868
return key.split('.').reduce((o, i) => {
6969
if (o) return o[i]
7070
}, options)
@@ -73,31 +73,31 @@ export default {
7373
}
7474
```
7575

76-
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`، وستبحث في الإعدادات الموفرة وستعيد القيمة المترجمة.
7777

78-
The object containing the translated keys should be passed to the plugin during installation via additional parameters to `app.use()`:
78+
يجب إرسال كائن يحتوي على مفاتيح الترجمة إلى الملحق خلال التثبيت عبر وسائط إضافية لـلتابع `()app.use`:
7979

8080
```js
8181
import i18nPlugin from './plugins/i18n'
8282

8383
app.use(i18nPlugin, {
8484
greetings: {
85-
hello: 'Bonjour!'
85+
hello: 'مرحبا!'
8686
}
8787
})
8888
```
8989

90-
Now, our initial expression `$translate('greetings.hello')` will be replaced by `Bonjour!` at runtime.
90+
الآن، سيستبدل التعبير الأولي `translate('greetings.hello')$` بـ `مرحبا!` عند تشغيل التطبيق.
9191

92-
See also: [Augmenting Global Properties](/guide/typescript/options-api.html#augmenting-global-properties) <sup class="vt-badge ts" />
92+
اطلع أيضا على: [تعزيز الخاصيات العامة](/guide/typescript/options-api.html#augmenting-global-properties) <sup class="vt-badge ts" />
9393

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+
استخدم الخاصيات العامة في حالة الضرورة فقط، لأنه يمكن أن يصبح الأمر مربكًا بسرعة إذا استخدمت العديد من الخاصيات العامة المدخلة من قبل ملحقات مختلفة مستخدمة عبر التطبيق.
9696
:::
9797

98-
### Provide / Inject with Plugins {#provide-inject-with-plugins}
98+
### الحقن/التزويد عبر الملحقات {#provide-inject-with-plugins}
9999

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` لكي يتمكن من استخدام كائن الترجمات.
101101

102102
```js{10}
103103
// plugins/i18n.js
@@ -114,7 +114,7 @@ export default {
114114
}
115115
```
116116

117-
Plugin users will now be able to inject the plugin options into their components using the `i18n` key:
117+
سيتمكن مستخدمو الملحق الآن من إدخال خيارات الملحق في مكوناتهم باستخدام مفتاح `i18n`:
118118

119119
<div class="composition-api">
120120

0 commit comments

Comments
 (0)