Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Make I18n component completely optional for Mvc
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Dec 15, 2013
1 parent 4e5f075 commit a3267ed
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
20 changes: 20 additions & 0 deletions library/Zend/Mvc/I18n/DummyTranslator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Mvc\I18n;

use Zend\Validator\Translator\TranslatorInterface as ValidatorTranslatorInterface;

class DummyTranslator implements ValidatorTranslatorInterface
{
public function translate($message, $textDomain = 'default', $locale = null)
{
return $message;
}
}
19 changes: 18 additions & 1 deletion library/Zend/Mvc/I18n/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
use Zend\I18n\Translator\Translator as I18nTranslator;
use Zend\Validator\Translator\TranslatorInterface as ValidatorTranslatorInterface;

class Translator extends I18nTranslator implements ValidatorTranslatorInterface
class Translator implements ValidatorTranslatorInterface
{
/**
* @var I18nTranslator
*/
protected $translator;

/**
* @param I18nTranslator $translator
*/
public function __construct(I18nTranslator $translator)
{
$this->translator = $translator;
}

public function translate($message, $textDomain = 'default', $locale = null)
{
return $this->translator->translate($message, $textDomain, $locale);
}
}
14 changes: 7 additions & 7 deletions library/Zend/Mvc/Service/TranslatorServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@

namespace Zend\Mvc\Service;

use Zend\I18n\Translator\TranslatorServiceFactory as I18nTranslatorServiceFactory;
use Zend\Mvc\I18n\DummyTranslator;
use Zend\Mvc\I18n\Translator;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Overrides the translator factory from the i18n component in order to
* replace it with the bridge class from this namespace.
*/
class TranslatorServiceFactory extends I18nTranslatorServiceFactory
class TranslatorServiceFactory
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
// Configure the translator
$config = $serviceLocator->get('Config');
$trConfig = isset($config['translator']) ? $config['translator'] : array();
$translator = Translator::factory($trConfig);
return $translator;
if (!$serviceLocator->has('translator')) {
return new DummyTranslator();
}

return new Translator($serviceLocator->get('translator'));
}
}
6 changes: 3 additions & 3 deletions library/Zend/View/HelperPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ public function injectTranslator($helper)
{
if ($helper instanceof TranslatorAwareInterface) {
$locator = $this->getServiceLocator();
if ($locator && $locator->has('MvcTranslator')) {
$helper->setTranslator($locator->get('MvcTranslator'));
} elseif ($locator && $locator->has('translator')) {
if ($locator && $locator->has('translator')) {
$helper->setTranslator($locator->get('translator'));
} elseif ($locator && $locator->has('MvcTranslator')) {
$helper->setTranslator($locator->get('MvcTranslator'));
}
}
}
Expand Down

0 comments on commit a3267ed

Please sign in to comment.