Feeds:
Posts
Comments

Archive for May, 2014

In order to allow developer to use translator instance into validators, Zend Framework 2.2 add a new service call MvcTranslator, as quoted in documentation:

“A new service has also been registered with the MVC, MvcTranslator, which will return this specialized, bridge instance.

Most users should see no issues, as Zend\Validator\ValidatorPluginManager has been modified to use the MvcTranslator service internally, which is how most developers were getting the translator instance into validators in the first place. You will only need to change code if you were manually injecting the instance previously.”

However, we used to set the locale by a manually injected translator to allow users switching to different languages. After upgraded to 2.2.2 or later (the latest version at this time is 2.3.1), the switching languages function is no longer working properly.

In order to make sure function works properly no matter the version is, I updated the code to something like:

    public function setLocale($locale) {
        $sm = $this->getServiceLocator();
        if($sm->has("mvcTranslator")){
            $this->translator = $sm->get('mvcTranslator');
            $this->translator->setLocale($locale);
        }else if($sm->has("Translator")){
            $this->translator = $sm->get('translator');
            $this->translator->setLocale($locale);
        }
    }

Read Full Post »