Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Config / Processor / Translator.php
blobdb9691d1972b07b0dfaf5c98ffa513bddcd7b70d
1 <?php
2 /**
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
8 */
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
18 /**
19 * @var ZendTranslator
21 protected $translator;
23 /**
24 * @var string|null
26 protected $locale = null;
28 /**
29 * @var string
31 protected $textDomain = 'default';
33 /**
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);
48 /**
49 * @param ZendTranslator $translator
50 * @return Translator
52 public function setTranslator(ZendTranslator $translator)
54 $this->translator = $translator;
55 return $this;
58 /**
59 * @return ZendTranslator
61 public function getTranslator()
63 return $this->translator;
66 /**
67 * @param string|null $locale
68 * @return Translator
70 public function setLocale($locale)
72 $this->locale = $locale;
73 return $this;
76 /**
77 * @return string|null
79 public function getLocale()
81 return $this->locale;
84 /**
85 * @param string $textDomain
86 * @return Translator
88 public function setTextDomain($textDomain)
90 $this->textDomain = $textDomain;
91 return $this;
94 /**
95 * @return string
97 public function getTextDomain()
99 return $this->textDomain;
103 * Process
105 * @param Config $config
106 * @return 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);
121 } else {
122 $config->{$key} = $this->translator->translate($val, $this->textDomain, $this->locale);
126 return $config;
130 * Process a single value
132 * @param $value
133 * @return mixed
135 public function processValue($value)
137 return $this->translator->translate($value, $this->textDomain, $this->locale);