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

Commit

Permalink
Use dummy translator when no translator is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Sep 12, 2013
1 parent 3bd643a commit e5e7e65
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
29 changes: 29 additions & 0 deletions library/Zend/Mvc/I18n/DummyTranslator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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
{
/**
* translate(): defined by ValidatorTranslatorInterface()
*
* @see ValidatorTranslatorInterface::translate()
* @param string $message
* @param string $textDomain
* @param string $locale
* @return string
*/
public function translate($message, $textDomain = 'default', $locale = null)
{
return $message;
}
}
8 changes: 7 additions & 1 deletion library/Zend/Mvc/Service/TranslatorServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;

Expand All @@ -22,7 +23,12 @@ class TranslatorServiceFactory extends I18nTranslatorServiceFactory
public function createService(ServiceLocatorInterface $serviceLocator)
{
// Configure the translator
$config = $serviceLocator->get('Config');
$config = $serviceLocator->get('Config');

if (!isset($config['translator']) || !class_exists('Zend\I18n\Translator')) {
return new DummyTranslator();
}

$trConfig = isset($config['translator']) ? $config['translator'] : array();
$translator = Translator::factory($trConfig);
return $translator;
Expand Down

0 comments on commit e5e7e65

Please sign in to comment.