3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Config\Processor
;
12 use Zend\Config\Config
;
13 use Zend\Config\Exception
;
14 use Zend\I18n\Translator\Translator
as ZendTranslator
;
16 class Translator
implements ProcessorInterface
21 protected $translator;
26 protected $locale = null;
31 protected $textDomain = 'default';
34 * Translator uses the supplied Zend\I18n\Translator\Translator to find
35 * and translate language strings in config.
37 * @param ZendTranslator $translator
38 * @param string $textDomain
39 * @param string|null $locale
41 public function __construct(ZendTranslator
$translator, $textDomain = 'default', $locale = null)
43 $this->setTranslator($translator);
44 $this->setTextDomain($textDomain);
45 $this->setLocale($locale);
49 * @param ZendTranslator $translator
52 public function setTranslator(ZendTranslator
$translator)
54 $this->translator
= $translator;
59 * @return ZendTranslator
61 public function getTranslator()
63 return $this->translator
;
67 * @param string|null $locale
70 public function setLocale($locale)
72 $this->locale
= $locale;
79 public function getLocale()
85 * @param string $textDomain
88 public function setTextDomain($textDomain)
90 $this->textDomain
= $textDomain;
97 public function getTextDomain()
99 return $this->textDomain
;
105 * @param Config $config
107 * @throws Exception\InvalidArgumentException
109 public function process(Config
$config)
111 if ($config->isReadOnly()) {
112 throw new Exception\
InvalidArgumentException('Cannot process config because it is read-only');
116 * Walk through config and replace values
118 foreach ($config as $key => $val) {
119 if ($val instanceof Config
) {
120 $this->process($val);
122 $config->{$key} = $this->translator
->translate($val, $this->textDomain
, $this->locale
);
130 * Process a single value
135 public function processValue($value)
137 return $this->translator
->translate($value, $this->textDomain
, $this->locale
);