Rev 193 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 200 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | class IndexView extends \PointedEars\PHPX\View |
3 | class IndexView extends \PointedEars\PHPX\View |
4 | {
|
4 | {
|
5 | /**
|
5 | /**
|
6 | * @var \Zend\I18n\Translator\Translator
|
6 | * @var \Zend\I18n\Translator\Translator
|
7 | */
|
7 | */
|
8 | private $_translator; |
8 | private $_translator; |
9 | 9 | ||
10 | /**
|
10 | /**
|
11 | * @var string
|
11 | * @var string
|
12 | */
|
12 | */
|
13 | private $_textDomain; |
13 | private $_textDomain; |
14 | 14 | ||
15 | /**
|
15 | /**
|
16 | * @var string
|
16 | * @var string
|
17 | */
|
17 | */
|
18 | private $_language; |
18 | private $_language; |
19 | 19 | ||
20 | /**
|
20 | /**
|
21 | * Creates a new index view
|
21 | * Creates a new index view
|
22 | *
|
22 | *
|
23 | * @see View::__construct()
|
23 | * @see View::__construct()
|
24 | */
|
24 | */
|
25 | public function __construct ($template) |
25 | public function __construct ($template) |
26 | {
|
26 | {
|
27 | parent::__construct('application/layouts/index/index.phtml'); |
27 | parent::__construct('layouts/index/index.phtml'); |
28 | 28 | ||
29 | require_once 'Zend/Loader/StandardAutoloader.php'; |
29 | require_once 'Zend/Loader/StandardAutoloader.php'; |
30 | $loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true)); |
30 | $loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true)); |
31 | $loader->register(); |
31 | $loader->register(); |
32 | 32 | ||
33 | $translator = $this->_translator = new Zend\I18n\Translator\Translator(); |
33 | $translator = $this->_translator = new Zend\I18n\Translator\Translator(); |
34 | // $translator->setCache(new Zend\Cache\Storage\*Adapter());
|
34 | // $translator->setCache(new Zend\Cache\Storage\*Adapter());
|
35 | $type = 'gettext'; |
35 | $type = 'gettext'; |
36 | $base_dir = $_SERVER['DOCUMENT_ROOT'] . '/i18n/LocaleData'; |
36 | $base_dir = $_SERVER['DOCUMENT_ROOT'] . '/i18n/LocaleData'; |
37 | $pattern = '%s/LC_MESSAGES/%1$s.pointedears.mo'; |
37 | $pattern = '%s/LC_MESSAGES/%1$s.pointedears.mo'; |
38 | $text_domain = $this->_textDomain = 'de.pointedears'; |
38 | $text_domain = $this->_textDomain = 'de.pointedears'; |
39 | $translator->addTranslationFilePattern($type, $base_dir, $pattern, $text_domain); |
39 | $translator->addTranslationFilePattern($type, $base_dir, $pattern, $text_domain); |
40 | }
|
40 | }
|
41 | 41 | ||
42 | /**
|
42 | /**
|
43 | * @param string $value
|
43 | * @param string $value
|
44 | * @return IndexView
|
44 | * @return IndexView
|
45 | */
|
45 | */
|
46 | public function setLanguage ($value) |
46 | public function setLanguage ($value) |
47 | {
|
47 | {
|
48 | $this->_language = $value; |
48 | $this->_language = $value; |
49 | return $this; |
49 | return $this; |
50 | }
|
50 | }
|
51 | 51 | ||
52 | /**
|
52 | /**
|
53 | * Returns the translation of the parameter, if any,
|
53 | * Returns the translation of the parameter, if any,
|
54 | * using Zend Framework 2.1 Translate
|
54 | * using Zend Framework 2.1 Translate
|
55 | *
|
55 | *
|
56 | * @param string $s
|
56 | * @param string $s
|
57 | * @return string
|
57 | * @return string
|
58 | */
|
58 | */
|
59 | public function _ ($s) |
59 | public function _ ($s) |
60 | {
|
60 | {
|
61 | return $this->_translator->translate($s, $this->_textDomain, $this->_language); |
61 | return $this->_translator->translate($s, $this->_textDomain, $this->_language); |
62 | }
|
62 | }
|
63 | 63 | ||
64 | public function getCoverage ($seen) |
64 | public function getCoverage ($seen) |
65 | {
|
65 | {
|
66 | if (!is_array($seen)) |
66 | if (!is_array($seen)) |
67 | {
|
67 | {
|
68 | return ''; |
68 | return ''; |
69 | }
|
69 | }
|
70 | 70 | ||
71 | return implode(', ', |
71 | return implode(', ', |
72 | array_map( |
72 | array_map( |
73 | function ($e) { |
73 | function ($e) { |
74 | if (is_array($e)) |
74 | if (is_array($e)) |
75 | {
|
75 | {
|
76 | if ($e[1] === $e[0] + 1) |
76 | if ($e[1] === $e[0] + 1) |
77 | {
|
77 | {
|
78 | return implode(', ', $e); |
78 | return implode(', ', $e); |
79 | }
|
79 | }
|
80 | 80 | ||
81 | return $e[0] . '–' . $e[1]; |
81 | return $e[0] . '–' . $e[1]; |
82 | }
|
82 | }
|
83 | 83 | ||
84 | return $e; |
84 | return $e; |
85 | }, |
85 | }, |
86 | $seen
|
86 | $seen
|
87 | )
|
87 | )
|
88 | ); |
88 | ); |
89 | }
|
89 | }
|
90 | }
|
90 | }
|