Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-31 Thread Andreas Möller
Hello Ralf,


> here you go:
> 
> 

Thanks a lot!


Best regards,

Andreas

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-30 Thread Ralf Eggert
Hi Andreas,

here you go:

-
namespace Application;

use Application\Listener\ApplicationListener;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;

class Module implements BootstrapListenerInterface
{
public function onBootstrap(EventInterface $e)
{
// attach application listener
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attachAggregate(new ApplicationListener());
}
}

-
namespace Application\Listener;

use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\I18n\Translator\Translator;
use Zend\Mvc\MvcEvent;
use Zend\Validator\AbstractValidator;

class ApplicationListener implements ListenerAggregateInterface
{
protected $listeners = array();

public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(
MvcEvent::EVENT_DISPATCH,
array($this, 'addValidatorTranslations'),
100
);
}

public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $listener) {
if ($events->detach($listener)) {
unset($this->listeners[$index]);
}
}
}

public function addValidatorTranslations(EventInterface $e)
{
$baseDir = APPLICATION_ROOT . '/module/Application/language';

$translator = Translator::factory(array(
'locale'=> 'de',
'translation_file_patterns' => array(
array(
'type'=> 'phpArray',
'base_dir'=> $baseDir,
'pattern' => 'Zend_Validate.php',
'text_domain' => 'default',
),
)
));

AbstractValidator::setDefaultTranslator($translator);
}
}

-

The APPLICATION_ROOT constant is set in my index.php to the path of the,
well, application root.

HTH,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-30 Thread Andreas Möller
Hello Ralf,


>>AbstractValidator::setDefaultTranslator($translator);

How are you attaching the listener? To what event? I don't seem to get it wired 
up correctly yet.


Best regards,

Andreas

Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-28 Thread Andreas Möller
Hello Ralf,


>AbstractValidator::setDefaultTranslator($translator);

Sort of solved my problem by specifying the default translator in this way. 
Don't like it, though.


Best regards,

Andreas

Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-28 Thread Andreas Möller
Hello Ralf,


> currently I use this code in a ListenerAggregate class to add the
> translations for validators:
> 
>   $baseDir = APPLICATION_ROOT . '/module/Application/language';
> 
>   $translator = Translator::factory(array(
>   'locale'=> 'de',
>   'translation_file_patterns' => array(
>   array(
>   'type'=> 'phpArray',
>   'base_dir'=> $baseDir,
>   'pattern' => 'Zend_Validate.php',
>   'text_domain' => 'default',
>   ),
>   )
>   ));
> 
>   AbstractValidator::setDefaultTranslator($translator);

I'm not so sure whether I should specify the translator statically. I've dug 
around in the code a bit and found the following:

* when adding inputs to the input filter using array specification, 
Zend\InputFilter\Factory::createInput() is invoked
* if a validators option is found in the array specification, 
Zend\InputFilter\Factory::createInput() iterates over the validator 
specifications
* for each validator specification, 
Zend\InputFilter\Factory::populateValidators() is called with the validator 
chain of the input as an argument
* if no validator chain exists, Zend\InputFilter\Input::getValidatorChain() 
will instantiate one, set and return it
* then, Zend\InputFilter\Factory::populateValidators() will call 
Zend\Validator\ValidatorChain::addByName() and while doing so, retrieve - and 
if the chain doesn't have one, create an instance of - a 
Zend\Validator\ValidatorPluginManager
* upon construction, Zend\Validator\ValidatorPluginManager adds an initialiser 
to itself, which should inject a translate service retrieved from the plugin 
manager itself into the validator

Problem is, my validators never have a translator injected into them.

Why, though, do I ask? What am I missing here?

> The problem I see with your gist is that I need to set the messages for
> every validator I usw. With AbstractValidator::setDefaultTranslator() I
> can set it a central point and I only need to overwrite such messages
> which are to technical and hard to understand for end users.

Actually, I'm just overriding a few messages I don't like to see, as otherwise 
the default message templates will be used.


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-27 Thread Ralf Eggert
Hi Andreas,

currently I use this code in a ListenerAggregate class to add the
translations for validators:

$baseDir = APPLICATION_ROOT . '/module/Application/language';

$translator = Translator::factory(array(
'locale'=> 'de',
'translation_file_patterns' => array(
array(
'type'=> 'phpArray',
'base_dir'=> $baseDir,
'pattern' => 'Zend_Validate.php',
'text_domain' => 'default',
),
)
));

AbstractValidator::setDefaultTranslator($translator);


The Zend_Validate.php file is the one from the /resources path within
the ZF2 installation under /vendor. It is quite handy just to copy the
needed translation files for all validators.

The problem I see with your gist is that I need to set the messages for
every validator I usw. With AbstractValidator::setDefaultTranslator() I
can set it a central point and I only need to overwrite such messages
which are to technical and hard to understand for end users.

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-27 Thread Andreas Möller
Hello Ralf,


> What do you say?

So, after having had a look at Zend\Validator\AbstractValidator, translation 
obviously occurs in the validator, why setting form error messages in the form 
*after* validation has occurred will leave form error messages untranslated.


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-27 Thread Andreas Möller
Hello Ralf,


