AlexP's answer is the best way to do this.
But the question remains, why is your method not working?
It should work. But this is not because you are in different namespaces, so you use different domains among the files. You are doing something like this:
namespace MyModule\Controller; class MyController { public function someAction() { $this->getServiceLocator()->get('translator')->translate('my text',__NAMESPACE__,$myLocale); } }
In your `module.config.php ', you probably use this namespace:
namespace MyModule; return array(
Note that in the controller example, __NAMESPACE__ is equal to MyModule\Controller . Although in the configuration file, __NAMESPACE__ is equal to MyModule . You need to fix this by passing the same value in both cases.
In other words, there are several approaches to solving this problem, for example, AlexP. But, if you configure it, any of them must have a translator domain (the key value is 'text_domain' ), if you configure it, it is equal to the domain parameter (second parameter) of the translate method when you call it.
A faster solution changes the $ domain parameter to a line in the controller file:
$this->getServiceLocator()->get('translator')->translate('my text','MyModule',$myLocale);
Another solution should be to create a constant and use it in files (controllers, views and settings).