Reputation: 3527
I've been using ZF2 since alpha so I'm not entirely new. However not to disturb my current project I setup a new SkeletonApp and it's working. I've added my Translations I needed for both English and German and they are working as expected. However, the Form Error Messages are not being translated to German, or any other language.
I've read the manual but it only covers how to setup Translations based on Factories and it has no details regarding how to set up inside of the module.config.php. Just like in ZF1, ZF2 also have a resources/languages folder which contains all the Form Validation Error Messages already translated. I'd like to use those! And this is where my problem is. I have no idea how to add the configuration to make this work with all my forms.
In my module.config.php file based on the SkeletonApp it already had support for translations, so I took that configuration and added another array, assuming this would have worked.
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo'
),
array(
'type' => 'phparray',
'base_dir' => __DIR__ . '/../resources/languages',
'pattern' => '%s.php'
)
)
),
However to no avail has this worked. In my Controller I have an eventManager which is where I set my locale like this:
$self->getServiceLocator()->get('translator')->setLocale('en_US'); // change to de_DE for German
Doing this as I mentioned above does translate my text from English to German and so on.
What am I missing to make my Form Errors Translate? Thank you for any guidance you can share on this situation.
Upvotes: 0
Views: 606
Reputation: 1683
Both sources use the same text domain, with the gettext source having the higher priority. This means that it will load your locale from the gettext source and then stop, since the locale + text domain combination is already loaded.
Solution: Use different text domains for each source.
Upvotes: 1