3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\I18n\View\Helper
;
12 use Zend\I18n\Translator\TranslatorInterface
as Translator
;
13 use Zend\I18n\Translator\TranslatorAwareInterface
;
14 use Zend\View\Helper\AbstractHelper
;
16 abstract class AbstractTranslatorHelper
extends AbstractHelper
implements
17 TranslatorAwareInterface
20 * Translator (optional)
24 protected $translator;
27 * Translator text domain (optional)
31 protected $translatorTextDomain = 'default';
34 * Whether translator should be used
38 protected $translatorEnabled = true;
41 * Sets translator to use in helper
43 * @param Translator $translator [optional] translator.
44 * Default is null, which sets no translator.
45 * @param string $textDomain [optional] text domain
46 * Default is null, which skips setTranslatorTextDomain
47 * @return AbstractTranslatorHelper
49 public function setTranslator(Translator
$translator = null, $textDomain = null)
51 $this->translator
= $translator;
52 if (null !== $textDomain) {
53 $this->setTranslatorTextDomain($textDomain);
60 * Returns translator used in helper
62 * @return Translator|null
64 public function getTranslator()
66 if (! $this->isTranslatorEnabled()) {
70 return $this->translator
;
74 * Checks if the helper has a translator
78 public function hasTranslator()
80 return (bool) $this->getTranslator();
84 * Sets whether translator is enabled and should be used
86 * @param bool $enabled
87 * @return AbstractTranslatorHelper
89 public function setTranslatorEnabled($enabled = true)
91 $this->translatorEnabled
= (bool) $enabled;
96 * Returns whether translator is enabled and should be used
100 public function isTranslatorEnabled()
102 return $this->translatorEnabled
;
106 * Set translation text domain
108 * @param string $textDomain
109 * @return AbstractTranslatorHelper
111 public function setTranslatorTextDomain($textDomain = 'default')
113 $this->translatorTextDomain
= $textDomain;
118 * Return the translation text domain
122 public function getTranslatorTextDomain()
124 return $this->translatorTextDomain
;