Created
February 25, 2014 11:32
-
-
Save gkralik/9207273 to your computer and use it in GitHub Desktop.
ZF2 without ext/intl prior to 2.3.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* module/Application/src/Application/I18n/DummyTranslator.php */ | |
namespace Application\I18n; | |
use Zend\I18n\Exception; | |
use Zend\I18n\Translator\Translator; | |
class DummyTranslator extends Translator | |
{ | |
/** | |
* Translator::getLocale() throws an exception if the locale is not | |
* set and ext/intl is not available. | |
* So simply do nothing here. | |
*/ | |
public function getLocale() | |
{ | |
return false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* module/Application/src/Application/I18n/DummyTranslatorServiceFactory.php */ | |
namespace Application\I18n; | |
use Zend\ServiceManager\FactoryInterface; | |
use Zend\ServiceManager\ServiceLocatorInterface; | |
class DummyTranslatorServiceFactory implements FactoryInterface | |
{ | |
/** | |
* Create service | |
* | |
* @param ServiceLocatorInterface $serviceLocator | |
* @return mixed | |
*/ | |
public function createService(ServiceLocatorInterface $serviceLocator) | |
{ | |
return new DummyTranslator(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* config/autoload/global.php */ | |
return array( | |
'service_manager' => array( | |
'factories' => array( | |
/** | |
* Override the service manager's 'MvcTranslator'. ZF2 injects the MvcTranslator | |
* even if there is no 'translator' config available. | |
* This usually is no problem, but if you don't have ext/intl enabled, | |
* you cannot use some view helpers (like headTitle()), forms, etc. | |
*/ | |
'MvcTranslator' => 'Application\I18n\DummyTranslatorServiceFactory', | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment