@intlayer/docs 7.0.4-canary.0 → 7.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/blog/ar/intlayer_with_i18next.md +68 -106
  2. package/blog/ar/intlayer_with_next-i18next.md +84 -288
  3. package/blog/ar/intlayer_with_next-intl.md +58 -337
  4. package/blog/ar/intlayer_with_react-i18next.md +68 -290
  5. package/blog/ar/intlayer_with_react-intl.md +63 -266
  6. package/blog/de/intlayer_with_i18next.md +77 -97
  7. package/blog/de/intlayer_with_next-i18next.md +69 -296
  8. package/blog/de/intlayer_with_next-intl.md +59 -340
  9. package/blog/de/intlayer_with_react-i18next.md +68 -290
  10. package/blog/de/intlayer_with_react-intl.md +62 -264
  11. package/blog/en/intlayer_with_i18next.md +36 -1638
  12. package/blog/en/intlayer_with_next-i18next.md +22 -847
  13. package/blog/en/intlayer_with_next-intl.md +32 -1053
  14. package/blog/en/intlayer_with_react-i18next.md +38 -764
  15. package/blog/en/intlayer_with_react-intl.md +42 -1018
  16. package/blog/en-GB/intlayer_with_i18next.md +67 -103
  17. package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
  18. package/blog/en-GB/intlayer_with_next-intl.md +58 -337
  19. package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
  20. package/blog/en-GB/intlayer_with_react-intl.md +61 -264
  21. package/blog/es/intlayer_with_i18next.md +67 -103
  22. package/blog/es/intlayer_with_next-i18next.md +71 -296
  23. package/blog/es/intlayer_with_next-intl.md +57 -338
  24. package/blog/es/intlayer_with_react-i18next.md +68 -290
  25. package/blog/es/intlayer_with_react-intl.md +62 -265
  26. package/blog/fr/intlayer_with_i18next.md +66 -104
  27. package/blog/fr/intlayer_with_next-i18next.md +82 -285
  28. package/blog/fr/intlayer_with_next-intl.md +57 -338
  29. package/blog/fr/intlayer_with_react-i18next.md +67 -289
  30. package/blog/fr/intlayer_with_react-intl.md +61 -264
  31. package/blog/hi/intlayer_with_i18next.md +68 -104
  32. package/blog/hi/intlayer_with_next-i18next.md +74 -299
  33. package/blog/hi/intlayer_with_next-intl.md +57 -239
  34. package/blog/hi/intlayer_with_react-i18next.md +69 -291
  35. package/blog/hi/intlayer_with_react-intl.md +65 -268
  36. package/blog/id/intlayer_with_i18next.md +126 -0
  37. package/blog/id/intlayer_with_next-i18next.md +142 -0
  38. package/blog/id/intlayer_with_next-intl.md +113 -0
  39. package/blog/id/intlayer_with_react-i18next.md +124 -0
  40. package/blog/id/intlayer_with_react-intl.md +122 -0
  41. package/blog/it/intlayer_with_i18next.md +67 -103
  42. package/blog/it/intlayer_with_next-i18next.md +71 -296
  43. package/blog/it/intlayer_with_next-intl.md +57 -338
  44. package/blog/it/intlayer_with_react-i18next.md +68 -290
  45. package/blog/it/intlayer_with_react-intl.md +62 -265
  46. package/blog/ja/intlayer_with_i18next.md +68 -103
  47. package/blog/ja/intlayer_with_next-i18next.md +85 -283
  48. package/blog/ja/intlayer_with_next-intl.md +58 -336
  49. package/blog/ja/intlayer_with_react-i18next.md +68 -290
  50. package/blog/ja/intlayer_with_react-intl.md +62 -264
  51. package/blog/ko/intlayer_with_i18next.md +80 -96
  52. package/blog/ko/intlayer_with_next-i18next.md +85 -287
  53. package/blog/ko/intlayer_with_next-intl.md +68 -327
  54. package/blog/ko/intlayer_with_react-i18next.md +68 -290
  55. package/blog/ko/intlayer_with_react-intl.md +64 -266
  56. package/blog/pl/intlayer_with_i18next.md +126 -0
  57. package/blog/pl/intlayer_with_next-i18next.md +142 -0
  58. package/blog/pl/intlayer_with_next-intl.md +111 -0
  59. package/blog/pl/intlayer_with_react-i18next.md +124 -0
  60. package/blog/pl/intlayer_with_react-intl.md +122 -0
  61. package/blog/pt/intlayer_with_i18next.md +67 -103
  62. package/blog/pt/intlayer_with_next-i18next.md +72 -293
  63. package/blog/pt/intlayer_with_next-intl.md +57 -256
  64. package/blog/pt/intlayer_with_react-i18next.md +104 -78
  65. package/blog/pt/intlayer_with_react-intl.md +62 -266
  66. package/blog/ru/intlayer_with_i18next.md +66 -104
  67. package/blog/ru/intlayer_with_next-i18next.md +71 -296
  68. package/blog/ru/intlayer_with_next-intl.md +58 -337
  69. package/blog/ru/intlayer_with_react-i18next.md +68 -290
  70. package/blog/ru/intlayer_with_react-intl.md +62 -265
  71. package/blog/tr/intlayer_with_i18next.md +71 -107
  72. package/blog/tr/intlayer_with_next-i18next.md +72 -297
  73. package/blog/tr/intlayer_with_next-intl.md +58 -339
  74. package/blog/tr/intlayer_with_react-i18next.md +69 -291
  75. package/blog/tr/intlayer_with_react-intl.md +63 -285
  76. package/blog/vi/intlayer_with_i18next.md +126 -0
  77. package/blog/vi/intlayer_with_next-i18next.md +142 -0
  78. package/blog/vi/intlayer_with_next-intl.md +111 -0
  79. package/blog/vi/intlayer_with_react-i18next.md +124 -0
  80. package/blog/vi/intlayer_with_react-intl.md +122 -0
  81. package/blog/zh/intlayer_with_i18next.md +67 -102
  82. package/blog/zh/intlayer_with_next-i18next.md +72 -296
  83. package/blog/zh/intlayer_with_next-intl.md +58 -336
  84. package/blog/zh/intlayer_with_react-i18next.md +68 -290
  85. package/blog/zh/intlayer_with_react-intl.md +63 -106
  86. package/docs/ar/plugins/sync-json.md +244 -0
  87. package/docs/de/plugins/sync-json.md +244 -0
  88. package/docs/en/intlayer_cli.md +25 -0
  89. package/docs/en/intlayer_with_nextjs_14.md +2 -0
  90. package/docs/en/intlayer_with_nextjs_15.md +2 -0
  91. package/docs/en/intlayer_with_nextjs_16.md +2 -0
  92. package/docs/en/plugins/sync-json.md +1 -1
  93. package/docs/en-GB/plugins/sync-json.md +244 -0
  94. package/docs/es/plugins/sync-json.md +244 -0
  95. package/docs/fr/plugins/sync-json.md +244 -0
  96. package/docs/hi/plugins/sync-json.md +244 -0
  97. package/docs/id/plugins/sync-json.md +244 -0
  98. package/docs/it/plugins/sync-json.md +244 -0
  99. package/docs/ja/plugins/sync-json.md +244 -0
  100. package/docs/ko/plugins/sync-json.md +244 -0
  101. package/docs/pl/plugins/sync-json.md +244 -0
  102. package/docs/pt/plugins/sync-json.md +244 -0
  103. package/docs/ru/plugins/sync-json.md +244 -0
  104. package/docs/tr/plugins/sync-json.md +245 -0
  105. package/docs/vi/plugins/sync-json.md +244 -0
  106. package/docs/zh/plugins/sync-json.md +244 -0
  107. package/package.json +14 -14
