Formulaire : étape 5, rajout internationalisation
[zf2.biz/galerie.git] / module / Galerie / src / Galerie / Form / GalerieForm.php
1 <?php
2
3 namespace Galerie\Form;
4
5 use Zend\Form\Form;
6
7 use Zend\I18n\Translator\TranslatorAwareInterface;
8 use Zend\I18n\Translator\Translator;
9
10
11 class GalerieForm extends Form implements TranslatorAwareInterface
12 {
13
14     private $_translator;
15     private $_textDomain = 'galerie';
16     private $_translator_enabled = true; 
17
18
19     public function initialize()
20     {
21         $this->setAttribute('method', 'post');
22         $this->add(array(
23             'name' => 'id',
24             'attributes' => array(
25                 'type' => 'hidden',
26             ),
27         ));
28         $this->add(array(
29             'name' => 'name',
30             'attributes' => array(
31                 'type' => 'text',
32             ),
33             'options' => array(
34                 'label' => $this->translate('Galerie_form_label_name'),
35             )
36         ));
37         $this->add(array(
38             'name' => 'description',
39             'attributes' => array(
40                 'type' => 'text',
41             ),
42             'options' => array(
43                 'label' => $this->translate('Galerie_form_label_description'),
44             )
45         ));
46         $this->add(array(
47             'name' => 'submit',
48             'attributes' => array(
49                 'type' => 'submit',
50                 'value' => 'Valider',
51                 'id' => 'submit_galerie_form',
52             ),
53         ));
54     }
55
56
57
58
59     public function translate($k)
60     {
61         if ($this->_translator && $this->_translator_enabled) {
62             return $this->_translator->translate($k, $this->_textDomain);
63         }
64         return $k . '(Non traduit)';
65     }
66
67
68     public function setTranslator(Translator $translator = null, $textDomain = null)
69     {
70         $this->_translator = $translator;
71         $this->_textDomain = $textDomain;
72     }
73
74     public function getTranslator()
75     {
76         return $this->_translator;
77     }
78
79     public function hasTranslator()
80     {
81         return $this->_translator !== null;
82     }
83
84     public function setTranslatorEnabled($enabled = true)
85     {
86         $this->_translator_enabled = $enabed;
87     }
88
89     public function isTranslatorEnabled()
90     {
91         return $this->_translator_enabled;
92     }
93
94     public function setTranslatorTextDomain($textDomain = 'default')
95     {
96         $this->_textDomain = $textDomain;
97     }
98
99     public function getTranslatorTextDomain()
100     {
101         return $this->_textDomain;
102     }
103
104 }