123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace Cube\View\Helper;
- use Cube\Translate as TranslateObject,
- Cube\Translate\Adapter\AbstractAdapter as TranslateAdapter,
- Cube\Controller\Front;
- class Translate extends AbstractHelper
- {
-
- protected $_adapter;
-
- public function getAdapter()
- {
- if ($this->_adapter === null) {
- $translate = Front::getInstance()->getBootstrap()->getResource('translate');
- $this->setAdapter($translate);
- }
- return $this->_adapter;
- }
-
- public function setAdapter($adapter)
- {
- if ($adapter instanceof TranslateAdapter) {
- $this->_adapter = $adapter;
- }
- else if ($adapter instanceof TranslateObject) {
- $this->_adapter = $adapter->getAdapter();
- }
- else {
- throw new \InvalidArgumentException("The translation adapter set in the view helper must be of type \Cube\Translate or \Cube\Translate\Adapter.");
- }
- return $this;
- }
-
- public function getLocale()
- {
- return $this->getAdapter()->getLocale();
- }
-
- public function setLocale($locale)
- {
- $this->getAdapter()->setLocale($locale);
- return $this;
- }
-
- public function translate($message = null)
- {
- if (!$message) {
- return '';
- }
- return $this->getAdapter()->translate($message);
- }
- }
|