Rev 186 | Rev 193 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 173 | PointedEar | 1 | <?php | 
| 2 | |||
| 186 | PointedEar | 3 | class IndexView extends \PointedEars\PHPX\View | 
| 173 | PointedEar | 4 | { | 
| 5 |   /** | ||
| 192 | PointedEar | 6 |    * @var \Zend\I18n\Translator\Translator | 
| 7 |    */ | ||
| 8 | private $_translator; | ||
| 9 | |||
| 10 |   /** | ||
| 11 |    * @var string | ||
| 12 |    */ | ||
| 13 | private $_textDomain; | ||
| 14 | |||
| 15 |   /** | ||
| 16 |    * @var string | ||
| 17 |    */ | ||
| 18 | private $_language; | ||
| 19 | |||
| 20 |   /** | ||
| 173 | PointedEar | 21 |    * Creates a new index view | 
| 22 |    * | ||
| 23 |    * @see View::__construct() | ||
| 24 |    */ | ||
| 25 | public function __construct ($template) | ||
| 26 |   { | ||
| 27 | parent::__construct('application/layouts/index/index.phtml'); | ||
| 192 | PointedEar | 28 | |
| 29 | require_once 'Zend/Loader/StandardAutoloader.php'; | ||
| 30 | $loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true)); | ||
| 31 | $loader->register(); | ||
| 32 | |||
| 33 | $translator = $this->_translator = new Zend\I18n\Translator\Translator(); | ||
| 34 |     // $translator->setCache(new Zend\Cache\Storage\*Adapter()); | ||
| 35 | $type = 'gettext'; | ||
| 36 | $base_dir = $_SERVER['DOCUMENT_ROOT'] . '/i18n/LocaleData'; | ||
| 37 | $pattern = '%s/LC_MESSAGES/%1$s.pointedears.mo'; | ||
| 38 | $text_domain = $this->_textDomain = 'de.pointedears'; | ||
| 39 | $translator->addTranslationFilePattern($type, $base_dir, $pattern, $text_domain); | ||
| 173 | PointedEar | 40 |   } | 
| 192 | PointedEar | 41 | |
| 42 |   /** | ||
| 43 |    * @param string $value | ||
| 44 |    * @return IndexView | ||
| 45 |    */ | ||
| 46 | public function setLanguage ($value) | ||
| 47 |   { | ||
| 48 | $this->_language = $value; | ||
| 49 | return $this; | ||
| 50 |   } | ||
| 51 | |||
| 52 |   /** | ||
| 53 |    * Returns the translation of the parameter, if any, | ||
| 54 |    * using Zend Framework 2.1 Translate | ||
| 55 |    * | ||
| 56 |    * @param string $s | ||
| 57 |    * @return string | ||
| 58 |    */ | ||
| 59 | function _ ($s) | ||
| 60 |   { | ||
| 61 | return $this->_translator->translate($s, $this->_textDomain, $this->_language); | ||
| 62 |   } | ||
| 173 | PointedEar | 63 | } |