Skip to content

Instantly share code, notes, and snippets.

@gkralik
Created February 25, 2014 11:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkralik/9207273 to your computer and use it in GitHub Desktop.
Save gkralik/9207273 to your computer and use it in GitHub Desktop.
ZF2 without ext/intl prior to 2.3.0
<?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;
}
}
<?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();
}
}
<?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