@@ -1,392 +1,113 @@
1
1
  ---
2
2
  createdAt: 2025-01-02
3
- updatedAt: 2025-06-29
4
- title: Intlayer وnext-intl
5
- description: قم بدمج Intlayer مع next-intl للتدويل (i18n) لتطبيق React
6
- keywords:
7
- - next-intl
8
- - Intlayer
9
- - التدويل
10
- - التوثيق
11
- - Next.js
12
- - JavaScript
13
- - React
3
+ updatedAt: 2025-10-29
4
+ title: كيفية أتمتة ترجمات JSON الخاصة بـ next-intl باستخدام Intlayer
5
+ description: أتمتة ترجمات JSON الخاصة بك باستخدام Intlayer و next-intl لتعزيز التدويل في تطبيقات Next.js.
14
6
  slugs:
15
7
  - blog
16
8
  - intlayer-with-next-intl
9
+ history:
10
+ - version: 7.0.0
11
+ date: 2025-10-29
12
+ changes: التغيير إلى مكون syncJSON
17
13
  ---
18
14
 
19
- # Next.js Internationalization (i18n) with next-intl و Intlayer
15
+ # كيفية أتمتة ترجمات JSON الخاصة بـ next-intl باستخدام Intlayer
20
16
 
21
- كلا من next-intl و Intlayer هما إطاران مفتوحا المصدر للتعريب (i18n) مصممان لتطبيقات Next.js. يتم استخدامهما بشكل واسع لإدارة الترجمات، والمحلية، وتبديل اللغات في مشاريع البرمجيات.
17
+ ## ما هو Intlayer؟
22
18
 
