123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- *
- * Cube Framework $Id$ JQ/llBxac2Qi2BDSApPlNuF8k1nb1C9IfVbXg/a0gjM=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2015 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.4
- */
- namespace Cube\View\Helper;
- use Cube\Translate as TranslateObject,
- Cube\Translate\Adapter\AbstractAdapter as TranslateAdapter,
- Cube\Controller\Front;
- /**
- * translate view helper
- *
- * Class Translate
- *
- * @package Cube\View\Helper
- */
- class Translate extends AbstractHelper
- {
- /**
- *
- * translate adapter used by the view helper
- *
- * @var \Cube\Translate\Adapter\AbstractAdapter
- */
- protected $_adapter;
- /**
- *
- * get translation adapter
- *
- * @return TranslateAdapter|null
- */
- public function getAdapter()
- {
- if ($this->_adapter === null) {
- $translate = Front::getInstance()->getBootstrap()->getResource('translate');
- $this->setAdapter($translate);
- }
- return $this->_adapter;
- }
- /**
- *
- * set translation adapter
- *
- * @param mixed $adapter
- *
- * @return $this
- * @throws \InvalidArgumentException
- */
- 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;
- }
- /**
- *
- * get locale
- *
- * @return string
- */
- public function getLocale()
- {
- return $this->getAdapter()->getLocale();
- }
- /**
- *
- * set locale
- *
- * @param string|\Cube\Locale $locale
- *
- * @return $this
- */
- public function setLocale($locale)
- {
- $this->getAdapter()->setLocale($locale);
- return $this;
- }
- /**
- *
- * returns translated string
- *
- * @param string $message
- *
- * @return string
- */
- public function translate($message = null)
- {
- if (!$message) {
- return '';
- }
- return $this->getAdapter()->translate($message);
- }
- }
|