> I know its xmas but do you have any news on this. Just again I have the
> problem with untranslated validator messages and I am starting again to
> mess around with setting messages for each validator I use.

I haven't had much of a chance to work on this over the last two to three 
weeks, but from what I have observed while working on form validation, I'm not 
so sure whether validation error messages are translated at all - unless I've 
missed some magic that should be going on behind the scenes because I've wired 
services together in an unexpected way.

Have a look at this gist, which is an excerpt of how I set up an input filter 
within a model that implements Zend\InputFilter\InputFilterAwareInterface:

* https://gist.github.com/4359801

When rendering form errors using the Zend\Form\View\Helper\FormElementErrors 
after not having entered a firstname , the message rendered will be 
FORM_USER_FIRSTNAME_EMPTY_ERROR. The render() method of the view helper doesn't 
translate any validation error messages. The point is, I'm not sure whether it 
should, or whether translation should occur in the validator. Personally, I 
think it should be done in the former, rather than the latter.

What do you say?


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-25 Thread Ralf Eggert
Hi Andreas,

Andreas Möller schrieb am 11.12.2012 16:27:
>> Yes -- the plan is to roll out 2.1 the first or second week of
>> January. As such, getting it in in the next two to three weeks would
>> be necessary if you want to hit that release.
> 
> I'll try my best!

I know its xmas but do you have any news on this. Just again I have the
problem with untranslated validator messages and I am starting again to
mess around with setting messages for each validator I use.

Best regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Marc Bennewitz
We already had message keys as translator keys previously in ZF1.
It was changed to have full messages as keys but I don't know why this
was changes. Does anyone know more about ?

Greetings
Marc

On 11.12.2012 16:07, Ralf Eggert wrote:
> Hi,
> 
>> Thoughts?
> 
> Would it be possible to use the constants in the translation files
> rather than the text messages? Instead of
> 
> "Invalid type given. String, integer or float expected" => "..."
> 
> use
> 
> Zend\I18n\Validator\Alnum::INVALID => "..."
> 
> So, when a text in the validator class is changed, then the translation
> will not automatically be broken again.
> 
> Regards,
> 
> Ralf
> 

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Andreas Möller
Hello Matthew,


> Yes -- the plan is to roll out 2.1 the first or second week of
> January. As such, getting it in in the next two to three weeks would
> be necessary if you want to hit that release.

I'll try my best!


Best regards,

Andreas

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Matthew Weier O'Phinney
On Tue, Dec 11, 2012 at 9:15 AM, Andreas Möller  wrote:
>> I like this idea. Andreas?
>
> I wouldn't mind doing this, since I'm the one who opened the issue. 
> Unfortunately, I can't tell by when I could accomplish this. Matthew, can you 
> give me some deadline by which it should be finished to make it into 2.1? 
> Before new year, I guess, when I remember the mail from Ralf asking yesterday.

Yes -- the plan is to roll out 2.1 the first or second week of
January. As such, getting it in in the next two to three weeks would
be necessary if you want to hit that release.

--
Matthew Weier O'Phinney
Project Lead| matt...@zend.com
Zend Framework  | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Matthew Weier O'Phinney
On Tue, Dec 11, 2012 at 9:14 AM, Andreas Möller  wrote:
>> Would it be possible to use the constants in the translation files
>> rather than the text messages? Instead of
>>
>> "Invalid type given. String, integer or float expected" => "..."
>>
>> use
>>
>> Zend\I18n\Validator\Alnum::INVALID => "..."
>>
>> So, when a text in the validator class is changed, then the translation
>> will not automatically be broken again.
>
> While this is probably a great idea in terms of maintainability, I'm not so 
> sure about the mechanism that loads the translations. Will the translation 
> files only be loaded when I use the specific validator? If not, using the 
> constants will load all the validator classes, when the translation files are 
> loaded, no?

IIRC, the constants are supposed to be used as translation keys;
however, please check with DASPRiD, cgmartin, and Bakura to be sure
(or look int the source of the form element errors view helper). If
this is the case, it makes the old files doubly broken.

--
Matthew Weier O'Phinney
Project Lead| matt...@zend.com
Zend Framework  | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Andreas Möller
Hello Ralf,


> I like this idea. Andreas?

I wouldn't mind doing this, since I'm the one who opened the issue. 
Unfortunately, I can't tell by when I could accomplish this. Matthew, can you 
give me some deadline by which it should be finished to make it into 2.1? 
Before new year, I guess, when I remember the mail from Ralf asking yesterday.


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Andreas Möller
Hello Ralf,


> Would it be possible to use the constants in the translation files
> rather than the text messages? Instead of
> 
> "Invalid type given. String, integer or float expected" => "..."
> 
> use
> 
> Zend\I18n\Validator\Alnum::INVALID => "..."
> 
> So, when a text in the validator class is changed, then the translation
> will not automatically be broken again.

