From 420a9c41e02b2ff18f331bda80981206effa7e58 Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Thu, 28 Sep 2023 17:34:18 +0200 Subject: [PATCH] Use WP logic to enqueue Parsley validation strings [MAILPOET-5118] --- mailpoet/lib/AdminPages/AssetsController.php | 3 +++ mailpoet/views/layout.html | 28 -------------------- mailpoet/views/parsley-translations.html | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 mailpoet/views/parsley-translations.html diff --git a/mailpoet/lib/AdminPages/AssetsController.php b/mailpoet/lib/AdminPages/AssetsController.php index 35ba94ea1d..25f0d0758d 100644 --- a/mailpoet/lib/AdminPages/AssetsController.php +++ b/mailpoet/lib/AdminPages/AssetsController.php @@ -75,6 +75,9 @@ class AssetsController { true ); $this->wp->wpSetScriptTranslations($name, 'mailpoet'); + + // append Parsley validation string translations + $this->wp->wpAddInlineScript($name, $this->renderer->render('parsley-translations.html')); } private function registerAdminDeps(): void { diff --git a/mailpoet/views/layout.html b/mailpoet/views/layout.html index 08b6bb5cfb..eee8c589b4 100644 --- a/mailpoet/views/layout.html +++ b/mailpoet/views/layout.html @@ -206,32 +206,4 @@ <% endif %> -
diff --git a/mailpoet/views/parsley-translations.html b/mailpoet/views/parsley-translations.html new file mode 100644 index 0000000000..352dc41f81 --- /dev/null +++ b/mailpoet/views/parsley-translations.html @@ -0,0 +1,27 @@ + +Parsley.addMessages('mailpoet', { + defaultMessage: '<%= __("This value seems to be invalid.") %>', + type: { + email: '<%= __("This value should be a valid email.") %>', + url: '<%= __("This value should be a valid url.") %>', + number: '<%= __("This value should be a valid number.") %>', + integer: '<%= __("This value should be a valid integer.") %>', + digits: '<%= __("This value should be digits.") %>', + alphanum: '<%= __("This value should be alphanumeric.") %>' + }, + notblank: '<%= __("This value should not be blank.") %>', + required: '<%= __("This value is required.") %>', + pattern: '<%= __("This value seems to be invalid.") %>', + min: '<%= __("This value should be greater than or equal to %s.") %>', + max: '<%= __("This value should be lower than or equal to %s.") %>', + range: '<%= __("This value should be between %s and %s.") %>', + minlength: '<%= __("This value is too short. It should have %s characters or more.") %>', + maxlength: '<%= __("This value is too long. It should have %s characters or fewer.") %>', + length: '<%= __("This value length is invalid. It should be between %s and %s characters long.") %>', + mincheck: '<%= __("You must select at least %s choices.") %>', + maxcheck: '<%= __("You must select %s choices or fewer.") %>', + check: '<%= __("You must select between %s and %s choices.") %>', + equalto: '<%= __("This value should be the same.") %>' +}); + +Parsley.setLocale('mailpoet');