From 3505ef046d6e9340b3ee258f452e7e5ddbeb212b Mon Sep 17 00:00:00 2001 From: Paul Bovis Date: Tue, 17 Nov 2015 11:50:47 -0700 Subject: [PATCH 1/4] Added a translation for "Validation failed:" text The English term "Validation failed:" was hard coded on line 83. Instead, I created a translation and placed this at /system/languages/en.yaml. It will need to be translated into other languages by others. --- system/src/Grav/Common/Data/Blueprint.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index bf1f5a32f..7aa51440e 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -72,12 +72,15 @@ class Blueprint { // Initialize data $this->fields(); + + // Get language class + $language = self::getGrav()['language']; try { $this->validateArray($data, $this->nested); } catch (\RuntimeException $e) { - $language = self::getGrav()['language']; - throw new \RuntimeException(sprintf('Validation failed: %s', $language->translate($e->getMessage()))); + $message = sprintf($language->translate('FORM.VALIDATION_FAIL', null, true) . ' %s', $e->getMessage()); + throw new \RuntimeException($message); } } From d5b3f070a5a47a7da888cac84ea61f16c9480ba9 Mon Sep 17 00:00:00 2001 From: Paul Bovis Date: Tue, 17 Nov 2015 11:55:31 -0700 Subject: [PATCH 2/4] Added a translation for "Invalid input in " text The English phrase "Invalid input in " was hardcoded at line 40. I created a new translation 'FORM.INVALID_INPUT' and placed it in /system/languages/en.yaml. It will need to be translated into other languages by others. --- system/src/Grav/Common/Data/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index 653386fe9..c232467ba 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -38,7 +38,7 @@ class Validation $type = (string) isset($field['validate']['type']) ? $field['validate']['type'] : $field['type']; $method = 'type'.strtr($type, '-', '_'); $name = ucfirst(isset($field['label']) ? $field['label'] : $field['name']); - $message = (string) isset($field['validate']['message']) ? $field['validate']['message'] : 'Invalid input in "' . $language->translate($name) . '""'; + $message = (string) isset($field['validate']['message']) ? $field['validate']['message'] : $language->translate('FORM.INVALID_INPUT', null, true) . ' "' . $language->translate($name) . '"'; if (method_exists(__CLASS__, $method)) { $success = self::$method($value, $validate, $field); From 280377985fc525c915cd5f5c97c2b59f540ef82c Mon Sep 17 00:00:00 2001 From: Paul Bovis Date: Tue, 17 Nov 2015 11:57:15 -0700 Subject: [PATCH 3/4] Added form validation translations These will need to be translated into other languages. --- system/languages/en.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/system/languages/en.yaml b/system/languages/en.yaml index 5ae01dbde..a1eab6f19 100644 --- a/system/languages/en.yaml +++ b/system/languages/en.yaml @@ -92,3 +92,6 @@ NICETIME: MO_PLURAL: mos YR_PLURAL: yrs DEC_PLURAL: decs +FORM: + VALIDATION_FAIL: Validation failed: + INVALID_INPUT: Invalid input in From 3f94a6fda97b2589f3cd3be3d6c8240f329a8079 Mon Sep 17 00:00:00 2001 From: Paul Bovis Date: Tue, 17 Nov 2015 14:25:51 -0700 Subject: [PATCH 4/4] moved $language variable inside catch statement As requested --- system/src/Grav/Common/Data/Blueprint.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 7aa51440e..9bfc32303 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -72,13 +72,11 @@ class Blueprint { // Initialize data $this->fields(); - - // Get language class - $language = self::getGrav()['language']; try { $this->validateArray($data, $this->nested); } catch (\RuntimeException $e) { + $language = self::getGrav()['language']; $message = sprintf($language->translate('FORM.VALIDATION_FAIL', null, true) . ' %s', $e->getMessage()); throw new \RuntimeException($message); }