Beautiful Open-Source Form Builder
ESC-652 = Enhance useAlert composable for internationalization support (#826)
Chirag Chhatralaff0db7e45933
diff --git a/client/components/open/forms/OpenCompleteForm.vue b/client/components/open/forms/OpenCompleteForm.vueindex 316b7f477..378206cac 100644--- a/client/components/open/forms/OpenCompleteForm.vue+++ b/client/components/open/forms/OpenCompleteForm.vue@@ -397,9 +397,9 @@ const triggerSubmit = () => {.catch(error => {console.error(error)if (error.response && error.response.status === 422 && error.data) {- useAlert().formValidationError(error.data)+ alert.formValidationError(error.data)} else if (error.message) {- useAlert().error(error.message)+ alert.error(error.message)}handleScrollToError()}).finally(() => {diff --git a/client/composables/useAlert.js b/client/composables/useAlert.jsindex c929fcc38..b3c7a4654 100644--- a/client/composables/useAlert.js+++ b/client/composables/useAlert.js@@ -1,6 +1,6 @@import { h } from 'vue'-export function useAlert () {+export function useAlert() {function success (message, autoClose = 10000, options = {}) {if (typeof message === 'object' && message !== null) {@@ -68,7 +68,8 @@ export function useAlert () {}function validationError(error, autoClose = 10000, options = {}) {- const message = error.message || 'Validation Error'+ const t = useNuxtApp().$i18n.t+ const message = error.message || t('forms.validation_error')let description = messageif (error.errors) {@@ -83,7 +84,7 @@ export function useAlert () {return useToast().add({icon: 'i-heroicons-x-circle',- title: options.title ?? 'Validation Error',+ title: options.title ?? t('forms.validation_error'),description,color: 'error',duration: autoClose,@@ -96,6 +97,8 @@ export function useAlert () {return error(error.message || 'An unknown validation error occurred', autoClose, options)}+ const t = useNuxtApp().$i18n.t+// Count total errorsconst errorCount = Object.keys(error.errors).length@@ -114,8 +117,8 @@ export function useAlert () {// Add count of errors to the titleconst title = options.title || (errorCount > 1- ? `Validation Error (${errorCount} fields)`- : 'Validation Error')+ ? t('forms.validation_error_with_count', { count: errorCount })+ : t('forms.validation_error'))return useToast().add({icon: 'i-heroicons-x-circle',diff --git a/client/i18n/lang/ar.json b/client/i18n/lang/ar.jsonindex 033876714..96e8283ab 100644--- a/client/i18n/lang/ar.json+++ b/client/i18n/lang/ar.json@@ -66,6 +66,8 @@"failedIntent": "فشل في إنشاء نية الدفع.","processingFailed": "فشلت معالجة الدفع."}- }+ },+ "validation_error": "خطأ في التحقق",+ "validation_error_with_count": "خطأ في التحقق ({count} حقول)"}}\ No newline at end of filediff --git a/client/i18n/lang/bn.json b/client/i18n/lang/bn.jsonindex aff40c205..c9c588c7f 100644--- a/client/i18n/lang/bn.json+++ b/client/i18n/lang/bn.json@@ -66,6 +66,8 @@"failedIntent": "পেমেন্ট ইনটেন্ট তৈরি করতে ব্যর্থ হয়েছে।","processingFailed": "পেমেন্ট প্রক্রিয়াকরণ ব্যর্থ হয়েছে।"}- }+ },+ "validation_error": "যাচাইকরণ ত্রুটি",+ "validation_error_with_count": "যাচাইকরণ ত্রুটি ({count}টি ক্ষেত্র)"}}\ No newline at end of filediff --git a/client/i18n/lang/ca.json b/client/i18n/lang/ca.jsonindex 4b14130e5..fd7cc6b35 100644--- a/client/i18n/lang/ca.json+++ b/client/i18n/lang/ca.json@@ -66,6 +66,8 @@"failedIntent": "No s'ha pogut crear la intenció de pagament.","processingFailed": "El processament del pagament ha fallat."}- }+ },+ "validation_error": "Error de validació",+ "validation_error_with_count": "Error de validació ({count} camps)"}}\ No newline at end of filediff --git a/client/i18n/lang/cs.json b/client/i18n/lang/cs.jsonindex ecf451eef..e79cd078d 100644--- a/client/i18n/lang/cs.json+++ b/client/i18n/lang/cs.json@@ -66,6 +66,8 @@"failedIntent": "Nepodařilo se vytvořit záměr platby.","processingFailed": "Zpracování platby se nezdařilo."}- }+ },+ "validation_error": "Chyba ověření",+ "validation_error_with_count": "Chyba ověření ({count} polí)"}}\ No newline at end of filediff --git a/client/i18n/lang/de.json b/client/i18n/lang/de.jsonindex 8246f9fc2..c270305f4 100644--- a/client/i18n/lang/de.json+++ b/client/i18n/lang/de.json@@ -66,6 +66,8 @@"failedIntent": "Zahlungsabsicht konnte nicht erstellt werden.","processingFailed": "Zahlungsabwicklung fehlgeschlagen."}- }+ },+ "validation_error": "Validierungsfehler",+ "validation_error_with_count": "Validierungsfehler ({count} Felder)"}}\ No newline at end of filediff --git a/client/i18n/lang/en.json b/client/i18n/lang/en.jsonindex 9faa6ae66..e59966634 100644--- a/client/i18n/lang/en.json+++ b/client/i18n/lang/en.json@@ -66,6 +66,8 @@"failedIntent": "Failed to create payment intent.","processingFailed": "Payment processing failed."}- }+ },+ "validation_error": "Validation Error",+ "validation_error_with_count": "Validation Error ({count} fields)"}}\ No newline at end of filediff --git a/client/i18n/lang/es.json b/client/i18n/lang/es.jsonindex 6367d53db..f463a4f3c 100644--- a/client/i18n/lang/es.json+++ b/client/i18n/lang/es.json@@ -66,6 +66,8 @@"failedIntent": "Error al crear la intención de pago.","processingFailed": "El procesamiento del pago ha fallado."}- }+ },+ "validation_error": "Error de validación",+ "validation_error_with_count": "Error de validación ({count} campos)"}}\ No newline at end of filediff --git a/client/i18n/lang/eu.json b/client/i18n/lang/eu.jsonindex 42bfca961..6d5ed567c 100644--- a/client/i18n/lang/eu.json+++ b/client/i18n/lang/eu.json@@ -66,6 +66,8 @@"failedIntent": "Ezin izan da ordainketa asmoa sortu.","processingFailed": "Ordainketaren prozesamenduak huts egin du."}- }+ },+ "validation_error": "Balidazio errorea",+ "validation_error_with_count": "Balidazio errorea ({count} eremu)"}}\ No newline at end of filediff --git a/client/i18n/lang/fr.json b/client/i18n/lang/fr.jsonindex c84403af0..97c42358c 100644--- a/client/i18n/lang/fr.json+++ b/client/i18n/lang/fr.json@@ -66,6 +66,8 @@"failedIntent": "Échec de la création de l'intention de paiement.","processingFailed": "Le traitement du paiement a échoué."}- }+ },+ "validation_error": "Erreur de validation",+ "validation_error_with_count": "Erreur de validation ({count} champs)"}}\ No newline at end of filediff --git a/client/i18n/lang/gl.json b/client/i18n/lang/gl.jsonindex 5b2b87249..feae0d868 100644--- a/client/i18n/lang/gl.json+++ b/client/i18n/lang/gl.json@@ -66,6 +66,8 @@"failedIntent": "Non se puido crear a intención de pago.","processingFailed": "O procesamento do pago fallou."}- }+ },+ "validation_error": "Erro de validación",+ "validation_error_with_count": "Erro de validación ({count} campos)"}}\ No newline at end of filediff --git a/client/i18n/lang/hi.json b/client/i18n/lang/hi.jsonindex e29b56378..ff9c514c5 100644--- a/client/i18n/lang/hi.json+++ b/client/i18n/lang/hi.json@@ -66,6 +66,8 @@"failedIntent": "भुगतान इरादा बनाने में विफल।","processingFailed": "भुगतान प्रसंस्करण विफल रहा।"}- }+ },+ "validation_error": "सत्यापन त्रुटि",+ "validation_error_with_count": "सत्यापन त्रुटि ({count} फ़ील्ड)"}}\ No newline at end of filediff --git a/client/i18n/lang/ja.json b/client/i18n/lang/ja.jsonindex dc75c520e..db7d77bfe 100644--- a/client/i18n/lang/ja.json+++ b/client/i18n/lang/ja.json@@ -66,6 +66,8 @@"failedIntent": "支払いインテントを作成できませんでした。","processingFailed": "支払処理に失敗しました。"}- }+ },+ "validation_error": "検証エラー",+ "validation_error_with_count": "検証エラー({count}フィールド)"}}\ No newline at end of filediff --git a/client/i18n/lang/jv.json b/client/i18n/lang/jv.jsonindex 9cf7405d6..d6a5b8f3c 100644--- a/client/i18n/lang/jv.json+++ b/client/i18n/lang/jv.json@@ -66,6 +66,8 @@"failedIntent": "Gagal nggawe niat pembayaran.","processingFailed": "Proses pembayaran gagal."}- }+ },+ "validation_error": "Kesalahan validasi",+ "validation_error_with_count": "Kesalahan validasi ({count} kolom)"}}\ No newline at end of filediff --git a/client/i18n/lang/ko.json b/client/i18n/lang/ko.jsonindex 65b3b4640..a4d269904 100644--- a/client/i18n/lang/ko.json+++ b/client/i18n/lang/ko.json@@ -66,6 +66,8 @@"failedIntent": "결제 의도를 생성하지 못했습니다.","processingFailed": "결제 처리에 실패했습니다."}- }+ },+ "validation_error": "유효성 검사 오류",+ "validation_error_with_count": "유효성 검사 오류 ({count}개 필드)"}}\ No newline at end of filediff --git a/client/i18n/lang/mr.json b/client/i18n/lang/mr.jsonindex 8d3dc0d2d..299b01775 100644--- a/client/i18n/lang/mr.json+++ b/client/i18n/lang/mr.json@@ -66,6 +66,8 @@"failedIntent": "पेमेंट उद्देश तयार करण्यात अयशस्वी.","processingFailed": "पेमेंट प्रक्रिया अयशस्वी झाली."}- }+ },+ "validation_error": "प्रमाणीकरण त्रुटी",+ "validation_error_with_count": "प्रमाणीकरण त्रुटी ({count} फील्ड)"}}\ No newline at end of filediff --git a/client/i18n/lang/pa.json b/client/i18n/lang/pa.jsonindex 45645dc12..3794048ac 100644--- a/client/i18n/lang/pa.json+++ b/client/i18n/lang/pa.json@@ -66,6 +66,8 @@"failedIntent": "ਭੁਗਤਾਨ ਇਰਾਦਾ ਬਣਾਉਣ ਵਿੱਚ ਅਸਫਲ।","processingFailed": "ਭੁਗਤਾਨ ਪ੍ਰਕਿਰਿਆ ਅਸਫਲ ਰਹੀ।"}- }+ },+ "validation_error": "ਪ੍ਰਮਾਣਿਕਤਾ ਗਲਤੀ",+ "validation_error_with_count": "ਪ੍ਰਮਾਣਿਕਤਾ ਗਲਤੀ ({count} ਖੇਤਰ)"}}\ No newline at end of filediff --git a/client/i18n/lang/pl.json b/client/i18n/lang/pl.jsonindex b2723b05f..a078a0a0a 100644--- a/client/i18n/lang/pl.json+++ b/client/i18n/lang/pl.json@@ -66,6 +66,8 @@"failedIntent": "Nie udało się utworzyć zamiaru płatności.","processingFailed": "Przetwarzanie płatności nie powiodło się."}- }+ },+ "validation_error": "Błąd walidacji",+ "validation_error_with_count": "Błąd walidacji ({count} pola)"}}\ No newline at end of filediff --git a/client/i18n/lang/pt.json b/client/i18n/lang/pt.jsonindex 804a40468..78fcccd2e 100644--- a/client/i18n/lang/pt.json+++ b/client/i18n/lang/pt.json@@ -66,6 +66,8 @@"failedIntent": "Falha ao criar a intenção de pagamento.","processingFailed": "O processamento do pagamento falhou."}- }+ },+ "validation_error": "Erro de validação",+ "validation_error_with_count": "Erro de validação ({count} campos)"}}\ No newline at end of filediff --git a/client/i18n/lang/ru.json b/client/i18n/lang/ru.jsonindex c1367ef7c..bce4b62cb 100644--- a/client/i18n/lang/ru.json+++ b/client/i18n/lang/ru.json@@ -66,6 +66,8 @@"failedIntent": "Не удалось создать намерение платежа.","processingFailed": "Ошибка обработки платежа."}- }+ },+ "validation_error": "Ошибка валидации",+ "validation_error_with_count": "Ошибка валидации ({count} поля)"}}\ No newline at end of filediff --git a/client/i18n/lang/sk.json b/client/i18n/lang/sk.jsonindex 25fdf8cc2..1dcf8c54b 100644--- a/client/i18n/lang/sk.json+++ b/client/i18n/lang/sk.json@@ -66,6 +66,8 @@"failedIntent": "Nepodarilo sa vytvoriť zámer platby.","processingFailed": "Spracovanie platby zlyhalo."}- }+ },+ "validation_error": "Chyba overenia",+ "validation_error_with_count": "Chyba overenia ({count} polí)"}}diff --git a/client/i18n/lang/sv.json b/client/i18n/lang/sv.jsonindex b7ab5d9a5..60d77a5bf 100644--- a/client/i18n/lang/sv.json+++ b/client/i18n/lang/sv.json@@ -66,6 +66,8 @@"failedIntent": "Det gick inte att skapa betalningsavsikt.","processingFailed": "Betalningsbehandlingen misslyckades."}- }+ },+ "validation_error": "Valideringsfel",+ "validation_error_with_count": "Valideringsfel ({count} fält)"}}\ No newline at end of filediff --git a/client/i18n/lang/ta.json b/client/i18n/lang/ta.jsonindex eafa5fd22..e07b69dfa 100644--- a/client/i18n/lang/ta.json+++ b/client/i18n/lang/ta.json@@ -66,6 +66,8 @@"failedIntent": "பணம் செலுத்தும் நோக்கத்தை உருவாக்க முடியவில்லை.","processingFailed": "பணம் செலுத்துதல் செயலாக்கம் தோல்வியடைந்தது."}- }+ },+ "validation_error": "சரிபார்ப்பு பிழை",+ "validation_error_with_count": "சரிபார்ப்பு பிழை ({count} புலங்கள்)"}}\ No newline at end of filediff --git a/client/i18n/lang/te.json b/client/i18n/lang/te.jsonindex 61f9a30ce..d231e0275 100644--- a/client/i18n/lang/te.json+++ b/client/i18n/lang/te.json@@ -66,6 +66,8 @@"failedIntent": "చెల్లింపు ఉద్దేశాన్ని సృష్టించడంలో విఫలమైంది.","processingFailed": "చెల్లింపు ప్రాసెసింగ్ విఫలమైంది."}- }+ },+ "validation_error": "ధ్రువీకరణ లోపం",+ "validation_error_with_count": "ధ్రువీకరణ లోపం ({count} ఫీల్డ్లు)"}}\ No newline at end of filediff --git a/client/i18n/lang/tr.json b/client/i18n/lang/tr.jsonindex 1e119ace4..28955b050 100644--- a/client/i18n/lang/tr.json+++ b/client/i18n/lang/tr.json@@ -66,6 +66,8 @@"failedIntent": "Ödeme amacı oluşturulamadı.","processingFailed": "Ödeme işlemi başarısız oldu."}- }+ },+ "validation_error": "Doğrulama Hatası",+ "validation_error_with_count": "Doğrulama Hatası ({count} alan)"}}\ No newline at end of filediff --git a/client/i18n/lang/ur.json b/client/i18n/lang/ur.jsonindex 5823e40bc..943788740 100644--- a/client/i18n/lang/ur.json+++ b/client/i18n/lang/ur.json@@ -66,6 +66,8 @@"failedIntent": "ادائیگی کا ارادہ بنانے میں ناکام۔","processingFailed": "ادائیگی کی کارروائی ناکام ہوگئی۔"}- }+ },+ "validation_error": "تصدیق کی خرابی",+ "validation_error_with_count": "تصدیق کی خرابی ({count} فیلڈز)"}}\ No newline at end of filediff --git a/client/i18n/lang/vi.json b/client/i18n/lang/vi.jsonindex 1562c9c00..15dca867b 100644--- a/client/i18n/lang/vi.json+++ b/client/i18n/lang/vi.json@@ -66,6 +66,8 @@"failedIntent": "Không thể tạo ý định thanh toán.","processingFailed": "Xử lý thanh toán không thành công."}- }+ },+ "validation_error": "Lỗi xác thực",+ "validation_error_with_count": "Lỗi xác thực ({count} trường)"}}\ No newline at end of filediff --git a/client/i18n/lang/zh.json b/client/i18n/lang/zh.jsonindex 8837b103a..bf3321af9 100644--- a/client/i18n/lang/zh.json+++ b/client/i18n/lang/zh.json@@ -66,6 +66,8 @@"failedIntent": "创建支付意图失败。","processingFailed": "支付处理失败。"}- }+ },+ "validation_error": "验证错误",+ "validation_error_with_count": "验证错误 ({count} 个字段)"}}\ No newline at end of filediff --git a/client/lib/forms/composables/useFormValidation.js b/client/lib/forms/composables/useFormValidation.jsindex 04b4c0c92..657162d42 100644--- a/client/lib/forms/composables/useFormValidation.js+++ b/client/lib/forms/composables/useFormValidation.js@@ -23,7 +23,13 @@ export function useFormValidation(formConfig, form, managerState) {const validationUrl = `/forms/${config.slug}/answer` // Use reactive config// Use the reactive formRef- await formRef.value.validate(httpMethod, validationUrl, {}, fieldIds)+ try {+ await formRef.value.validate(httpMethod, validationUrl, {}, fieldIds)+ } catch (error) {+ console.error('Validation error:', error)+ useAlert().formValidationError(error.data)+ throw error+ }return true // Validation passed}