Quick Search:

View

Revision:

Diff

Diff from 448 to:

Annotations

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

Annotated File View

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