Reputation: 75
I am building a multi-lingual application with Zend Framework 2.
Currently, I have every object with a translatable output implement the TranslatorAwareInterface and use the TranslatorAwareTrait. So, I'am injecting a translator instance into every form, input filter and controller object in order to translate form labels, error messages and notifications.
Is this the correct way to do it or is there a different approach which does not require to inject a translator instance into every object having a text needing a translation?
(I know I can translate validation errors by injecting a default translator to AbstractValidator, but I prefer to have my own error messages)
Upvotes: 1
Views: 492
Reputation: 2087
use doctrine module for zf2 as orm and let Doctrine extension gedmo/translatable handle the data translation https://github.com/l3pp4rd/DoctrineExtensions
To get the Translatable feature working, follow this part of the documentation: https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/zendframework2.md#note-you-may-need-to-provide-additional-settings-for-some-of-the-available-listeners
After that run the schema tool to update your database.
Upvotes: 2