MDX
الترجمة بالذكاء الاصطناعي لملفات MDX باستخدام Lingo.dev CLI
ما هو MDX؟
MDX هو تنسيق يجمع بين Markdown وJSX، مما يتيح لك استخدام مكونات React مباشرة في محتوى Markdown الخاص بك. يُستخدم بشكل شائع في مواقع التوثيق وتطبيقات الويب الغنية بالمحتوى.
على سبيل المثال:
---
title: "Restaurant Review: Bella Vista"
description: "Our dining experience at the new Italian restaurant downtown"
author: "not-localized-author"
---
# Dinner at Bella Vista
We finally tried the new Italian restaurant that opened last month on Main Street.
## The Atmosphere
The restaurant has a warm, inviting atmosphere with:
- **Dim lighting** that creates an intimate setting
- *Soft jazz music* playing in the background
ما هو Lingo.dev CLI؟
Lingo.dev CLI هو واجهة سطر أوامر مجانية ومفتوحة المصدر لترجمة التطبيقات والمحتوى باستخدام الذكاء الاصطناعي. تم تصميمه ليحل محل برامج إدارة الترجمة التقليدية مع التكامل مع خطوط الأنابيب الحالية.
لمعرفة المزيد، راجع نظرة عامة.
حول هذا الدليل
يشرح هذا الدليل كيفية ترجمة ملفات MDX باستخدام Lingo.dev CLI.
ستتعلم كيفية:
- إنشاء مشروع من الصفر
- تكوين خط أنابيب الترجمة
- إنشاء ترجمات باستخدام الذكاء الاصطناعي
المتطلبات الأساسية
لاستخدام Lingo.dev CLI، تأكد من تثبيت Node.js الإصدار 18 أو أحدث:
❯ node -v
v22.17.0
الخطوة 1. إعداد المشروع
في دليل مشروعك، أنشئ ملف i18n.json:
{
"$schema": "https://lingo.dev/schema/i18n.json",
"version": "1.10",
"locale": {
"source": "en",
"targets": ["es"]
},
"buckets": {}
}
يحدد هذا الملف سلوك خط أنابيب الترجمة، بما في ذلك اللغات المراد الترجمة بينها ومكان وجود المحتوى القابل للترجمة على نظام الملفات.
لمعرفة المزيد حول الخصائص المتاحة، راجع i18n.json.
الخطوة 2. تكوين اللغة المصدر
اللغة المصدر هي اللغة والمنطقة الأصلية التي تمت كتابة المحتوى بها. لتكوين اللغة المصدر، قم بتعيين خاصية locale.source في ملف i18n.json:
{
"$schema": "https://lingo.dev/schema/i18n.json",
"version": "1.10",
"locale": {
"source": "en",
"targets": ["es"]
},
"buckets": {}
}
يجب توفير اللغة المصدر كـ علامة لغة BCP 47.
للحصول على القائمة الكاملة لرموز اللغات التي يدعمها Lingo.dev CLI، راجع رموز اللغات المدعومة.
الخطوة 3. تكوين اللغات المستهدفة
اللغات المستهدفة هي اللغات والمناطق التي تريد ترجمة المحتوى الخاص بك إليها. لتكوين اللغات المستهدفة، قم بتعيين خاصية locale.targets في ملف i18n.json:
{
"$schema": "https://lingo.dev/schema/i18n.json",
"version": "1.10",
"locale": {
"source": "en",
"targets": ["es"]
},
"buckets": {}
}
الخطوة 4. إنشاء المحتوى المصدر
إذا لم تكن قد قمت بذلك بالفعل، قم بإنشاء ملف واحد أو أكثر من ملفات MDX التي تحتوي على المحتوى المراد ترجمته. يجب أن تكون هذه الملفات موجودة في مسار يتضمن اللغة المصدر في مكان ما من المسار (على سبيل المثال، كاسم دليل مثل en/ أو كجزء من اسم الملف مثل messages.en.mdx).
الخطوة 5. إنشاء حاوية
-
في ملف
i18n.json، أضف كائن"mdx"إلى كائنbuckets:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "mdx": {} } } -
في كائن
"mdx"، قم بتعريف مصفوفة من نمط واحد أو أكثر من أنماطinclude:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "mdx": { "include": ["./[locale]/example.mdx"] } } }تحدد هذه الأنماط الملفات التي سيتم ترجمتها.
الأنماط نفسها:
- يجب أن تحتوي على
[locale]كعنصر نائب للغة المكونة - يمكن أن تشير إلى مسارات الملفات (على سبيل المثال،
"[locale]/blog.mdx") - يمكن استخدام النجوم كعناصر نائبة بدل (على سبيل المثال،
"[locale]/*.mdx")
أنماط glob العودية (على سبيل المثال،
**/*.mdx) غير مدعومة. - يجب أن تحتوي على
الخطوة 6. تكوين نموذج لغوي كبير
يستخدم Lingo.dev CLI نماذج لغوية كبيرة (LLMs) لترجمة المحتوى باستخدام الذكاء الاصطناعي. لاستخدام أحد هذه النماذج، تحتاج إلى مفتاح API من مزود مدعوم.
للبدء بأسرع وقت ممكن، نوصي باستخدام Lingo.dev Engine — منصتنا المستضافة الخاصة التي توفر 10,000 رمز مميز من الاستخدام المجاني الشهري:
-
قم بتشغيل الأمر التالي:
npx lingo.dev@latest loginسيؤدي هذا إلى فتح متصفحك الافتراضي ومطالبتك بالمصادقة.
-
اتبع التعليمات.
الخطوة 7. إنشاء الترجمات
في الدليل الذي يحتوي على ملف i18n.json، قم بتشغيل الأمر التالي:
npx lingo.dev@latest run
يقوم هذا الأمر بما يلي:
- قراءة ملف
i18n.json. - العثور على الملفات التي تحتاج إلى ترجمة.
- استخراج المحتوى القابل للترجمة من الملفات.
- استخدام نموذج اللغة الكبير المُكوَّن لترجمة المحتوى المستخرج.
- كتابة المحتوى المترجم مرة أخرى إلى نظام الملفات.
في المرة الأولى التي يتم فيها إنشاء الترجمات، يتم إنشاء ملف i18n.lock. يتتبع هذا الملف المحتوى الذي تمت ترجمته، مما يمنع إعادة الترجمة غير الضرورية في عمليات التشغيل اللاحقة.
مثال
en/example.mdx
---
title: "Restaurant Review: Bella Vista"
description: "Our dining experience at the new Italian restaurant downtown"
author: "not-localized-author"
published: "2024-03-15"
rating: 4.5
locked_key_1: "This value should remain unchanged in all locales"
ignored_key_1: "This field should not appear in target locales"
---
# Dinner at Bella Vista
We finally tried the new Italian restaurant that opened last month on Main Street. Here's our honest review.
## The Atmosphere
The restaurant has a warm, inviting atmosphere with:
- **Dim lighting** that creates an intimate setting
- *Soft jazz music* playing in the background
- Fresh flowers on every table
es/example.mdx
---
title: "Reseña de Restaurante: Bella Vista"
description: "Nuestra experiencia gastronómica en el nuevo restaurante italiano del centro"
author: "not-localized-author"
published: "2024-03-15"
rating: 4.5
locked_key_1: "This value should remain unchanged in all locales"
---
# Cena en Bella Vista
Finalmente probamos el nuevo restaurante italiano que abrió el mes pasado en Main Street. Esta es nuestra reseña honesta.
## El Ambiente
El restaurante tiene un ambiente cálido y acogedor con:
- **Iluminación tenue** que crea un ambiente íntimo
- *Música de jazz suave* sonando de fondo
- Flores frescas en cada mesa
i18n.json
{
"version": "1.10",
"locale": {
"source": "en",
"targets": ["es"]
},
"buckets": {
"mdx": {
"include": ["./[locale]/example.mdx"],
"lockedKeys": ["locked_key_1"],
"lockedPatterns": ["pattern_1"]
}
},
"$schema": "https://lingo.dev/schema/i18n.json"
}
i18n.lock
version: 1
checksums:
0d5b5aa6d2b9937d47fd63868ef9e9f6:
meta/title: a4bdd0dee24f8318f3300dcae130a353
meta/description: 609213841f122e494f62262618ee4761
meta/author: f3f7164b5963b4da6cd31a2ec0251630
content/0: 8a8520492d23503da5691602e60bd22a
content/1: 1fc859854cda505b2a94a04c8b09ab43
content/2: 8add667f2a1d5d791a64b50bde54fa59
content/3: e6e34c4c92eda512ec209266abe8e074
content/4: 07f1896ad050b9606d7674f70d847818
content/5: bd4d40a4f0cc92ac8a880c8d9ce8b43d
content/6: 3036a07a887121ea080427d84fc80912
content/7: f555318416c5c5388c1d961ef02f5955
content/8: 90e02688ab103de60e42c70ece7efc4d
content/9: 8c5be3cd002a3a194c991821e0182e08
content/10: 3495801a7461ac5ea8d78369873a5409
content/11: d444739ce3d48afb7976067c67149a9e
content/12: 5f02c0a3b6385f80bdd08cf7e2d8c04d
content/13: 0a15fd446b87d907f58c303aece0882b
content/14: 778ed0aa1f81768280a23afe559c55f7
content/15: fa244af2d8e558d6c3644ff8c1a64562
content/16: 14f593e7cf3b3df84a21e17db318912e
content/17: 5f42d26a42aa29be063019eea27ad07c
content/18: 48bb7e89e72d68d6de12f5cdac64fc18
content/19: 1639b9ef57bf363e04293e27d1c13952
content/20: bb1c8d22064f7af4879c69d444e6e769
content/21: 52f9d6beaa85591f77811e1162d756c4