zendframework / zend-inputfilter

InputFilter component from Zend Framework
BSD 3-Clause "New" or "Revised" License
64 stars 50 forks source link

NotEmpty::IS_EMPTY not translated #71

Closed bacinsky closed 8 years ago

bacinsky commented 8 years ago

How is it possible to translate NotEmpty::IS_EMPTY message?

https://github.com/zendframework/zend-inputfilter/blob/master/src/Input.php#L497

bogutskyy commented 8 years ago

The same problem. Any ideas?

bogutskyy commented 8 years ago

And how to set a custom message for required field? Message generate without any validators https://github.com/zendframework/zend-inputfilter/blob/master/src/Input.php#L407.

bacinsky commented 8 years ago

As a temporary solution I rewrote the class method like this:

protected function prepareRequiredValidationFailureMessage()
    {
        $notEmpty = new NotEmpty();
        $templates = $notEmpty->getOption('messageTemplates');

        $message = $notEmpty->hasTranslator()
                 ? $notEmpty->getTranslator()->translate($templates[NotEmpty::IS_EMPTY])
                 : $templates[NotEmpty::IS_EMPTY];

        return [
            // TODO remove this file
            // @issue message translation fix https://github.com/zendframework/zend-inputfilter/issues/71
            NotEmpty::IS_EMPTY => $message,
        ];
    }

But I think it's even a more mess now.

svycka commented 8 years ago

does this help? https://github.com/zendframework/zend-inputfilter/pull/73

bogutskyy commented 8 years ago

In #73 message still get from templates, without translation. https://github.com/larsnystrom/zend-inputfilter/commit/4fc84cd93fd90da68f216927ef6226c97927e330#diff-5e41c64803af5c0ad8ad84c3e25c834cR510.

         return [
             NotEmpty::IS_EMPTY => $templates[NotEmpty::IS_EMPTY],
svycka commented 8 years ago

you could set translated message with validator options, but yes this is not perfect. just as test I created PR https://github.com/larsnystrom/zend-inputfilter/pull/1 could you test with this?

larsnystrom commented 8 years ago

PR #67 addresses this. PR #73 concerns being able to specify any message when the required validation fails.

FabianKoestring commented 8 years ago

I think this is solved in zendframework/zend-inputfilter (2.7.0).