~sylar-developers/sylar/dev

« back to all changes in this revision

Viewing changes to sylar/classes/presentation/Format.php

  • Committer: g.giusti at giano-solutions
  • Date: 2008-05-29 17:03:55 UTC
  • Revision ID: g.giusti@giano-solutions.com-20080529170355-7as0xn2vadfpkndl
Some bugs fixed

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
 
25
25
 
 
26
import('sylar.common.locale.Locale');
 
27
import('sylar.common.locale.Language');
 
28
 
 
29
 
26
30
/**
27
31
 * Main Format Class
28
32
 * 
39
43
 
40
44
class Sylar_Format{
41
45
        
42
 
        function __construct(){
43
 
                // nothing to do at the moment
 
46
        private $localeConf;
 
47
                
 
48
        function __construct(Sylar_LocaleConfiguration $localeConf=null){
 
49
                
 
50
                if(is_null($localeConf)){
 
51
                        /** 
 
52
                         * system locale
 
53
                         * an objet to use as default sylar Locale Config
 
54
                         * 
 
55
                         * @see sylar.php
 
56
                         * 
 
57
                         */
 
58
                        $localeConf = new Sylar_LocaleConfiguration(Sylar_ConfigBox::getDefaultLocaleKey());
 
59
                }
 
60
                
 
61
                // try to switch to application locale, if isn't set use sylar locale
 
62
                if(is_null(APP_DEFAULT_LOCALE)){
 
63
                        $localeConf->switchToStandardSetting(Sylar_ConfigBox::getDefaultLocaleKey());
 
64
                }else{
 
65
                        $localeConf->switchToStandardSetting(APP_DEFAULT_LOCALE);
 
66
                }
 
67
                
 
68
                $this->setLocaleConfig($localeConf);
 
69
                
 
70
                // it prepare the language object
 
71
                $this->initializeLanguage();
 
72
                
44
73
        }
45
74
        function __destruct(){
46
75
                // nothing to do at the moment
47
76
        }
 
77
        
 
78
        
 
79
        
 
80
        
 
81
        //                                                                                                                 Setter and Getter
 
82
        //__________________________________________________________________________
 
83
        
 
84
        
 
85
        public function setLocaleConfig(Sylar_LocaleConfiguration $localeConf){
 
86
                $this->localeConf = $localeConf;
 
87
        }
 
88
        public function getLocaleConfig(){
 
89
                return $this->localeConf;
 
90
        }       
 
91
        
 
92
        /**
 
93
         * @return void
 
94
         * @param Sylar_Language $oLang
 
95
         */
 
96
        public function setLangObj(Sylar_Language $oLang){
 
97
                $this->oLang=$oLang;
 
98
        }
 
99
        /**
 
100
         * @return Sylar_Language
 
101
         */
 
102
        public function getLangObj(){
 
103
                return $this->oLang;
 
104
        }
 
105
 
 
106
        
 
107
        
 
108
        
 
109
        
 
110
        
 
111
        //                                                                                                                        Public Methods
 
112
        //__________________________________________________________________________
 
113
        
 
114
        
 
115
 
 
116
        
 
117
        
 
118
        
 
119
        
 
120
        //                                                                                                                 Protected Methods
 
121
        //__________________________________________________________________________
 
122
        
 
123
        
 
124
        /**
 
125
         * Return the code of locale in witch will be translated the page
 
126
         *
 
127
         * @return string
 
128
         */
 
129
        protected function getLocale(){
 
130
                return $this->getLocaleConfig()->getStandardSettingKey();
 
131
        }
 
132
                
 
133
        
 
134
        /**
 
135
         * Wrapper for provideText
 
136
         *
 
137
         * @see Sylar_Language
 
138
         * 
 
139
         * @return string
 
140
         * @param string $sKey
 
141
         * @param array $aReplace
 
142
         */
 
143
        protected function translate($sLabel, $aReplaceList=null){
 
144
                return $this->getLangObj()->provideText($sLabel, $aReplaceList);
 
145
        }
 
146
        
 
147
 
 
148
        /**
 
149
         * Wrapper for loadApplicationDictionary
 
150
         *
 
151
         * @see Sylar_Language
 
152
         * 
 
153
         * @return void
 
154
         * @param string $sDictName
 
155
         * @param boolean $bFlagAppend
 
156
         */
 
157
        protected function loadDictionary($sDictName, $bFlagAppend=true){
 
158
                $this->getLangObj()->loadApplicationDictionary($sDictName, $sDictName);
 
159
        }
 
160
        
 
161
 
 
162
        
 
163
        
 
164
        
 
165
        
 
166
        //                                                                                                                   Private Methods
 
167
        //__________________________________________________________________________
 
168
        
 
169
        
 
170
        
 
171
        
 
172
        /**
 
173
         * It prepare the object language for the default use in the application
 
174
         * 
 
175
         * @return void
 
176
         * @see Sylar_Language
 
177
         */
 
178
        private function initializeLanguage(){
 
179
                // Prepare Language engine
 
180
                $this->setLangObj( new Sylar_Language($this->getLocaleConfig()) );
 
181
                // Set Locale Application repository root
 
182
                if(is_null(APP_LOCALE_ROOT_FS)){
 
183
                        throw new ExceptionInSylar('Application dictionary folder not defined.', 10025);
 
184
                }
 
185
                $this->getLangObj()->setApplicationLocaleRootFs(APP_LOCALE_ROOT_FS);            
 
186
 
 
187
        }       
 
188
        
 
189
        
 
190
        
48
191
 
49
192
}
50
193