diff --git a/apps/web/src/components/DesignSystemsSection.tsx b/apps/web/src/components/DesignSystemsSection.tsx index 5de3dae9a76..2ab4065b654 100644 --- a/apps/web/src/components/DesignSystemsSection.tsx +++ b/apps/web/src/components/DesignSystemsSection.tsx @@ -2,6 +2,7 @@ import { Dialog, DialogFooter, DialogTitle } from '@open-design/components'; import { useEffect, useId, useMemo, useRef, useState } from 'react'; import type { Dispatch, FormEvent, SetStateAction } from 'react'; import { useT } from '../i18n'; +import { designSystemImportErrorKey } from '../runtime/design-system-import-error'; import type { AppConfig, DesignSystemGenerationJob, DesignSystemSummary } from '../types'; import { fetchDesignSystems, @@ -9,6 +10,7 @@ import { importLocalDesignSystem, importShadcnDesignSystem, updateDesignSystemDraft, + type SkillImportError, } from '../providers/registry'; import { DesignSystemPreviewModal } from './DesignSystemPreviewModal'; import { Icon } from './Icon'; @@ -71,7 +73,7 @@ export function DesignSystemsSection({ const [importMessage, setImportMessage] = useState(null); const [importedDesignSystem, setImportedDesignSystem] = useState(null); const [highlightedDesignSystemId, setHighlightedDesignSystemId] = useState(null); - const [importError, setImportError] = useState(null); + const [importError, setImportError] = useState(null); useEffect(() => { fetchDesignSystems().then(setDesignSystems); @@ -239,7 +241,7 @@ export function DesignSystemsSection({ : await importLocalDesignSystem({ baseDir: importTarget, ...importOptions }); setImporting(false); if ('error' in result) { - setImportError(result.error.message); + setImportError(result.error); return; } setDesignSystems((current) => { @@ -276,6 +278,8 @@ export function DesignSystemsSection({ }); } + const importErrorKey = importError ? designSystemImportErrorKey(importError) : null; + return (
@@ -451,7 +455,15 @@ export function DesignSystemsSection({
- {importError ?

{importError}

: null} + {importError ? ( +

+ {importErrorKey ? t(importErrorKey) : importError.message} +

+ {t('settings.designSystemsImportErrorDetails')} + {importError.message} +
+

+ ) : null} {importMessage ? (

{t('settings.designSystemsImportedStatus', { title: importMessage })} diff --git a/apps/web/src/i18n/locales/ar.ts b/apps/web/src/i18n/locales/ar.ts index 69213505b07..e06fa1665cf 100644 --- a/apps/web/src/i18n/locales/ar.ts +++ b/apps/web/src/i18n/locales/ar.ts @@ -3430,6 +3430,9 @@ export const ar: Dict = { 'settings.designSystemsImportProject': 'استيراد من المشروع', 'settings.designSystemsImportedStatus': 'تم استيراد {title}', 'settings.designSystemsViewImported': 'عرض نظام التصميم المستورد', + 'settings.designSystemsImportErrorInvalid': 'تعذر استيراد نظام التصميم. تحقق من المسار أو عنوان URL وحاول مرة أخرى.', + 'settings.designSystemsImportErrorInternal': 'تعذر استيراد نظام التصميم بسبب خطأ داخلي. حاول مرة أخرى.', + 'settings.designSystemsImportErrorDetails': 'التفاصيل', 'settings.designSystemsCategory': 'الفئة', 'settings.designSystemsAllCategories': 'كل الفئات', 'settings.designSystemsShowInHomeGallery': 'إظهار في معرض الصفحة الرئيسية', diff --git a/apps/web/src/i18n/locales/de.ts b/apps/web/src/i18n/locales/de.ts index 151fad854e3..30bd3e17300 100644 --- a/apps/web/src/i18n/locales/de.ts +++ b/apps/web/src/i18n/locales/de.ts @@ -3430,6 +3430,9 @@ export const de: Dict = { 'settings.designSystemsImportProject': 'Aus Projekt importieren', 'settings.designSystemsImportedStatus': '{title} importiert', 'settings.designSystemsViewImported': 'Importiertes Design-System anzeigen', + 'settings.designSystemsImportErrorInvalid': 'Design-System konnte nicht importiert werden. Überprüfen Sie den Pfad oder die URL und versuchen Sie es erneut.', + 'settings.designSystemsImportErrorInternal': 'Das Design-System konnte aufgrund eines internen Fehlers nicht importiert werden. Bitte versuchen Sie es erneut.', + 'settings.designSystemsImportErrorDetails': 'Details', 'settings.designSystemsCategory': 'Kategorie', 'settings.designSystemsAllCategories': 'Alle Kategorien', 'settings.designSystemsShowInHomeGallery': 'In Home-Galerie anzeigen', diff --git a/apps/web/src/i18n/locales/en.ts b/apps/web/src/i18n/locales/en.ts index 932ee24027f..2c55d5bb67c 100644 --- a/apps/web/src/i18n/locales/en.ts +++ b/apps/web/src/i18n/locales/en.ts @@ -3468,6 +3468,9 @@ export const en: Dict = { 'settings.designSystemsImportProject': 'Import from project', 'settings.designSystemsImportedStatus': 'Imported {title}', 'settings.designSystemsViewImported': 'View imported design system', + 'settings.designSystemsImportErrorInvalid': 'Couldn\'t import design system. Check the path or URL and try again.', + 'settings.designSystemsImportErrorInternal': 'Couldn\'t import design system due to an internal error. Please try again.', + 'settings.designSystemsImportErrorDetails': 'Details', 'settings.designSystemsCategory': 'Category', 'settings.designSystemsAllCategories': 'All categories', 'settings.designSystemsShowInHomeGallery': 'Show in home gallery', diff --git a/apps/web/src/i18n/locales/es-ES.ts b/apps/web/src/i18n/locales/es-ES.ts index 5a9711a8008..6bb99ba7922 100644 --- a/apps/web/src/i18n/locales/es-ES.ts +++ b/apps/web/src/i18n/locales/es-ES.ts @@ -3430,6 +3430,9 @@ export const esES: Dict = { 'settings.designSystemsImportProject': 'Importar desde proyecto', 'settings.designSystemsImportedStatus': '{title} importado', 'settings.designSystemsViewImported': 'Ver sistema de diseño importado', + 'settings.designSystemsImportErrorInvalid': 'No se pudo importar el sistema de diseño. Compruebe la ruta o la URL e inténtelo de nuevo.', + 'settings.designSystemsImportErrorInternal': 'No se pudo importar el sistema de diseño debido a un error interno. Inténtelo de nuevo.', + 'settings.designSystemsImportErrorDetails': 'Detalles', 'settings.designSystemsCategory': 'Categoría', 'settings.designSystemsAllCategories': 'Todas las categorías', 'settings.designSystemsShowInHomeGallery': 'Mostrar en la galería de inicio', diff --git a/apps/web/src/i18n/locales/fa.ts b/apps/web/src/i18n/locales/fa.ts index 04827052e8d..874f06adec1 100644 --- a/apps/web/src/i18n/locales/fa.ts +++ b/apps/web/src/i18n/locales/fa.ts @@ -3430,6 +3430,9 @@ export const fa: Dict = { 'settings.designSystemsImportProject': 'درون‌ریزی از پروژه', 'settings.designSystemsImportedStatus': '{title} درون‌ریزی شد', 'settings.designSystemsViewImported': 'مشاهده سیستم طراحی درون‌ریزی‌شده', + 'settings.designSystemsImportErrorInvalid': 'سیستم طراحی وارد نشد. مسیر یا URL را بررسی کرده و دوباره امتحان کنید.', + 'settings.designSystemsImportErrorInternal': 'به دلیل خطای داخلی، سیستم طراحی وارد نشد. لطفاً دوباره امتحان کنید.', + 'settings.designSystemsImportErrorDetails': 'جزئیات', 'settings.designSystemsCategory': 'دسته‌بندی', 'settings.designSystemsAllCategories': 'همه دسته‌بندی‌ها', 'settings.designSystemsShowInHomeGallery': 'نمایش در گالری خانه', diff --git a/apps/web/src/i18n/locales/fr.ts b/apps/web/src/i18n/locales/fr.ts index 77762559020..01c7bb63760 100644 --- a/apps/web/src/i18n/locales/fr.ts +++ b/apps/web/src/i18n/locales/fr.ts @@ -3430,6 +3430,9 @@ export const fr: Dict = { 'settings.designSystemsImportProject': 'Importer depuis le projet', 'settings.designSystemsImportedStatus': '{title} importé', 'settings.designSystemsViewImported': 'Voir le système de design importé', + 'settings.designSystemsImportErrorInvalid': 'Impossible d’importer le design system. Vérifiez le chemin ou l’URL et réessayez.', + 'settings.designSystemsImportErrorInternal': 'Impossible d’importer le design system en raison d’une erreur interne. Veuillez réessayer.', + 'settings.designSystemsImportErrorDetails': 'Détails', 'settings.designSystemsCategory': 'Catégorie', 'settings.designSystemsAllCategories': 'Toutes les catégories', 'settings.designSystemsShowInHomeGallery': 'Afficher dans la galerie d’accueil', diff --git a/apps/web/src/i18n/locales/hu.ts b/apps/web/src/i18n/locales/hu.ts index df86306e74d..44ce906fc6f 100644 --- a/apps/web/src/i18n/locales/hu.ts +++ b/apps/web/src/i18n/locales/hu.ts @@ -3430,6 +3430,9 @@ export const hu: Dict = { 'settings.designSystemsImportProject': 'Importálás projektből', 'settings.designSystemsImportedStatus': '{title} importálva', 'settings.designSystemsViewImported': 'Importált designrendszer megtekintése', + 'settings.designSystemsImportErrorInvalid': 'A designrendszer importálása nem sikerült. Ellenőrizze az elérési utat vagy az URL-t, és próbálja újra.', + 'settings.designSystemsImportErrorInternal': 'A designrendszer importálása belső hiba miatt nem sikerült. Kérjük, próbálja újra.', + 'settings.designSystemsImportErrorDetails': 'Részletek', 'settings.designSystemsCategory': 'Kategória', 'settings.designSystemsAllCategories': 'Minden kategória', 'settings.designSystemsShowInHomeGallery': 'Megjelenítés a kezdő galériában', diff --git a/apps/web/src/i18n/locales/id.ts b/apps/web/src/i18n/locales/id.ts index 28e58b9c338..7bebfdd5aa0 100644 --- a/apps/web/src/i18n/locales/id.ts +++ b/apps/web/src/i18n/locales/id.ts @@ -3430,6 +3430,9 @@ export const id: Dict = { 'settings.designSystemsImportProject': 'Impor dari proyek', 'settings.designSystemsImportedStatus': '{title} diimpor', 'settings.designSystemsViewImported': 'Lihat sistem desain yang diimpor', + 'settings.designSystemsImportErrorInvalid': 'Tidak dapat mengimpor sistem desain. Periksa jalur atau URL dan coba lagi.', + 'settings.designSystemsImportErrorInternal': 'Tidak dapat mengimpor sistem desain karena kesalahan internal. Silakan coba lagi.', + 'settings.designSystemsImportErrorDetails': 'Detail', 'settings.designSystemsCategory': 'Kategori', 'settings.designSystemsAllCategories': 'Semua kategori', 'settings.designSystemsShowInHomeGallery': 'Tampilkan di galeri beranda', diff --git a/apps/web/src/i18n/locales/it.ts b/apps/web/src/i18n/locales/it.ts index c59d4ca3a4e..267cb747dca 100644 --- a/apps/web/src/i18n/locales/it.ts +++ b/apps/web/src/i18n/locales/it.ts @@ -3430,6 +3430,9 @@ export const it: Dict = { 'settings.designSystemsImportProject': 'Importa dal progetto', 'settings.designSystemsImportedStatus': '{title} importato', 'settings.designSystemsViewImported': 'Vedi design system importato', + 'settings.designSystemsImportErrorInvalid': 'Impossibile importare il design system. Controlla il percorso o l’URL e riprova.', + 'settings.designSystemsImportErrorInternal': 'Impossibile importare il design system a causa di un errore interno. Riprova.', + 'settings.designSystemsImportErrorDetails': 'Dettagli', 'settings.designSystemsCategory': 'Categoria', 'settings.designSystemsAllCategories': 'Tutte le categorie', 'settings.designSystemsShowInHomeGallery': 'Mostra nella galleria iniziale', diff --git a/apps/web/src/i18n/locales/ja.ts b/apps/web/src/i18n/locales/ja.ts index b1245671c31..8de1fb7e475 100644 --- a/apps/web/src/i18n/locales/ja.ts +++ b/apps/web/src/i18n/locales/ja.ts @@ -3430,6 +3430,9 @@ export const ja: Dict = { 'settings.designSystemsImportProject': 'プロジェクトからインポート', 'settings.designSystemsImportedStatus': '{title} をインポートしました', 'settings.designSystemsViewImported': 'インポートしたデザインシステムを表示', + 'settings.designSystemsImportErrorInvalid': 'デザインシステムをインポートできませんでした。パスまたはURLを確認して、もう一度お試しください。', + 'settings.designSystemsImportErrorInternal': '内部エラーのため、デザインシステムをインポートできませんでした。もう一度お試しください。', + 'settings.designSystemsImportErrorDetails': '詳細', 'settings.designSystemsCategory': 'カテゴリー', 'settings.designSystemsAllCategories': 'すべてのカテゴリー', 'settings.designSystemsShowInHomeGallery': 'ホームギャラリーに表示', diff --git a/apps/web/src/i18n/locales/ko.ts b/apps/web/src/i18n/locales/ko.ts index 97926e5981f..cacb6971acc 100644 --- a/apps/web/src/i18n/locales/ko.ts +++ b/apps/web/src/i18n/locales/ko.ts @@ -3430,6 +3430,9 @@ export const ko: Dict = { 'settings.designSystemsImportProject': '프로젝트에서 가져오기', 'settings.designSystemsImportedStatus': '{title} 가져옴', 'settings.designSystemsViewImported': '가져온 디자인 시스템 보기', + 'settings.designSystemsImportErrorInvalid': '디자인 시스템을 가져올 수 없습니다. 경로 또는 URL을 확인하고 다시 시도하세요.', + 'settings.designSystemsImportErrorInternal': '낸부 오류로 인해 디자인 시스템을 가져올 수 없습니다. 다시 시도하세요.', + 'settings.designSystemsImportErrorDetails': '세부 정보', 'settings.designSystemsCategory': '카테고리', 'settings.designSystemsAllCategories': '모든 카테고리', 'settings.designSystemsShowInHomeGallery': '홈 갤러리에 표시', diff --git a/apps/web/src/i18n/locales/pl.ts b/apps/web/src/i18n/locales/pl.ts index 2577f115d9b..a3d1f91cf4d 100644 --- a/apps/web/src/i18n/locales/pl.ts +++ b/apps/web/src/i18n/locales/pl.ts @@ -3430,6 +3430,9 @@ export const pl: Dict = { 'settings.designSystemsImportProject': 'Importuj z projektu', 'settings.designSystemsImportedStatus': 'Zaimportowano {title}', 'settings.designSystemsViewImported': 'Pokaż zaimportowany system projektowy', + 'settings.designSystemsImportErrorInvalid': 'Nie można zaimportować systemu projektowego. Sprawdź ścieżkę lub adres URL i spróbuj ponownie.', + 'settings.designSystemsImportErrorInternal': 'Nie można zaimportować systemu projektowego z powodu błędu wewnętrznego. Spróbuj ponownie.', + 'settings.designSystemsImportErrorDetails': 'Szczegóły', 'settings.designSystemsCategory': 'Kategoria', 'settings.designSystemsAllCategories': 'Wszystkie kategorie', 'settings.designSystemsShowInHomeGallery': 'Pokaż w galerii głównej', diff --git a/apps/web/src/i18n/locales/pt-BR.ts b/apps/web/src/i18n/locales/pt-BR.ts index 6074c17a6fc..5bb1bde8055 100644 --- a/apps/web/src/i18n/locales/pt-BR.ts +++ b/apps/web/src/i18n/locales/pt-BR.ts @@ -3430,6 +3430,9 @@ export const ptBR: Dict = { 'settings.designSystemsImportProject': 'Importar do projeto', 'settings.designSystemsImportedStatus': '{title} importado', 'settings.designSystemsViewImported': 'Ver design system importado', + 'settings.designSystemsImportErrorInvalid': 'Não foi possível importar o design system. Verifique o caminho ou a URL e tente novamente.', + 'settings.designSystemsImportErrorInternal': 'Não foi possível importar o design system devido a um erro interno. Tente novamente.', + 'settings.designSystemsImportErrorDetails': 'Detalhes', 'settings.designSystemsCategory': 'Categoria', 'settings.designSystemsAllCategories': 'Todas as categorias', 'settings.designSystemsShowInHomeGallery': 'Mostrar na galeria inicial', diff --git a/apps/web/src/i18n/locales/ru.ts b/apps/web/src/i18n/locales/ru.ts index d6a0f10de15..14ab3d0b8c2 100644 --- a/apps/web/src/i18n/locales/ru.ts +++ b/apps/web/src/i18n/locales/ru.ts @@ -3430,6 +3430,9 @@ export const ru: Dict = { 'settings.designSystemsImportProject': 'Импортировать из проекта', 'settings.designSystemsImportedStatus': 'Импортировано: {title}', 'settings.designSystemsViewImported': 'Открыть импортированную дизайн-систему', + 'settings.designSystemsImportErrorInvalid': 'Не удалось импортировать дизайн-систему. Проверьте путь или URL и попробуйте снова.', + 'settings.designSystemsImportErrorInternal': 'Не удалось импортировать дизайн-систему из-за внутренней ошибки. Попробуйте снова.', + 'settings.designSystemsImportErrorDetails': 'Подробности', 'settings.designSystemsCategory': 'Категория', 'settings.designSystemsAllCategories': 'Все категории', 'settings.designSystemsShowInHomeGallery': 'Показывать в домашней галерее', diff --git a/apps/web/src/i18n/locales/th.ts b/apps/web/src/i18n/locales/th.ts index 1e4237b913f..db879ad30c2 100644 --- a/apps/web/src/i18n/locales/th.ts +++ b/apps/web/src/i18n/locales/th.ts @@ -3430,6 +3430,9 @@ export const th: Dict = { 'settings.designSystemsImportProject': 'นำเข้าจากโปรเจกต์', 'settings.designSystemsImportedStatus': 'นำเข้า {title} แล้ว', 'settings.designSystemsViewImported': 'ดูระบบออกแบบที่นำเข้า', + 'settings.designSystemsImportErrorInvalid': 'ไม่สามารถนำเข้าระบบออกแบบได้ ตรวจสอบเส้นทางหรือ URL แล้วลองอีกครั้ง', + 'settings.designSystemsImportErrorInternal': 'ไม่สามารถนำเข้าระบบออกแบบได้เนื่องจากข้อผิดพลาดภายใน โปรดลองอีกครั้ง', + 'settings.designSystemsImportErrorDetails': 'รายละเอียด', 'settings.designSystemsCategory': 'หมวดหมู่', 'settings.designSystemsAllCategories': 'ทุกหมวดหมู่', 'settings.designSystemsShowInHomeGallery': 'แสดงในแกลเลอรีหน้าแรก', diff --git a/apps/web/src/i18n/locales/tr.ts b/apps/web/src/i18n/locales/tr.ts index 0efe9eb9457..e23209aa316 100644 --- a/apps/web/src/i18n/locales/tr.ts +++ b/apps/web/src/i18n/locales/tr.ts @@ -3430,6 +3430,9 @@ export const tr: Dict = { 'settings.designSystemsImportProject': 'Projeden içe aktar', 'settings.designSystemsImportedStatus': '{title} içe aktarıldı', 'settings.designSystemsViewImported': 'İçe aktarılan tasarım sistemini görüntüle', + 'settings.designSystemsImportErrorInvalid': 'Tasarım sistemi içe aktarılamadı. Yolu veya URL\'yi kontrol edip tekrar deneyin.', + 'settings.designSystemsImportErrorInternal': 'Dahili bir hata nedeniyle tasarım sistemi içe aktarılamadı. Lütfen tekrar deneyin.', + 'settings.designSystemsImportErrorDetails': 'Ayrıntılar', 'settings.designSystemsCategory': 'Kategori', 'settings.designSystemsAllCategories': 'Tüm kategoriler', 'settings.designSystemsShowInHomeGallery': 'Ana galeride göster', diff --git a/apps/web/src/i18n/locales/uk.ts b/apps/web/src/i18n/locales/uk.ts index 055aab60631..b1539434f42 100644 --- a/apps/web/src/i18n/locales/uk.ts +++ b/apps/web/src/i18n/locales/uk.ts @@ -3430,6 +3430,9 @@ export const uk: Dict = { 'settings.designSystemsImportProject': 'Імпортувати з проєкту', 'settings.designSystemsImportedStatus': 'Імпортовано {title}', 'settings.designSystemsViewImported': 'Переглянути імпортовану дизайн-систему', + 'settings.designSystemsImportErrorInvalid': 'Не вдалося імпортувати дизайн-систему. Перевірте шлях або URL і спробуйте ще раз.', + 'settings.designSystemsImportErrorInternal': 'Не вдалося імпортувати дизайн-систему через внутрішню помилку. Спробуйте ще раз.', + 'settings.designSystemsImportErrorDetails': 'Деталі', 'settings.designSystemsCategory': 'Категорія', 'settings.designSystemsAllCategories': 'Усі категорії', 'settings.designSystemsShowInHomeGallery': 'Показувати в домашній галереї', diff --git a/apps/web/src/i18n/locales/zh-CN.ts b/apps/web/src/i18n/locales/zh-CN.ts index 704c2cc6c2e..a9f74123ae2 100644 --- a/apps/web/src/i18n/locales/zh-CN.ts +++ b/apps/web/src/i18n/locales/zh-CN.ts @@ -3682,6 +3682,9 @@ export const zhCN: Dict = { "settings.designSystemsImportProject": "从项目导入", "settings.designSystemsImportedStatus": "已导入 {title}", "settings.designSystemsViewImported": "查看导入的设计系统", + "settings.designSystemsImportErrorInvalid": "无法导入设计系统。请检查路径或 URL 后重试。", + "settings.designSystemsImportErrorInternal": "由于内部错误,无法导入设计系统。请重试。", + "settings.designSystemsImportErrorDetails": "详细信息", "settings.designSystemsCategory": "分类", "settings.designSystemsAllCategories": "所有分类", "settings.designSystemsShowInHomeGallery": "在首页 Gallery 中显示", diff --git a/apps/web/src/i18n/locales/zh-TW.ts b/apps/web/src/i18n/locales/zh-TW.ts index c5d29405db0..2eeb7fc5d6a 100644 --- a/apps/web/src/i18n/locales/zh-TW.ts +++ b/apps/web/src/i18n/locales/zh-TW.ts @@ -3691,6 +3691,9 @@ export const zhTW: Dict = { "settings.designSystemsImportProject": "從專案匯入", "settings.designSystemsImportedStatus": "已匯入 {title}", "settings.designSystemsViewImported": "查看匯入的設計系統", + "settings.designSystemsImportErrorInvalid": "無法匯入設計系統。請檢查路徑或 URL 後重試。", + "settings.designSystemsImportErrorInternal": "由於內部錯誤,無法匯入設計系統。請重試。", + "settings.designSystemsImportErrorDetails": "詳細資訊", "settings.designSystemsCategory": "分類", "settings.designSystemsAllCategories": "所有分類", "settings.designSystemsShowInHomeGallery": "在首頁 Gallery 中顯示", diff --git a/apps/web/src/i18n/types.ts b/apps/web/src/i18n/types.ts index 36f712c3bab..d7027d07134 100644 --- a/apps/web/src/i18n/types.ts +++ b/apps/web/src/i18n/types.ts @@ -603,6 +603,9 @@ export interface Dict { 'settings.designSystemsImportProject': string; 'settings.designSystemsImportedStatus': string; 'settings.designSystemsViewImported': string; + 'settings.designSystemsImportErrorInvalid': string; + 'settings.designSystemsImportErrorInternal': string; + 'settings.designSystemsImportErrorDetails': string; 'settings.designSystemsCategory': string; 'settings.designSystemsAllCategories': string; 'settings.designSystemsShowInHomeGallery': string; diff --git a/apps/web/src/runtime/design-system-import-error.ts b/apps/web/src/runtime/design-system-import-error.ts new file mode 100644 index 00000000000..c00a36111ed --- /dev/null +++ b/apps/web/src/runtime/design-system-import-error.ts @@ -0,0 +1,18 @@ +/** + * Maps a daemon design-system-import error code to its i18n key. + * + * The daemon returns `{ error: { code, message } }` where `message` is + * always English. This helper lets the UI show a localized summary for + * known codes while keeping the raw detail (paths, URLs) under a + *

disclosure. + * + * Returns `null` for unknown or missing codes — the caller should fall + * back to the raw `error.message` (pre-#2686 behavior). + */ +export function designSystemImportErrorKey( + error: { code?: string }, +): 'settings.designSystemsImportErrorInvalid' | 'settings.designSystemsImportErrorInternal' | null { + if (error.code === 'INTERNAL_ERROR') return 'settings.designSystemsImportErrorInternal'; + if (error.code === 'BAD_REQUEST') return 'settings.designSystemsImportErrorInvalid'; + return null; +} diff --git a/apps/web/tests/components/DesignSystemsSection.test.tsx b/apps/web/tests/components/DesignSystemsSection.test.tsx index d87491814e4..ce924fa3579 100644 --- a/apps/web/tests/components/DesignSystemsSection.test.tsx +++ b/apps/web/tests/components/DesignSystemsSection.test.tsx @@ -8,7 +8,12 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; import type { DesignSystemSummary } from '@open-design/contracts'; import { DesignSystemsSection } from '../../src/components/DesignSystemsSection'; -import { fetchDesignSystems, updateDesignSystemDraft } from '../../src/providers/registry'; +import { I18nProvider } from '../../src/i18n'; +import { + fetchDesignSystems, + importLocalDesignSystem, + updateDesignSystemDraft, +} from '../../src/providers/registry'; import type { AppConfig } from '../../src/types'; const memoryCss = readFileSync(resolve(process.cwd(), 'src/styles/viewer/memory.css'), 'utf8'); @@ -63,6 +68,11 @@ vi.mock('../../src/providers/registry', async () => { ...actual, fetchDesignSystems: vi.fn(async () => [editable, builtIn]), updateDesignSystemDraft: vi.fn(async () => ({ ...editable, title: 'Acme v2', body: '' })), + // Default to a successful response so unrelated tests don't hit the real fetch. + // Individual tests override with `mockResolvedValueOnce` to assert error paths. + importLocalDesignSystem: vi.fn( + async () => ({ designSystem: editable }) as Awaited>, + ), }; }); @@ -199,3 +209,63 @@ describe('DesignSystemsSection rename (issue #2811)', () => { } }); }); + +// Issue #2686: when the daemon rejects a design-system import, the Settings +// form must not surface its raw English message in a non-English UI. Today +// the import-error slot renders `result.error.message` directly, so a Chinese +// (or any other non-English) locale sees an English error inline. The red +// spec anchors the contract: after a failed import, the daemon's English +// text must not be visible in the rendered form. The fix will route the +// error envelope through a localized formatter (`formatDesignSystemImportError`) +// that maps `code` to an i18n key and keeps the raw detail under a details +// disclosure. +describe('DesignSystemsSection import error localization (issue #2686)', () => { + it('does not surface the daemon raw English message in the import form under zh-CN', async () => { + vi.mocked(importLocalDesignSystem).mockResolvedValueOnce({ + error: { + code: 'BAD_REQUEST', + message: 'local project path must be a directory', + }, + }); + + render( + + {}} /> + , + ); + + // Open the import form (collapsible +Add design system panel). + const addButton = await screen.findByRole('button', { + name: /add design system|添加设计系统/i, + }); + fireEvent.click(addButton); + + // Fill in the local-import path field. + const pathInput = await screen.findByPlaceholderText(/\/path\/to\/project/); + fireEvent.change(pathInput, { target: { value: '/tmp/non-existent' } }); + + // Submit. The button text is localized ("从项目导入" in zh-CN) — match on a unique substring. + const submit = screen.getByRole('button', { + name: /从项目导入/i, + }); + fireEvent.click(submit); + + // Sanity: the import client was actually invoked with our typed path. + await waitFor(() => { + expect(importLocalDesignSystem).toHaveBeenCalledWith( + expect.objectContaining({ baseDir: '/tmp/non-existent' }), + ); + }); + + // The localized Chinese summary replaces the raw English as the + // user-facing message. The raw detail stays under
. + await waitFor(() => { + expect(screen.getByText(/无法导入设计系统/)).toBeInTheDocument(); + }); + + // Raw daemon detail is still accessible for diagnostics. + const detail = document.querySelector('.library-install-error-detail code'); + expect(detail).toBeTruthy(); + expect(detail!.textContent).toBe('local project path must be a directory'); + }); +}); diff --git a/apps/web/tests/runtime/design-system-import-error.test.ts b/apps/web/tests/runtime/design-system-import-error.test.ts new file mode 100644 index 00000000000..96b16ebf860 --- /dev/null +++ b/apps/web/tests/runtime/design-system-import-error.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, it } from 'vitest'; + +import { designSystemImportErrorKey } from '../../src/runtime/design-system-import-error'; + +describe('designSystemImportErrorKey', () => { + it('maps BAD_REQUEST to the invalid-import key', () => { + expect(designSystemImportErrorKey({ code: 'BAD_REQUEST' })).toBe( + 'settings.designSystemsImportErrorInvalid', + ); + }); + + it('maps INTERNAL_ERROR to the internal-error key', () => { + expect(designSystemImportErrorKey({ code: 'INTERNAL_ERROR' })).toBe( + 'settings.designSystemsImportErrorInternal', + ); + }); + + it('returns null for unknown codes', () => { + expect(designSystemImportErrorKey({ code: 'SOMETHING_ELSE' })).toBeNull(); + }); + + it('returns null when code is missing', () => { + expect(designSystemImportErrorKey({})).toBeNull(); + }); + + it('returns null for an empty code string', () => { + expect(designSystemImportErrorKey({ code: '' })).toBeNull(); + }); +});