Reputation: 173
I've seem to waste past few hours trying to find a solution to what it seems a simple problem. Deal is simple, I want to be able to dynamically set locale to my Translator service, so
$this->translate('some string')
used in my view would return a proper translated string.
Every single solution i've found so far pointed to a simple snippet of code
in Module::onBoostrap()
$e->getApplication()->getServiceManager()->get('Translator')->setLocale('some_LOCALE');
It gives no errors, no warnings, runs smoothly with just one exception, it doesn't affect anything, the line above ( translate helper ) still uses locale defined in module.config.php, I've tried numerous a million approaches, trying to set a locale through different parts of the MVC ( god forbid I've even tried to change it directly in my view using:
$this->plugin('translate')->getTranslator()->setLocale('some_LOCALE')
So to sum up: translator works properly when locale is set from module config, setting it anywhere else doesn't seem to have any effect whatsoever.
Any help, tip, advice, pointer to a solution would be very appriciated.
Thanks in advance
Upvotes: 0
Views: 1013
Reputation: 173
I'm answering myself because that's why. And answer is: For some reason which is far beyond my comprehension about ZendFramework, my instance of it decided to use service MvcTranslator instead of Translator, my idea of why it may happened points to not haveing php-intl installed, but that's a blind guess.
For future generations:
$e->getApplication()->getServiceManager()->get('MvcTranslator')->setLocale('some_LOCALE');
That one worked as expected for me.
Upvotes: 3