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 | { |
||
200 | PointedEar | 27 | parent::__construct('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 | */ |
||
193 | PointedEar | 59 | public function _ ($s) |
192 | PointedEar | 60 | { |
61 | return $this->_translator->translate($s, $this->_textDomain, $this->_language); |
||
62 | } |
||
193 | PointedEar | 63 | |
64 | public function getCoverage ($seen) |
||
65 | { |
||
66 | if (!is_array($seen)) |
||
67 | { |
||
68 | return ''; |
||
69 | } |
||
70 | |||
71 | return implode(', ', |
||
72 | array_map( |
||
73 | function ($e) { |
||
74 | if (is_array($e)) |
||
75 | { |
||
76 | if ($e[1] === $e[0] + 1) |
||
77 | { |
||
78 | return implode(', ', $e); |
||
79 | } |
||
80 | |||
81 | return $e[0] . '–' . $e[1]; |
||
82 | } |
||
83 | |||
84 | return $e; |
||
85 | }, |
||
86 | $seen |
||
87 | ) |
||
88 | ); |
||
89 | } |
||
173 | PointedEar | 90 | } |