While this is probably a great idea in terms of maintainability, I'm not so 
sure about the mechanism that loads the translations. Will the translation 
files only be loaded when I use the specific validator? If not, using the 
constants will load all the validator classes, when the translation files are 
loaded, no?


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Matthew Weier O'Phinney
On Tue, Dec 11, 2012 at 9:07 AM, Ralf Eggert  wrote:
>> Thoughts?
>
> Would it be possible to use the constants in the translation files
> rather than the text messages? Instead of
>
> "Invalid type given. String, integer or float expected" => "..."
>
> use
>
> Zend\I18n\Validator\Alnum::INVALID => "..."
>
> So, when a text in the validator class is changed, then the translation
> will not automatically be broken again.

I like this idea. Andreas?

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Ralf Eggert
Hi,

> Thoughts?

Would it be possible to use the constants in the translation files
rather than the text messages? Instead of

"Invalid type given. String, integer or float expected" => "..."

use

Zend\I18n\Validator\Alnum::INVALID => "..."

So, when a text in the validator class is changed, then the translation
will not automatically be broken again.

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Matthew Weier O'Phinney
On Tue, Dec 11, 2012 at 7:42 AM, Andreas Möller  wrote:
>>> Seems that the translation files need a big update, then, in the first 
>>> place. I'll have a look into this later.
>>
>> Yep. Would be great if youn could sort that out. Anyway, why is the file
>> called Zend_Validate.php and not Zend_Validator.php?
>
> Good question - I guess that's a remainder from porting from ZF1.
>
> The names of the old ZF1 classes are used throughout the translation files in 
> the comments as well.

I have an idea:

* Create new files named "Zend_Validator.php"
* Update the translation strings in these new files

This would keep BC for those currently using them, and we can put in
the documentation the names of the new files. Since the old files are
basically broken anyways, this would provide a migration path, and
also allow us to improve them (adding full stops, fixing grammar,
etc.).

Thoughts?


--
Matthew Weier O'Phinney
Project Lead| matt...@zend.com
Zend Framework  | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Andreas Möller
Hello Ralf,


>> Seems that the translation files need a big update, then, in the first 
>> place. I'll have a look into this later.
> 
> Yep. Would be great if youn could sort that out. Anyway, why is the file
> called Zend_Validate.php and not Zend_Validator.php?

Good question - I guess that's a remainder from porting from ZF1.

The names of the old ZF1 classes are used throughout the translation files in 
the comments as well.


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Ralf Eggert
Hi Andreas,

> Seems that the translation files need a big update, then, in the first place. 
> I'll have a look into this later.

Yep. Would be great if youn could sort that out. Anyway, why is the file
called Zend_Validate.php and not Zend_Validator.php?

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-11 Thread Andreas Möller
Hello Ralf,


thanks for your feedback!

> I personally have now problems with that full stop. But there is another
> issue which makes the messages translations useless currently.
> 
> https://github.com/zendframework/zf2/issues/2536
> 
> For example look at this file at the text for Alpha::NOT_ALPHA:
> 
> https://github.com/localheinz/zf2/blob/54fdd82023366f5d02600a38da4b8ec1f02e2939/library/Zend/I18n/Validator/Alpha.php#L38
> 
>> The input contains non alphabetic characters.
> 
> And then look at the translation for the same text:
> 
> https://github.com/localheinz/zf2/blob/54fdd82023366f5d02600a38da4b8ec1f02e2939/resources/languages/de/Zend_Validate.php#L31
> 
>> '%value%' contains non alphabetic characters.
> 
> There are a lot of these messages in the translation files which are out
> of date and which are still using a phrase like '%value%' while the
> message uses 'The input' already.
> 
> So your full stops does not brake anything that is not already broken.

Seems that the translation files need a big update, then, in the first place. 
I'll have a look into this later.

> By the way, the englisch translation file is up to date:
> 
> https://github.com/localheinz/zf2/blob/54fdd82023366f5d02600a38da4b8ec1f02e2939/resources/languages/en/Zend_Validate.php#L31


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] Adding full stops at the end of validation messages - trouble?

2012-12-10 Thread Ralf Eggert
Hi Andreas,

I personally have now problems with that full stop. But there is another
issue which makes the messages translations useless currently.

https://github.com/zendframework/zf2/issues/2536

For example look at this file at the text for Alpha::NOT_ALPHA:

https://github.com/localheinz/zf2/blob/54fdd82023366f5d02600a38da4b8ec1f02e2939/library/Zend/I18n/Validator/Alpha.php#L38

> The input contains non alphabetic characters.

And then look at the translation for the same text:

https://github.com/localheinz/zf2/blob/54fdd82023366f5d02600a38da4b8ec1f02e2939/resources/languages/de/Zend_Validate.php#L31

> '%value%' contains non alphabetic characters.

There are a lot of these messages in the translation files which are out
of date and which are still using a phrase like '%value%' while the
message uses 'The input' already.

So your full stops does not brake anything that is not already broken.

By the way, the englisch translation file is up to date:

https://github.com/localheinz/zf2/blob/54fdd82023366f5d02600a38da4b8ec1f02e2939/resources/languages/en/Zend_Validate.php#L31

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com