Quick Search:

View

Revision:

Diff

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