Quick Search:

View

Revision:

Diff

Diff from 393 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/language.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
120
3   $Id: language.php 393 2006-01-20 22:54:31Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
377
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Language {
14
15 /* Private variables */
hpdl
377
16     var $_code,
hpdl
387
17         $_languages = array(),
18         $_definitions = array();
hpdl
1
19
20 /* Class constructor */
21
22     function osC_Language() {
hpdl
199
23       global $osC_Database;
hpdl
1
24
25       $Qlanguages = $osC_Database->query('select * from :table_languages order by sort_order, name');
26       $Qlanguages->bindTable(':table_languages', TABLE_LANGUAGES);
27       $Qlanguages->setCache('languages');
28       $Qlanguages->execute();
29
30       while ($Qlanguages->next()) {
31         $this->_languages[$Qlanguages->value('code')] = array('id' => $Qlanguages->valueInt('languages_id'),
32                                                               'name' => $Qlanguages->value('name'),
hpdl
386
33                                                               'locale' => $Qlanguages->value('locale'),
34                                                               'charset' => $Qlanguages->value('charset'),
35                                                               'date_format_short' => $Qlanguages->value('date_format_short'),
36                                                               'date_format_long' => $Qlanguages->value('date_format_long'),
37                                                               'time_format' => $Qlanguages->value('time_format'),
38                                                               'text_direction' => $Qlanguages->value('text_direction'),
hpdl
1
39                                                               'image' => $Qlanguages->value('image'),
hpdl
386
40                                                               'currencies_id' => $Qlanguages->valueInt('currencies_id'),
41                                                               'numeric_separator_decimal' => $Qlanguages->value('numeric_separator_decimal'),
42                                                               'numeric_separator_thousands' => $Qlanguages->value('numeric_separator_thousands'));
hpdl
1
43       }
44
45       $Qlanguages->freeResult();
46
hpdl
377
47       $this->set();
hpdl
1
48     }
49
50 /* Public methods */
51
hpdl
387
52     function load($key) {
53       global $osC_Cache;
54
hpdl
393
55       if ($osC_Cache->read('languages-' . $this->_code . '-' . $key)) {
hpdl
387
56         $this->_definitions = array_merge($this->_definitions, $osC_Cache->getCache());
57       } else {
hpdl
393
58         $osC_XML = new osC_XML('includes/languages/' . $this->_code . '.xml');
hpdl
387
59         $osC_XML->parse();
60
61         $definitions = $osC_XML->getArray();
62
63         foreach ($definitions['language']['definitions']['definition'] as $def) {
64           if ($def['group']['VALUE'] == $key) {
65             $this->_definitions[$def['key']['VALUE']] = (string)$def['value']['VALUE'];
66           }
67         }
68
69         $osC_Cache->writeBuffer($this->_definitions);
70       }
71     }
72
73     function get($key) {
74       if (isset($this->_definitions[$key])) {
75         return $this->_definitions[$key];
76       }
77
78       return $key;
79     }
80
hpdl
377
81     function set($code = '') {
82       $this->_code = $code;
83
84       if (empty($this->_code)) {
85         if (isset($_SESSION['language'])) {
86           $this->_code = $_SESSION['language'];
87         } elseif (isset($_COOKIE['language'])) {
88           $this->_code = $_COOKIE['language'];
89         } else {
90           $this->_code = $this->getBrowserSetting();
hpdl
1
91         }
92       }
93
hpdl
377
94       if (empty($this->_code) || ($this->exists($this->_code) === false)) {
95         $this->_code = DEFAULT_LANGUAGE;
hpdl
1
96       }
97
hpdl
377
98       if (!isset($_COOKIE['language']) || (isset($_COOKIE['language']) && ($_COOKIE['language'] != $this->_code))) {
99         tep_setcookie('language', $this->_code, time()+60*60*24*90);
hpdl
1
100       }
101
hpdl
377
102       if ((isset($_SESSION['language']) === false) || (isset($_SESSION['language']) && ($_SESSION['language'] != $this->_code))) {
103         $_SESSION['language'] = $this->_code;
hpdl
1
104       }
105     }
106
hpdl
377
107     function getBrowserSetting() {
108       if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
109         $browser_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
hpdl
1
110
hpdl
377
111         $languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
112                            'bg' => 'bg|bulgarian',
113                            'br' => 'pt[-_]br|brazilian portuguese',
114                            'ca' => 'ca|catalan',
115                            'cs' => 'cs|czech',
116                            'da' => 'da|danish',
117                            'de' => 'de([-_][[:alpha:]]{2})?|german',
118                            'el' => 'el|greek',
119                            'en' => 'en([-_][[:alpha:]]{2})?|english',
120                            'es' => 'es([-_][[:alpha:]]{2})?|spanish',
121                            'et' => 'et|estonian',
122                            'fi' => 'fi|finnish',
123                            'fr' => 'fr([-_][[:alpha:]]{2})?|french',
124                            'gl' => 'gl|galician',
125                            'he' => 'he|hebrew',
126                            'hu' => 'hu|hungarian',
127                            'id' => 'id|indonesian',
128                            'it' => 'it|italian',
129                            'ja' => 'ja|japanese',
130                            'ko' => 'ko|korean',
131                            'ka' => 'ka|georgian',
132                            'lt' => 'lt|lithuanian',
133                            'lv' => 'lv|latvian',
134                            'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
135                            'no' => 'no|norwegian',
136                            'pl' => 'pl|polish',
137                            'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
138                            'ro' => 'ro|romanian',
139                            'ru' => 'ru|russian',
140                            'sk' => 'sk|slovak',
141                            'sr' => 'sr|serbian',
142                            'sv' => 'sv|swedish',
143                            'th' => 'th|thai',
144                            'tr' => 'tr|turkish',
145                            'uk' => 'uk|ukrainian',
146                            'tw' => 'zh[-_]tw|chinese traditional',
147                            'zh' => 'zh|chinese simplified');
hpdl
1
148
hpdl
377
149         foreach ($browser_languages as $browser_language) {
150           foreach ($languages as $key => $value) {
151             if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $browser_language) && $this->exists($key)) {
152               return $key;
153             }
hpdl
1
154           }
155         }
156       }
157
hpdl
377
158       return false;
hpdl
1
159     }
160
hpdl
377
161     function exists($code) {
162       return array_key_exists($code, $this->_languages);
hpdl
1
163     }
164
165     function getAll() {
166       return $this->_languages;
167     }
168
hpdl
387
169     function getData($key, $language = '') {
170       if (empty($language)) {
171         $language = $this->_code;
172       }
173
174       return $this->_languages[$language][$key];
175     }
176
hpdl
120
177     function getID() {
hpdl
377
178       return $this->_languages[$this->_code]['id'];
hpdl
1
179     }
hpdl
120
180
181     function getName() {
hpdl
377
182       return $this->_languages[$this->_code]['name'];
hpdl
120
183     }
184
185     function getCode() {
hpdl
377
186       return $this->_code;
hpdl
120
187     }
188
hpdl
386
189     function getLocale() {
190       return $this->_languages[$this->_code]['locale'];
191     }
192
193     function getCharacterSet() {
194       return $this->_languages[$this->_code]['charset'];
195     }
196
197     function getDateFormatShort() {
198       return $this->_languages[$this->_code]['date_format_short'];
199     }
200
201     function getDateFormatLong() {
202       return $this->_languages[$this->_code]['date_format_long'];
203     }
204
205     function getTimeFormat() {
206       return $this->_languages[$this->_code]['time_format'];
207     }
208
209     function getTextDirection() {
210       return $this->_languages[$this->_code]['text_direction'];
211     }
212
hpdl
120
213     function getImage() {
hpdl
377
214       return $this->_languages[$this->_code]['image'];
hpdl
120
215     }
216
hpdl
386
217     function getCurrencyID() {
218       return $this->_languages[$this->_code]['currencies_id'];
219     }
220
221     function getNumericDecimalSeparator() {
222       return $this->_languages[$this->_code]['numeric_separator_decimal'];
223     }
224
225     function getNumericThousandsSeparator() {
226       return $this->_languages[$this->_code]['numeric_separator_thousands'];
227     }
hpdl
1
228   }
229 ?>