@intlayer/docs 6.1.5 → 6.1.6-canary.0
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.
- package/blog/ar/next-i18next_vs_next-intl_vs_intlayer.md +404 -173
- package/blog/de/next-i18next_vs_next-intl_vs_intlayer.md +262 -113
- package/blog/en/intlayer_with_next-i18next.mdx +431 -0
- package/blog/en/intlayer_with_next-intl.mdx +335 -0
- package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +403 -140
- package/blog/en-GB/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
- package/blog/es/next-i18next_vs_next-intl_vs_intlayer.md +185 -71
- package/blog/fr/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
- package/blog/it/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
- package/blog/ja/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
- package/blog/ko/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
- package/blog/pt/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
- package/blog/ru/next-i18next_vs_next-intl_vs_intlayer.md +36 -28
- package/blog/tr/next-i18next_vs_next-intl_vs_intlayer.md +2 -0
- package/blog/zh/next-i18next_vs_next-intl_vs_intlayer.md +38 -28
- package/dist/cjs/generated/docs.entry.cjs +16 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +16 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/component_i18n.md +186 -0
- package/docs/ar/vs_code_extension.md +48 -109
- package/docs/de/component_i18n.md +186 -0
- package/docs/de/vs_code_extension.md +46 -107
- package/docs/en/component_i18n.md +186 -0
- package/docs/en/intlayer_with_nextjs_14.md +18 -1
- package/docs/en/intlayer_with_nextjs_15.md +18 -1
- package/docs/en/vs_code_extension.md +24 -114
- package/docs/en-GB/component_i18n.md +186 -0
- package/docs/en-GB/vs_code_extension.md +42 -103
- package/docs/es/component_i18n.md +182 -0
- package/docs/es/vs_code_extension.md +53 -114
- package/docs/fr/component_i18n.md +186 -0
- package/docs/fr/vs_code_extension.md +50 -111
- package/docs/hi/component_i18n.md +186 -0
- package/docs/hi/vs_code_extension.md +49 -110
- package/docs/it/component_i18n.md +186 -0
- package/docs/it/vs_code_extension.md +50 -111
- package/docs/ja/component_i18n.md +186 -0
- package/docs/ja/vs_code_extension.md +50 -111
- package/docs/ko/component_i18n.md +186 -0
- package/docs/ko/vs_code_extension.md +48 -109
- package/docs/pt/component_i18n.md +186 -0
- package/docs/pt/vs_code_extension.md +46 -107
- package/docs/ru/component_i18n.md +186 -0
- package/docs/ru/vs_code_extension.md +48 -109
- package/docs/tr/component_i18n.md +186 -0
- package/docs/tr/vs_code_extension.md +54 -115
- package/docs/zh/component_i18n.md +186 -0
- package/docs/zh/vs_code_extension.md +51 -105
- package/package.json +11 -11
- package/src/generated/docs.entry.ts +16 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2024-03-07
|
|
3
|
+
updatedAt: 2025-09-30
|
|
4
|
+
title: جعل المكون متعدد اللغات (مكتبة i18n) في React و Next.js
|
|
5
|
+
description: تعلم كيفية إعلان واسترجاع المحتوى المحلي لبناء مكون React أو Next.js متعدد اللغات باستخدام Intlayer.
|
|
6
|
+
keywords:
|
|
7
|
+
- i18n
|
|
8
|
+
- component
|
|
9
|
+
- react
|
|
10
|
+
- multilingual
|
|
11
|
+
- next.js
|
|
12
|
+
- intlayer
|
|
13
|
+
slugs:
|
|
14
|
+
- doc
|
|
15
|
+
- component
|
|
16
|
+
- i18n
|
|
17
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
|
|
18
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# كيفية جعل المكون متعدد اللغات (i18n) باستخدام Intlayer
|
|
22
|
+
|
|
23
|
+
يوضح هذا الدليل الخطوات الأساسية لجعل مكون واجهة المستخدم متعدد اللغات في إعدادين شائعين:
|
|
24
|
+
|
|
25
|
+
- React (Vite/SPA)
|
|
26
|
+
- Next.js (App Router)
|
|
27
|
+
|
|
28
|
+
ستقوم أولاً بإعلان المحتوى الخاص بك، ثم استرجاعه في مكونك.
|
|
29
|
+
|
|
30
|
+
## 1) إعلان المحتوى الخاص بك (مشترك بين React و Next.js)
|
|
31
|
+
|
|
32
|
+
قم بإنشاء ملف إعلان المحتوى بالقرب من مكونك. هذا يحافظ على الترجمات قريبة من مكان استخدامها ويمكّن من الأمان النوعي.
|
|
33
|
+
|
|
34
|
+
```ts fileName="component.content.ts"
|
|
35
|
+
import { t, type Dictionary } from "intlayer";
|
|
36
|
+
|
|
37
|
+
const componentContent = {
|
|
38
|
+
key: "component-example",
|
|
39
|
+
content: {
|
|
40
|
+
title: t({
|
|
41
|
+
en: "Hello",
|
|
42
|
+
fr: "Bonjour",
|
|
43
|
+
es: "Hola",
|
|
44
|
+
}),
|
|
45
|
+
description: t({
|
|
46
|
+
en: "A multilingual React component",
|
|
47
|
+
fr: "Un composant React multilingue",
|
|
48
|
+
es: "Un componente React multilingüe",
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
} satisfies Dictionary;
|
|
52
|
+
|
|
53
|
+
export default componentContent;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
يدعم JSON أيضًا إذا كنت تفضل ملفات التكوين.
|
|
57
|
+
|
|
58
|
+
```json fileName="component.content.json"
|
|
59
|
+
{
|
|
60
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
61
|
+
"key": "component-example",
|
|
62
|
+
"content": {
|
|
63
|
+
"title": {
|
|
64
|
+
"nodeType": "translation",
|
|
65
|
+
"translation": { "en": "Hello", "fr": "Bonjour", "es": "Hola" }
|
|
66
|
+
},
|
|
67
|
+
"description": {
|
|
68
|
+
"nodeType": "translation",
|
|
69
|
+
"translation": {
|
|
70
|
+
"en": "A multilingual React component",
|
|
71
|
+
"fr": "Un composant React multilingue",
|
|
72
|
+
"es": "Un componente React multilingüe"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 2) استرجع محتواك
|
|
80
|
+
|
|
81
|
+
### الحالة أ — تطبيق React (Vite/SPA)
|
|
82
|
+
|
|
83
|
+
الطريقة الافتراضية: استخدم `useIntlayer` للاسترجاع بواسطة المفتاح. هذا يحافظ على مكونات خفيفة ومكتوبة بأنواع.
|
|
84
|
+
|
|
85
|
+
```tsx fileName="ComponentExample.tsx"
|
|
86
|
+
import { useIntlayer } from "react-intlayer";
|
|
87
|
+
|
|
88
|
+
export function ComponentExample() {
|
|
89
|
+
const content = useIntlayer("component-example");
|
|
90
|
+
return (
|
|
91
|
+
<div>
|
|
92
|
+
<h1>{content.title}</h1>
|
|
93
|
+
<p>{content.description}</p>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
التصيير على جانب الخادم أو خارج المزود: استخدم `react-intlayer/server` ومرر `locale` صريحًا عند الحاجة.
|
|
100
|
+
|
|
101
|
+
```tsx fileName="ServerRenderedExample.tsx"
|
|
102
|
+
import { useIntlayer } from "react-intlayer/server";
|
|
103
|
+
|
|
104
|
+
export function ServerRenderedExample({ locale }: { locale: string }) {
|
|
105
|
+
const content = useIntlayer("component-example", locale);
|
|
106
|
+
return (
|
|
107
|
+
<>
|
|
108
|
+
<h1>{content.title}</h1>
|
|
109
|
+
<p>{content.description}</p>
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
بديل: يمكن لـ `useDictionary` قراءة كائن معلن بالكامل إذا كنت تفضل تجميع البنية في موقع الاستدعاء.
|
|
116
|
+
|
|
117
|
+
```tsx fileName="ComponentWithDictionary.tsx"
|
|
118
|
+
import { useDictionary } from "react-intlayer";
|
|
119
|
+
import componentContent from "./component.content";
|
|
120
|
+
|
|
121
|
+
export function ComponentWithDictionary() {
|
|
122
|
+
const { title, description } = useDictionary(componentContent);
|
|
123
|
+
return (
|
|
124
|
+
<div>
|
|
125
|
+
<h1>{title}</h1>
|
|
126
|
+
<p>{description}</p>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### الحالة ب — Next.js (موجه التطبيق)
|
|
133
|
+
|
|
134
|
+
يفضل استخدام مكونات الخادم لأمان البيانات والأداء. استخدم `useIntlayer` من `next-intlayer/server` في ملفات الخادم، و`useIntlayer` من `next-intlayer` في مكونات العميل.
|
|
135
|
+
|
|
136
|
+
```tsx fileName="app/[locale]/example/ServerComponent.tsx"
|
|
137
|
+
import { useIntlayer } from "next-intlayer/server";
|
|
138
|
+
|
|
139
|
+
export default function ServerComponent() {
|
|
140
|
+
const content = useIntlayer("component-example");
|
|
141
|
+
return (
|
|
142
|
+
<>
|
|
143
|
+
<h1>{content.title}</h1>
|
|
144
|
+
<p>{content.description}</p>
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```tsx fileName="app/[locale]/example/ClientComponent.tsx"
|
|
151
|
+
"use client";
|
|
152
|
+
|
|
153
|
+
import { useIntlayer } from "next-intlayer";
|
|
154
|
+
|
|
155
|
+
export function ClientComponent() {
|
|
156
|
+
const content = useIntlayer("component-example");
|
|
157
|
+
return (
|
|
158
|
+
<div>
|
|
159
|
+
<h1>{content.title}</h1>
|
|
160
|
+
<p>{content.description}</p>
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
نصيحة: للحصول على بيانات وصفية للصفحة وتحسين محركات البحث، يمكنك أيضًا جلب المحتوى باستخدام `getIntlayer` وإنشاء روابط متعددة اللغات عبر `getMultilingualUrls`.
|
|
167
|
+
|
|
168
|
+
## لماذا نهج مكونات Intlayer هو الأفضل
|
|
169
|
+
|
|
170
|
+
- **التجميع**: تعيش إعلانات المحتوى بالقرب من المكونات، مما يقلل الانحراف ويحسن إعادة الاستخدام عبر أنظمة التصميم.
|
|
171
|
+
- **سلامة النوع**: المفاتيح والهياكل ذات أنواع قوية؛ تظهر الترجمات المفقودة أثناء وقت البناء بدلاً من وقت التشغيل.
|
|
172
|
+
- **الخادم أولاً**: يعمل بشكل أصلي في مكونات الخادم لأمان وأداء أفضل؛ تبقى الخطافات الخاصة بالعميل سهلة الاستخدام.
|
|
173
|
+
- **إزالة الشجرة (Tree-shaking)**: يتم تجميع المحتوى المستخدم فقط بواسطة المكون، مما يحافظ على صغر حجم الحمولة في التطبيقات الكبيرة.
|
|
174
|
+
- **تجربة المطور والأدوات**: تتضمن طبقة وسيطة مدمجة، ومساعدات تحسين محركات البحث، وترجمات اختيارية عبر المحرر المرئي/الذكاء الاصطناعي لتبسيط العمل اليومي.
|
|
175
|
+
|
|
176
|
+
راجع المقارنات والأنماط في الملخص الموجه لـ Next.js: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
|
|
177
|
+
|
|
178
|
+
## الأدلة والمراجع ذات الصلة
|
|
179
|
+
|
|
180
|
+
- إعداد React (Vite): https://intlayer.org/doc/environment/vite-and-react
|
|
181
|
+
- React Router v7: https://intlayer.org/doc/environment/vite-and-react/react-router-v7
|
|
182
|
+
- بداية TanStack: https://intlayer.org/doc/environment/vite-and-react/tanstack-start
|
|
183
|
+
- إعداد Next.js: https://intlayer.org/doc/environment/nextjs
|
|
184
|
+
- لماذا Intlayer مقابل next-intl مقابل next-i18next: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
|
|
185
|
+
|
|
186
|
+
تتضمن هذه الصفحات إعدادًا شاملاً، ومزودين، والتوجيه، ومساعدات تحسين محركات البحث.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-03-17
|
|
3
|
-
updatedAt: 2025-09-
|
|
3
|
+
updatedAt: 2025-09-30
|
|
4
4
|
title: ملحق VS Code الرسمي
|
|
5
|
-
description: تعلّم كيفية استخدام ملحق Intlayer في VS Code لتعزيز سير عمل التطوير الخاص بك. تنقل بسرعة بين المحتوى المحلي وأدر
|
|
5
|
+
description: تعلّم كيفية استخدام ملحق Intlayer في VS Code لتعزيز سير عمل التطوير الخاص بك. تنقل بسرعة بين المحتوى المحلي وأدر قواميسك بكفاءة.
|
|
6
6
|
keywords:
|
|
7
7
|
- ملحق VS Code
|
|
8
8
|
- Intlayer
|
|
@@ -23,161 +23,100 @@ slugs:
|
|
|
23
23
|
|
|
24
24
|
[**Intlayer**](https://marketplace.visualstudio.com/items?itemName=Intlayer.intlayer-vs-code-extension) هو الملحق الرسمي لـ Visual Studio Code الخاص بـ **Intlayer**، مصمم لتحسين تجربة المطور عند العمل مع المحتوى المحلي في مشاريعك.
|
|
25
25
|
|
|
26
|
-

|
|
26
|
+

|
|
27
27
|
|
|
28
28
|
رابط الملحق: [https://marketplace.visualstudio.com/items?itemName=Intlayer.intlayer-vs-code-extension](https://marketplace.visualstudio.com/items?itemName=Intlayer.intlayer-vs-code-extension)
|
|
29
29
|
|
|
30
30
|
## الميزات
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+

|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
**دعم متعدد اللغات** – يدعم المحتوى المحلي عبر لغات مختلفة.
|
|
37
|
-
**تكامل مع VS Code** – يندمج بسلاسة مع التنقل ولوحة الأوامر في VS Code.
|
|
34
|
+
- **التنقل الفوري** – القفز بسرعة إلى ملف المحتوى الصحيح عند النقر على مفتاح `useIntlayer`.
|
|
35
|
+
- **ملء القواميس** – ملء القواميس بالمحتوى من مشروعك.
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+

|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
- **الوصول السهل إلى أوامر Intlayer** – بناء، دفع، سحب، ملء، اختبار قواميس المحتوى بسهولة.
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
- **دفع القواميس** – رفع أحدث محتوى القاموس إلى مستودعك.
|
|
45
|
-
- **سحب القواميس** – مزامنة أحدث محتوى القاموس من مستودعك إلى بيئتك المحلية.
|
|
46
|
-
- **ملء القواميس** – تعبئة القواميس بالمحتوى من مشروعك.
|
|
47
|
-
- **اختبار القواميس** – تحديد الترجمات المفقودة أو غير المكتملة.
|
|
41
|
+

|
|
48
42
|
|
|
49
|
-
|
|
43
|
+
- **مولد إعلان المحتوى** – إنشاء ملفات محتوى القاموس بصيغ مختلفة (`.ts`, `.esm`, `.cjs`, `.json`).
|
|
50
44
|
|
|
51
|
-
|
|
45
|
+

|
|
52
46
|
|
|
53
|
-
|
|
47
|
+
- **اختبار القواميس** – اختبار القواميس للترجمات المفقودة.
|
|
54
48
|
|
|
55
|
-
|
|
49
|
+

|
|
56
50
|
|
|
57
|
-
|
|
58
|
-
const MyComponent = () => {
|
|
59
|
-
const { myTranslatedContent } = useIntlayer("my-component");
|
|
51
|
+
- **حافظ على تحديث قواميسك** – حافظ على تحديث قواميسك بأحدث المحتويات من مشروعك.
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
الملف المُولد بصيغة TypeScript:
|
|
66
|
-
|
|
67
|
-
```tsx fileName="src/components/MyComponent/index.content.ts"
|
|
68
|
-
import { t, type Dictionary } from "intlayer";
|
|
69
|
-
|
|
70
|
-
const componentContent = {
|
|
71
|
-
key: "my-component",
|
|
72
|
-
content: {
|
|
73
|
-
myTranslatedContent: t({
|
|
74
|
-
en: "Hello World",
|
|
75
|
-
es: "Hola Mundo",
|
|
76
|
-
fr: "Bonjour le monde",
|
|
77
|
-
}),
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export default componentContent;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
الصيغ المتاحة:
|
|
85
|
-
|
|
86
|
-
- **TypeScript (`.ts`)**
|
|
87
|
-
- **وحدة ES (`.esm`)**
|
|
88
|
-
- **CommonJS (`.cjs`)**
|
|
89
|
-
- **JSON (`.json`)**
|
|
90
|
-
|
|
91
|
-
### تبويب Intlayer (شريط النشاط)
|
|
53
|
+

|
|
92
54
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
- **بحث**: شريط بحث مباشر لتصفية القواميس ومحتواها بسرعة. الكتابة تحدث النتائج فورًا.
|
|
96
|
-
- **القواميس**: عرض شجري لبيئاتك/مشاريعك، مفاتيح القواميس، والملفات التي تساهم بالإدخالات. يمكنك:
|
|
97
|
-
- النقر على ملف لفتحه في المحرر.
|
|
98
|
-
- استخدام شريط الأدوات لتنفيذ الأوامر: بناء، سحب، دفع، تعبئة، تحديث، اختبار، وإنشاء ملف قاموس.
|
|
99
|
-
- استخدام قائمة السياق لإجراءات محددة على العنصر:
|
|
100
|
-
- على قاموس: سحب أو دفع
|
|
101
|
-
- على ملف: تعبئة القاموس
|
|
102
|
-
- عند تبديل المحررات، سيكشف العرض الشجري عن الملف المطابق إذا كان ينتمي إلى قاموس.
|
|
103
|
-
|
|
104
|
-
## التثبيت
|
|
105
|
-
|
|
106
|
-
يمكنك تثبيت **Intlayer** مباشرة من سوق إضافات VS Code:
|
|
107
|
-
|
|
108
|
-
1. افتح **VS Code**.
|
|
109
|
-
2. اذهب إلى **سوق الإضافات**.
|
|
110
|
-
3. ابحث عن **"Intlayer"**.
|
|
111
|
-
4. انقر على **تثبيت**.
|
|
55
|
+
- **علامة تبويب Intlayer (شريط النشاط)** – تصفح وابحث في القواميس من علامة تبويب جانبية مخصصة مع شريط أدوات وإجراءات سياقية (بناء، سحب، دفع، ملء، تحديث، اختبار، إنشاء ملف).
|
|
112
56
|
|
|
113
57
|
## الاستخدام
|
|
114
58
|
|
|
115
59
|
### التنقل السريع
|
|
116
60
|
|
|
117
61
|
1. افتح مشروعًا يستخدم **react-intlayer**.
|
|
118
|
-
2. حدد
|
|
62
|
+
2. حدد موقع استدعاء `useIntlayer()`، مثل:
|
|
119
63
|
|
|
120
64
|
```tsx
|
|
121
65
|
const content = useIntlayer("app");
|
|
122
66
|
```
|
|
123
67
|
|
|
124
68
|
3. **انقر مع الضغط على الأمر** (`⌘+Click` على macOS) أو **Ctrl+Click** (على Windows/Linux) على المفتاح (مثل `"app"`).
|
|
125
|
-
4.
|
|
126
|
-
|
|
127
|
-
### إدارة قواميس المحتوى
|
|
69
|
+
4. سيقوم VS Code بفتح ملف القاموس المقابل تلقائيًا، مثل `src/app.content.ts`.
|
|
128
70
|
|
|
129
|
-
### تبويب Intlayer (شريط النشاط)
|
|
71
|
+
### علامة تبويب Intlayer (شريط النشاط)
|
|
130
72
|
|
|
131
|
-
استخدم التبويب
|
|
73
|
+
استخدم علامة التبويب الجانبية لتصفح وإدارة القواميس:
|
|
132
74
|
|
|
133
75
|
- افتح أيقونة Intlayer في شريط النشاط.
|
|
134
76
|
- في **البحث**، اكتب لتصفية القواميس والإدخالات في الوقت الحقيقي.
|
|
135
|
-
- في **القواميس**، تصفح البيئات والقواميس والملفات. استخدم شريط الأدوات للبناء، السحب، الدفع، الملء، التحديث، الاختبار، وإنشاء ملف
|
|
77
|
+
- في **القواميس**، تصفح البيئات والقواميس والملفات. استخدم شريط الأدوات للبناء، السحب، الدفع، الملء، التحديث، الاختبار، وإنشاء ملف قاموس. انقر بزر الماوس الأيمن للحصول على إجراءات سياقية (سحب/دفع على القواميس، ملء على الملفات). يتم الكشف تلقائيًا عن ملف المحرر الحالي في الشجرة عند الاقتضاء.
|
|
136
78
|
|
|
137
|
-
|
|
79
|
+
### الوصول إلى الأوامر
|
|
138
80
|
|
|
139
|
-
|
|
81
|
+
يمكنك الوصول إلى الأوامر من **لوحة الأوامر**.
|
|
140
82
|
|
|
141
83
|
```sh
|
|
142
84
|
Cmd + Shift + P (macOS) / Ctrl + Shift + P (Windows/Linux)
|
|
143
85
|
```
|
|
144
86
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
1. افتح **لوحة الأوامر**.
|
|
152
|
-
2. ابحث عن **Push Dictionaries**.
|
|
153
|
-
3. اختر القواميس التي تريد دفعها وقم بالتأكيد.
|
|
154
|
-
|
|
155
|
-
#### سحب القواميس
|
|
87
|
+
- **بناء القواميس**
|
|
88
|
+
- **دفع القواميس**
|
|
89
|
+
- **سحب القواميس**
|
|
90
|
+
- **ملء القواميس**
|
|
91
|
+
- **اختبار القواميس**
|
|
92
|
+
- **إنشاء ملف قاموس**
|
|
156
93
|
|
|
157
|
-
|
|
94
|
+
### تحميل متغيرات البيئة
|
|
158
95
|
|
|
159
|
-
|
|
160
|
-
2. ابحث عن **Pull Dictionaries**.
|
|
161
|
-
3. اختر القواميس التي تريد سحبها.
|
|
96
|
+
توصي Intlayer بتخزين مفاتيح API الخاصة بالذكاء الاصطناعي، بالإضافة إلى معرف العميل وسرية Intlayer في متغيرات البيئة.
|
|
162
97
|
|
|
163
|
-
|
|
98
|
+
يمكن للإضافة تحميل متغيرات البيئة من مساحة العمل الخاصة بك لتشغيل أوامر Intlayer بالسياق الصحيح.
|
|
164
99
|
|
|
165
|
-
|
|
100
|
+
- **ترتيب التحميل (حسب الأولوية)**: `.env.<env>.local` → `.env.<env>` → `.env.local` → `.env`
|
|
101
|
+
- **غير مدمر**: لا يتم تجاوز قيم `process.env` الموجودة.
|
|
102
|
+
- **النطاق**: يتم حل الملفات من الدليل الأساسي المُكوَّن (افتراضيًا جذر مساحة العمل).
|
|
166
103
|
|
|
167
|
-
|
|
168
|
-
2. ابحث عن **Fill Dictionaries**.
|
|
169
|
-
3. نفذ الأمر لملء القواميس.
|
|
104
|
+
#### اختيار البيئة النشطة
|
|
170
105
|
|
|
171
|
-
|
|
106
|
+
- **لوحة الأوامر**: افتح اللوحة وقم بتشغيل الأمر `Intlayer: Select Environment`، ثم اختر البيئة (مثلًا، `development`، `staging`، `production`). ستحاول الإضافة تحميل أول ملف متاح في قائمة الأولويات أعلاه وستعرض إشعارًا مثل "تم تحميل البيئة من .env.<env>.local".
|
|
107
|
+
- **الإعدادات**: اذهب إلى `Settings → Extensions → Intlayer`، وقم بتعيين:
|
|
108
|
+
- **البيئة**: اسم البيئة المستخدمة لحل ملفات `.env.<env>*`.
|
|
109
|
+
- (اختياري) **ملف البيئة**: مسار صريح لملف `.env`. عند توفيره، يكون له الأولوية على القائمة المستنتجة.
|
|
172
110
|
|
|
173
|
-
|
|
111
|
+
#### المستودعات الأحادية والمجلدات المخصصة
|
|
174
112
|
|
|
175
|
-
|
|
176
|
-
2. ابحث عن **Test Dictionaries**.
|
|
177
|
-
3. راجع المشكلات المبلغ عنها وقم بإصلاحها حسب الحاجة.
|
|
113
|
+
إذا كانت ملفات `.env` الخاصة بك موجودة خارج جذر مساحة العمل، فقم بتعيين **الدليل الأساسي** في `الإعدادات → الإضافات → Intlayer`. سيبحث المحمل عن ملفات `.env` نسبةً إلى ذلك الدليل.
|
|
178
114
|
|
|
179
115
|
## تاريخ الوثيقة
|
|
180
116
|
|
|
181
|
-
| الإصدار | التاريخ | التغييرات
|
|
182
|
-
| ------- | ---------- |
|
|
183
|
-
|
|
|
117
|
+
| الإصدار | التاريخ | التغييرات |
|
|
118
|
+
| ------- | ---------- | ---------------------------------------- |
|
|
119
|
+
| 6.1.5 | 2025-09-30 | إضافة صورة متحركة توضيحية |
|
|
120
|
+
| 6.1.0 | 2025-09-24 | إضافة قسم اختيار البيئة |
|
|
121
|
+
| 6.0.0 | 2025-09-22 | تبويب Intlayer / أوامر التعبئة والاختبار |
|
|
122
|
+
| 5.5.10 | 2025-06-29 | بدء السجل |
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2024-03-07
|
|
3
|
+
updatedAt: 2025-09-30
|
|
4
|
+
title: Eine Komponente mehrsprachig machen (i18n-Bibliothek) in React und Next.js
|
|
5
|
+
description: Lernen Sie, wie Sie lokalisierten Inhalt deklarieren und abrufen, um eine mehrsprachige React- oder Next.js-Komponente mit Intlayer zu erstellen.
|
|
6
|
+
keywords:
|
|
7
|
+
- i18n
|
|
8
|
+
- komponent
|
|
9
|
+
- react
|
|
10
|
+
- mehrsprachig
|
|
11
|
+
- next.js
|
|
12
|
+
- intlayer
|
|
13
|
+
slugs:
|
|
14
|
+
- doc
|
|
15
|
+
- component
|
|
16
|
+
- i18n
|
|
17
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
|
|
18
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# Wie man eine Komponente mehrsprachig macht (i18n) mit Intlayer
|
|
22
|
+
|
|
23
|
+
Diese Anleitung zeigt die minimalen Schritte, um eine UI-Komponente in zwei gängigen Setups mehrsprachig zu machen:
|
|
24
|
+
|
|
25
|
+
- React (Vite/SPA)
|
|
26
|
+
- Next.js (App Router)
|
|
27
|
+
|
|
28
|
+
Zuerst deklarieren Sie Ihren Inhalt und rufen ihn dann in Ihrer Komponente ab.
|
|
29
|
+
|
|
30
|
+
## 1) Deklarieren Sie Ihren Inhalt (gemeinsam für React und Next.js)
|
|
31
|
+
|
|
32
|
+
Erstellen Sie eine Inhaltsdeklarationsdatei in der Nähe Ihrer Komponente. Dies hält die Übersetzungen nah an der Verwendung und ermöglicht Typsicherheit.
|
|
33
|
+
|
|
34
|
+
```ts fileName="component.content.ts"
|
|
35
|
+
import { t, type Dictionary } from "intlayer";
|
|
36
|
+
|
|
37
|
+
const componentContent = {
|
|
38
|
+
key: "component-example",
|
|
39
|
+
content: {
|
|
40
|
+
title: t({
|
|
41
|
+
en: "Hello",
|
|
42
|
+
fr: "Bonjour",
|
|
43
|
+
es: "Hola",
|
|
44
|
+
}),
|
|
45
|
+
description: t({
|
|
46
|
+
en: "Eine mehrsprachige React-Komponente", // Kommentar auf Deutsch
|
|
47
|
+
fr: "Un composant React multilingue",
|
|
48
|
+
es: "Un componente React multilingüe",
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
} satisfies Dictionary;
|
|
52
|
+
|
|
53
|
+
export default componentContent;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
JSON wird ebenfalls unterstützt, wenn Sie Konfigurationsdateien bevorzugen.
|
|
57
|
+
|
|
58
|
+
```json fileName="component.content.json"
|
|
59
|
+
{
|
|
60
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
61
|
+
"key": "component-example",
|
|
62
|
+
"content": {
|
|
63
|
+
"title": {
|
|
64
|
+
"nodeType": "translation",
|
|
65
|
+
"translation": { "en": "Hello", "fr": "Bonjour", "es": "Hola" }
|
|
66
|
+
},
|
|
67
|
+
"description": {
|
|
68
|
+
"nodeType": "translation",
|
|
69
|
+
"translation": {
|
|
70
|
+
"en": "Eine mehrsprachige React-Komponente",
|
|
71
|
+
"fr": "Un composant React multilingue",
|
|
72
|
+
"es": "Un componente React multilingüe"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 2) Rufen Sie Ihren Inhalt ab
|
|
80
|
+
|
|
81
|
+
### Fall A — React-App (Vite/SPA)
|
|
82
|
+
|
|
83
|
+
Standardansatz: Verwenden Sie `useIntlayer`, um per Schlüssel abzurufen. Dies hält Komponenten schlank und typisiert.
|
|
84
|
+
|
|
85
|
+
```tsx fileName="ComponentExample.tsx"
|
|
86
|
+
import { useIntlayer } from "react-intlayer";
|
|
87
|
+
|
|
88
|
+
export function ComponentExample() {
|
|
89
|
+
const content = useIntlayer("component-example");
|
|
90
|
+
return (
|
|
91
|
+
<div>
|
|
92
|
+
<h1>{content.title}</h1>
|
|
93
|
+
<p>{content.description}</p>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Serverseitiges Rendering oder außerhalb des Providers: Verwenden Sie `react-intlayer/server` und übergeben Sie bei Bedarf eine explizite `locale`.
|
|
100
|
+
|
|
101
|
+
```tsx fileName="ServerRenderedExample.tsx"
|
|
102
|
+
import { useIntlayer } from "react-intlayer/server";
|
|
103
|
+
|
|
104
|
+
export function ServerRenderedExample({ locale }: { locale: string }) {
|
|
105
|
+
const content = useIntlayer("component-example", locale);
|
|
106
|
+
return (
|
|
107
|
+
<>
|
|
108
|
+
<h1>{content.title}</h1>
|
|
109
|
+
<p>{content.description}</p>
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Alternative: `useDictionary` kann ein vollständig deklariertes Objekt lesen, wenn Sie die Struktur lieber am Aufrufort zusammenhalten möchten.
|
|
116
|
+
|
|
117
|
+
```tsx fileName="ComponentWithDictionary.tsx"
|
|
118
|
+
import { useDictionary } from "react-intlayer";
|
|
119
|
+
import componentContent from "./component.content";
|
|
120
|
+
|
|
121
|
+
export function ComponentWithDictionary() {
|
|
122
|
+
const { title, description } = useDictionary(componentContent);
|
|
123
|
+
return (
|
|
124
|
+
<div>
|
|
125
|
+
<h1>{title}</h1>
|
|
126
|
+
<p>{description}</p>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Fall B — Next.js (App Router)
|
|
133
|
+
|
|
134
|
+
Bevorzugen Sie Server-Komponenten für Datensicherheit und Leistung. Verwenden Sie `useIntlayer` aus `next-intlayer/server` in Server-Dateien und `useIntlayer` aus `next-intlayer` in Client-Komponenten.
|
|
135
|
+
|
|
136
|
+
```tsx fileName="app/[locale]/example/ServerComponent.tsx"
|
|
137
|
+
import { useIntlayer } from "next-intlayer/server";
|
|
138
|
+
|
|
139
|
+
export default function ServerComponent() {
|
|
140
|
+
const content = useIntlayer("component-example");
|
|
141
|
+
return (
|
|
142
|
+
<>
|
|
143
|
+
<h1>{content.title}</h1>
|
|
144
|
+
<p>{content.description}</p>
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```tsx fileName="app/[locale]/example/ClientComponent.tsx"
|
|
151
|
+
"use client";
|
|
152
|
+
|
|
153
|
+
import { useIntlayer } from "next-intlayer";
|
|
154
|
+
|
|
155
|
+
export function ClientComponent() {
|
|
156
|
+
const content = useIntlayer("component-example");
|
|
157
|
+
return (
|
|
158
|
+
<div>
|
|
159
|
+
<h1>{content.title}</h1>
|
|
160
|
+
<p>{content.description}</p>
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Tipp: Für Seiten-Metadaten und SEO können Sie Inhalte auch mit `getIntlayer` abrufen und mehrsprachige URLs über `getMultilingualUrls` generieren.
|
|
167
|
+
|
|
168
|
+
## Warum der Komponentenansatz von Intlayer der beste ist
|
|
169
|
+
|
|
170
|
+
- **Kollokation**: Inhaltsdeklarationen befinden sich nahe bei den Komponenten, was Drift reduziert und die Wiederverwendung in Designsystemen verbessert.
|
|
171
|
+
- **Typsicherheit**: Schlüssel und Strukturen sind stark typisiert; fehlende Übersetzungen werden zur Build-Zeit und nicht zur Laufzeit erkannt.
|
|
172
|
+
- **Server-first**: Funktioniert nativ in Server-Komponenten für bessere Sicherheit und Leistung; Client-Hooks bleiben ergonomisch.
|
|
173
|
+
- **Tree-shaking**: Es wird nur der Inhalt gebündelt, der von der Komponente verwendet wird, wodurch die Payloads in großen Apps klein bleiben.
|
|
174
|
+
- **DX & Tooling**: Eingebaute Middleware, SEO-Hilfen und optionale Visual Editor/AI-Übersetzungen optimieren die tägliche Arbeit.
|
|
175
|
+
|
|
176
|
+
Siehe die Vergleiche und Muster im Next.js-fokussierten Überblick: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
|
|
177
|
+
|
|
178
|
+
## Verwandte Anleitungen und Referenzen
|
|
179
|
+
|
|
180
|
+
- React Setup (Vite): https://intlayer.org/doc/environment/vite-and-react
|
|
181
|
+
- React Router v7: https://intlayer.org/doc/environment/vite-and-react/react-router-v7
|
|
182
|
+
- TanStack Start: https://intlayer.org/doc/environment/vite-and-react/tanstack-start
|
|
183
|
+
- Next.js Einrichtung: https://intlayer.org/doc/environment/nextjs
|
|
184
|
+
- Warum Intlayer vs. next-intl vs. next-i18next: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
|
|
185
|
+
|
|
186
|
+
Diese Seiten enthalten End-to-End-Setup, Provider, Routing und SEO-Hilfen.
|