23
- يتشاركان ثلاث مفاهيم رئيسية:
19
+ **Intlayer** هو مكتبة تدويل مبتكرة ومفتوحة المصدر مصممة لمعالجة أوجه القصور في حلول i18n التقليدية. يقدم نهجًا حديثًا لإدارة المحتوى في تطبيقات Next.js.
24
20
 
25
- 1. **إعلان المحتوى**: الطريقة لتحديد المحتوى القابل للترجمة في تطبيقك.
26
- - يُسمى `ملف إعلان المحتوى` في Intlayer، والذي يمكن أن يكون ملف JSON أو JS أو TS يقوم بتصدير البيانات المنظمة. راجع [وثائق Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ar/concept/content.md) لمزيد من المعلومات.
27
- - يُسمى `الرسائل` أو `رسائل اللغة` في next-intl، عادةً في ملفات JSON. راجع [وثائق next-intl](https://github.com/amannn/next-intl) لمزيد من المعلومات.
21
+ راجع مقارنة ملموسة مع next-intl في منشور المدونة الخاص بنا [next-i18next مقابل next-intl مقابل Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/ar/next-i18next_vs_next-intl_vs_intlayer.md).
28
22
 
29
- 2. **الأدوات**: أدوات لبناء وتفسير إعلانات المحتوى في التطبيق، مثل `useIntlayer()` أو `useLocale()` لـ Intlayer، و `useTranslations()` لـ next-intl.
23
+ ## لماذا الجمع بين Intlayer و next-intl؟
30
24
 
31
- 3. **الإضافات والبرمجيات الوسيطة**: ميزات لإدارة إعادة توجيه عنوان URL، وتحسين التجميع، وأكثر, على سبيل المثال، `intlayerMiddleware` لـ Intlayer أو [`createMiddleware`](https://github.com/amannn/next-intl) لـ next-intl.
25
+ بينما يوفر Intlayer حلاً ممتازًا مستقلاً للتدويل (راجع دليل التكامل مع Next.js الخاص بنا [Next.js integration guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ar/intlayer_with_nextjs_16.md) قد ترغب في دمجه مع next-intl لأسباب عدة:
32
26
 
33
- ## Intlayer مقابل next-intl: الاختلافات الرئيسية
27
+ 1. **قاعدة الشيفرة الحالية**: لديك تنفيذ قائم لـ next-intl وترغب في الترحيل التدريجي إلى تجربة المطور المحسنة التي يقدمها Intlayer.
28
+ 2. **متطلبات قديمة**: يتطلب مشروعك التوافق مع الإضافات أو سير العمل الحالي لـ next-intl.
29
+ 3. **ألفة الفريق**: فريقك مرتاح لاستخدام next-intl ولكنه يرغب في إدارة محتوى أفضل.
34
30
 
35
- لتحليل أعمق حول كيفية مقارنة Intlayer بمكتبات i18n الأخرى لـ Next.js (مثل next-intl تحقق من [منشور المدونة next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/ar/i18next_vs_next-intl_vs_intlayer.md).
31
+ **لهذا السبب، يمكن تنفيذ Intlayer كمحول لـ next-intl للمساعدة في أتمتة ترجمات JSON الخاصة بك في واجهة الأوامر أو خطوط أنابيب CI/CD، واختبار ترجماتك، والمزيد.**
36
32
 
37
- ## كيفية إنشاء رسائل next-intl مع Intlayer
33
+ يوضح هذا الدليل كيفية الاستفادة من نظام إعلان المحتوى المتفوق في Intlayer مع الحفاظ على التوافق مع next-intl.
38
34
 
39
- ### لماذا تستخدم Intlayer مع next-intl؟
35
+ ## جدول المحتويات
40
36
 
41
- تقدم ملفات إعلان المحتوى في Intlayer بشكل عام تجربة أفضل للمطورين. إنها أكثر مرونة وقابلة للصيانة بسبب ميزتين رئيسيتين:
37
+ <TOC/>
42
38
 
43
- 1. **مكان مرن**: يمكنك وضع ملف إعلان المحتوى في Intlayer في أي مكان في شجرة ملفات تطبيقك. يجعل ذلك من السهل إعادة تسمية أو حذف المكونات دون ترك ملفات رسائل غير مستعملة أو معلقة.
39
+ ## دليل خطوة بخطوة لإعداد Intlayer مع next-intl
44
40
 
45
- هياكل الملفات النموذجية:
41
+ ### الخطوة 1: تثبيت التبعيات
46
42
 
47
- ```bash codeFormat="typescript"
48
- .
49
- └── src
50
- └── components
51
- └── MyComponent
52
- ├── index.content.ts # ملف إعلان المحتوى
53
- └── index.tsx
54
- ```
55
-
56
- ```bash codeFormat="esm"
57
- .
58
- └── src
59
- └── components
60
- └── MyComponent
61
- ├── index.content.mjs # ملف إعلان المحتوى
62
- └── index.mjx
63
- ```
64
-
65
- ```bash codeFormat="cjs"
66
- .
67
- └── src
68
- └── components
69
- └── MyComponent
70
- ├── index.content.cjs # ملف إعلان المحتوى
71
- └── index.cjx
72
- ```
73
-
74
- ```bash codeFormat="json"
75
- .
76
- └── src
77
- └── components
78
- └── MyComponent
79
- ├── index.content.json # ملف إعلان المحتوى
80
- └── index.jsx
81
- ```
82
-
83
- 2. **ترجمات مركزة**: تُخزن Intlayer جميع الترجمات في إعلان محتوى واحد، مما يضمن عدم فقدان أي ترجمة. في مشاريع TypeScript، تُعلم الترجمات المفقودة تلقائياً كأخطاء نوع، مما يوفر تغذية راجعة فورية للمطورين.
84
-
85
- ### التثبيت
86
-
87
- لاستخدام Intlayer و next-intl معًا، قم بتثبيت المكتبتين:
43
+ قم بتثبيت الحزم اللازمة:
88
44
 
89
45
  ```bash packageManager="npm"
90
- npm install intlayer next-intl
46
+ npm install intlayer @intlayer/sync-json-plugin
91
47
  ```
92
48
 
93
- ```bash packageManager="yarn"
94
- yarn add intlayer next-intl
49
+ ```bash packageManager="pnpm"
50
+ pnpm add intlayer @intlayer/sync-json-plugin
95
51
  ```
96
52
 
97
- ```bash packageManager="pnpm"
98
- pnpm add intlayer next-intl
53
+ ```bash packageManager="yarn"
54
+ yarn add intlayer @intlayer/sync-json-plugin
99
55
  ```
100
56
 
101
- ### تكوين Intlayer لتصدير رسائل next-intl
57
+ **وصف الحزم:**
102
58
 
103
- > **ملاحظة:** يمكن أن يؤدي تصدير الرسائل من Intlayer لـ next-intl إلى إدخال اختلافات طفيفة في الهيكل. إذا كان ذلك ممكنًا، احتفظ بتدفق يعمل بIntlayer فقط أو next-intl فقط لتبسيط التكامل. إذا كنت بحاجة إلى إنشاء رسائل next-intl من Intlayer، اتبع الخطوات أدناه.
59
+ - **intlayer**: المكتبة الأساسية لإدارة التدويل، إعلان المحتوى، والبناء
60
+ - **@intlayer/sync-json-plugin**: إضافة لتصدير إعلانات محتوى Intlayer إلى صيغة JSON متوافقة مع next-intl
104
61
 
105
- قم بإنشاء أو تحديث ملف `intlayer.config.ts` (أو `.mjs` / `.cjs`) في جذر مشروعك:
62
+ ### الخطوة 2: تنفيذ إضافة Intlayer لتغليف JSON
106
63
 
107
- ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
108
- import { Locales, type IntlayerConfig } from "intlayer";
64
+ قم بإنشاء ملف تكوين Intlayer لتعريف اللغات المدعومة لديك:
109
65
 
110
- const config: IntlayerConfig = {
111
- internationalization: {
112
- locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
113
- defaultLocale: Locales.ENGLISH,
114
- },
115
- content: {
116
- dictionaryOutput: ["next-intl"], // استخدم ناتج next-intl
117
- nextIntlMessagesDir: "./intl/messages", // حيث يتم حفظ رسائل next-intl
118
- },
119
- };
120
-
121
- export default config;
122
- ```
123
-
124
- ```javascript fileName="intlayer.config.mjs" codeFormat="esm"
125
- import { Locales } from "intlayer";
126
-
127
- /** @type {import('intlayer').IntlayerConfig} */
128
- const config = {
129
- internationalization: {
130
- locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
131
- defaultLocale: Locales.ENGLISH,
132
- },
133
- content: {
134
- dictionaryOutput: ["react-intl"],
135
- nextIntlMessagesDir: "./intl/messages",
136
- },
137
- };
66
+ **إذا كنت تريد أيضًا تصدير قواميس JSON لـ next-intl**، أضف إضافة `syncJSON`:
138
67
 
139
- export default config;
140
- ```
141
-
142
- ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
143
- const { Locales } = require("intlayer");
68
+ ```typescript fileName="intlayer.config.ts"
69
+ import { Locales, type IntlayerConfig } from "intlayer";
70
+ import { syncJSON } from "@intlayer/sync-json-plugin";
144
71
 
145
- /** @type {import('intlayer').IntlayerConfig} */
146
- const config = {
72
+ const config: IntlayerConfig = {
147
73
  internationalization: {
148
74
  locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
149
75
  defaultLocale: Locales.ENGLISH,
150
76
  },
151
- content: {
152
- dictionaryOutput: ["next-intl"],
153
- nextIntlMessagesDir: "./intl/messages",
154
- },
155
- };
156
-
157
- module.exports = config;
158
- ```
159
-
160
- ### إعلان المحتوى
161
-
162
- فيما يلي أمثلة على ملفات إعلان المحتوى بعدة تنسيقات. ستقوم Intlayer بتجميع هذه الملفات في ملفات رسائل يمكن أن تستهلكها next-intl.
163
-
164
- ```typescript fileName="**/*.content.ts" contentDeclarationFormat="typescript"
165
- import { t, type Dictionary } from "intlayer";
166
-
167
- const content = {
168
- key: "my-component",
169
- content: {
170
- helloWorld: t({
171
- en: "Hello World",
172
- es: "Hola Mundo",
173
- fr: "Bonjour le monde",
77
+ plugins: [
78
+ syncJSON({
79
+ source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
174
80
  }),
175
- },
176
- } satisfies Dictionary;
177
-
178
- export default content;
179
- ```
180
-
181
- ```javascript fileName="**/*.content.mjs" contentDeclarationFormat="esm"
182
- import { t } from "intlayer";
183
-
184
- /** @type {import('intlayer').Dictionary} */
185
- const content = {
186
- key: "my-component",
187
- content: {
188
- helloWorld: t({
189
- en: "Hello World",
190
- es: "Hola Mundo",
191
- fr: "Bonjour le monde",
192
- }),
193
- },
81
+ ],
194
82
  };
195
83
 
196
- export default content;
197
- ```
198
-
199
- ```javascript fileName="**/*.content.cjs" contentDeclarationFormat="commonjs"
200
- const { t } = require("intlayer");
201
-
202
- module.exports = {
203
- key: "my-component",
204
- content: {
205
- helloWorld: t({
206
- en: "Hello World",
207
- es: "Hola Mundo",
208
- fr: "Bonjour le monde",
209
- }),
210
- },
211
- };
84
+ export default config;
212
85
  ```
213
86
 
214
- ```json fileName="**/*.content.json" contentDeclarationFormat="json"
215
- {
216
- "$schema": "https://intlayer.org/schema.json",
217
- "key": "my-component",
218
- "content": {
219
- "helloWorld": {
220
- "nodeType": "translation",
221
- "translation": {
222
- "en": "Hello World",
223
- "fr": "Bonjour le monde",
224
- "es": "Hola Mundo"
225
- }
226
- }
227
- }
228
- }
229
- ```
87
+ ستقوم إضافة `syncJSON` تلقائيًا بتغليف JSON. ستقرأ وتكتب ملفات JSON دون تغيير هيكل المحتوى.
230
88
 
231
- ### بناء رسائل next-intl
89
+ إذا كنت تريد جعل JSON يتعايش مع ملفات إعلان المحتوى الخاصة بـ intlayer (`.content` files)، فسيعمل Intlayer بهذه الطريقة:
232
90
 
233
- لبناء ملفات الرسائل لـ next-intl، قم بتشغيل:
91
+ 1. تحميل كل من ملفات JSON وملفات إعلان المحتوى وتحويلها إلى قاموس intlayer.
92
+ 2. إذا كانت هناك تعارضات بين ملفات JSON وملفات إعلان المحتوى، فسيقوم Intlayer بدمج جميع القواميس. وذلك يعتمد على أولوية الإضافات، وأولوية ملف إعلان المحتوى (كلها قابلة للتكوين).
234
93
 
235
- ```bash packageManager="npm"
236
- npx intlayer dictionaries build
237
- ```
94
+ إذا تم إجراء تغييرات باستخدام واجهة الأوامر CLI لترجمة JSON، أو باستخدام نظام إدارة المحتوى CMS، فسيقوم Intlayer بتحديث ملف JSON بالترجمات الجديدة.
238
95
 
239
- ```bash packageManager="yarn"
240
- yarn intlayer build
241
- ```
96
+ ## إعدادات Git
242
97
 
243
- ```bash packageManager="pnpm"
244
- pnpm intlayer build
245
- ```
98
+ يوصى بتجاهل ملفات Intlayer التي يتم إنشاؤها تلقائيًا:
246
99
 
247
- سيقوم هذا بإنشاء الموارد في دليل `./intl/messages` (كما هو مُكون في `intlayer.config.*`). الناتج المتوقع:
248
-
249
- ```bash
250
- .
251
- └── intl
252
- └── messages
253
- └── ar
254
- └── my-content.json
255
- └── fr
256
- └── my-content.json
257
- └── es
258
- └── my-content.json
100
+ ```plaintext fileName=".gitignore"
101
+ # تجاهل الملفات التي تم إنشاؤها بواسطة Intlayer
102
+ .intlayer
259
103
  ```
260
104
 
261
- تتضمن كل ملف رسائل مجمعة من جميع إعلانات محتوى Intlayer. عادةً ما تتطابق المفاتيح في المستوى الأعلى مع حقول `content.key` الخاصة بك.
262
-
263
- ### استخدام next-intl في تطبيق Next.js الخاص بك
264
-
265
- > لمزيد من التفاصيل، راجع [وثائق استخدام next-intl الرسمية](https://github.com/amannn/next-intl#readme).
266
-
267
- 1. **إنشاء برمجية وسيطة (اختياري):**
268
- إذا كنت ترغب في إدارة الكشف التلقائي عن اللغة أو إعادة التوجيه، استخدم [createMiddleware](https://github.com/amannn/next-intl#createMiddleware) لـ next-intl.
269
-
270
- ```typescript fileName="middleware.ts"
271
- import createMiddleware from "next-intl/middleware";
272
- import { NextResponse } from "next/server";
273
-
274
- export default createMiddleware({
275
- locales: ["en", "fr", "es"],
276
- defaultLocale: "en",
277
- });
278
-
279
- export const config = {
280
- matcher: ["/((?!api|_next|.*\\..*).*)"],
281
- };
282
- ```
283
-
284
- 2. **إنشاء `layout.tsx` أو `_app.tsx` لتحميل الرسائل:**
285
- إذا كنت تستخدم App Router (Next.js 13+)، أنشئ تخطيطًا:
286
-
287
- ```typescript fileName="app/[locale]/layout.tsx"
288
- import { NextIntlClientProvider } from 'next-intl';
289
- import { notFound } from 'next/navigation';
290
- import React, { ReactNode } from 'react';
291
-
292
-
293
- export default async function RootLayout({
294
- children,
295
- params
296
- }: {
297
- children: ReactNode;
298
- params: { locale: string };
299
- }) {
300
- let messages;
301
- try {
302
- messages = (await import(`../../intl/messages/${params.locale}.json`)).default;
303
- } catch (error) {
304
- notFound();
305
- }
306
-
307
- return (
308
- <html lang={params.locale}>
309
- <body>
310
- <NextIntlClientProvider locale={params.locale} messages={messages}>
311
- {children}
312
- </NextIntlClientProvider>
313
- </body>
314
- </html>
315
- );
316
- }
317
- ```
318
-
319
- إذا كنت تستخدم Pages Router (Next.js 12 أو أقل)، قم بتحميل الرسائل في `_app.tsx`:
320
-
321
- ```typescript fileName="pages/_app.tsx"
322
- import type { AppProps } from 'next/app';
323
- import { NextIntlProvider } from 'next-intl';
324
-
325
- function MyApp({ Component, pageProps }: AppProps) {
326
- return (
327
- <NextIntlProvider locale={pageProps.locale} messages={pageProps.messages}>
328
- <Component {...pageProps} />
329
- </NextIntlProvider>
330
- );
331
- }
332
-
333
- export default MyApp;
334
- ```
335
-
336
- 3. **جلب الرسائل من جانب الخادم (مثال Pages Router):**
337
-
338
- ```typescript fileName="pages/index.tsx"
339
- import { GetServerSideProps } from "next";
340
- import HomePage from "../components/HomePage";
341
-
342
- export default HomePage;
343
-
344
- export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
345
- const messages = (await import(`../intl/messages/${locale}.json`)).default;
346
-
347
- return {
348
- props: {
349
- locale,
350
- messages,
351
- },
352
- };
353
- };
354
- ```
355
-
356
- ### استخدام المحتوى في مكونات Next.js
357
-
358
- بمجرد تحميل الرسائل في next-intl، يمكنك استخدامها في مكوناتك عبر `useTranslations()`:
359
-
360
- ```typescript fileName="src/components/MyComponent/index.tsx" codeFormat="typescript"
361
- import type { FC } from "react";
362
- import { useTranslations } from 'next-intl';
363
-
364
- const MyComponent: FC = () => {
365
- const t = useTranslations('my-component');
366
- // 'my-component' تتوافق مع مفتاح المحتوى في Intlayer
367
-
368
- return (
369
- <div>
370
- <h1>{t('helloWorld')}</h1>
371
- </div>
372
- );
373
- };
374
-
375
- export default MyComponent;
376
- ```
105
+ يمكن إعادة إنشاء هذه الملفات أثناء عملية البناء الخاصة بك ولا تحتاج إلى الالتزام بها في نظام التحكم في الإصدارات.
377
106
 
378
- ```jsx fileName="src/components/MyComponent/index.jsx" codeFormat="esm"
379
- import { useTranslations } from "next-intl";
107
+ ### إضافة VS Code
380
108
 
381
- export default function MyComponent() {
382
- const t = useTranslations("my-component");
109
+ لتحسين تجربة المطور، قم بتثبيت **إضافة Intlayer الرسمية لـ VS Code**:
383
110
 
384
- return (
385
- <div>
386
- <h1>{t("helloWorld")}</h1>
387
- </div>
388
- );
389
- }
390
- ```
111
+ [التثبيت من سوق VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
391
112
 
392
- **هذا كل شيء!** كلما قمت بتحديث أو إضافة ملفات إعلان محتوى جديدة من Intlayer، أعد تشغيل أمر `intlayer build` لإعادة توليد رسائل JSON الخاصة بك لـ next-intl. ستقوم next-intl بالتقاط المحتوى المحدث تلقائياً.
113
+ [التثبيت من سوق VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)