Quick Search:

View

Revision:

Diff

Diff from 386 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 386 2006-01-12 11:36:39Z 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,
17         $_languages = array();
hpdl
1
18
19 /* Class constructor */
20
21     function osC_Language() {
hpdl
199
22       global $osC_Database;
hpdl
1
23
24       $Qlanguages = $osC_Database->query('select * from :table_languages order by sort_order, name');
25       $Qlanguages->bindTable(':table_languages', TABLE_LANGUAGES);
26       $Qlanguages->setCache('languages');
27       $Qlanguages->execute();
28
29       while ($Qlanguages->next()) {
30         $this->_languages[$Qlanguages->value('code')] = array('id' => $Qlanguages->valueInt('languages_id'),
31                                                               'name' => $Qlanguages->value('name'),
hpdl
386
32                                                               'locale' => $Qlanguages->value('locale'),
33                                                               'charset' => $Qlanguages->value('charset'),
34                                                               'date_format_short' => $Qlanguages->value('date_format_short'),
35                                                               'date_format_long' => $Qlanguages->value('date_format_long'),
36                                                               'time_format' => $Qlanguages->value('time_format'),
37                                                               'text_direction' => $Qlanguages->value('text_direction'),
hpdl
1
38                                                               'image' => $Qlanguages->value('image'),
hpdl
386
39                                                               'directory' => $Qlanguages->value('directory'),
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
377
52     function set($code = '') {
53       $this->_code = $code;
54
55       if (empty($this->_code)) {
56         if (isset($_SESSION['language'])) {
57           $this->_code = $_SESSION['language'];
58         } elseif (isset($_COOKIE['language'])) {
59           $this->_code = $_COOKIE['language'];
60         } else {
61           $this->_code = $this->getBrowserSetting();
hpdl
1
62         }
63       }
64
hpdl
377
65       if (empty($this->_code) || ($this->exists($this->_code) === false)) {
66         $this->_code = DEFAULT_LANGUAGE;
hpdl
1
67       }
68
hpdl
377
69       if (!isset($_COOKIE['language']) || (isset($_COOKIE['language']) && ($_COOKIE['language'] != $this->_code))) {
70         tep_setcookie('language', $this->_code, time()+60*60*24*90);
hpdl
1
71       }
72
hpdl
377
73       if ((isset($_SESSION['language']) === false) || (isset($_SESSION['language']) && ($_SESSION['language'] != $this->_code))) {
74         $_SESSION['language'] = $this->_code;
hpdl
1
75       }
76     }
77
hpdl
377
78     function getBrowserSetting() {
79       if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
80         $browser_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
hpdl
1
81
hpdl
377
82         $languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
83                            'bg' => 'bg|bulgarian',
84                            'br' => 'pt[-_]br|brazilian portuguese',
85                            'ca' => 'ca|catalan',
86                            'cs' => 'cs|czech',
87                            'da' => 'da|danish',
88                            'de' => 'de([-_][[:alpha:]]{2})?|german',
89                            'el' => 'el|greek',
90                            'en' => 'en([-_][[:alpha:]]{2})?|english',
91                            'es' => 'es([-_][[:alpha:]]{2})?|spanish',
92                            'et' => 'et|estonian',
93                            'fi' => 'fi|finnish',
94                            'fr' => 'fr([-_][[:alpha:]]{2})?|french',
95                            'gl' => 'gl|galician',
96                            'he' => 'he|hebrew',
97                            'hu' => 'hu|hungarian',
98                            'id' => 'id|indonesian',
99                            'it' => 'it|italian',
100                            'ja' => 'ja|japanese',
101                            'ko' => 'ko|korean',
102                            'ka' => 'ka|georgian',
103                            'lt' => 'lt|lithuanian',
104                            'lv' => 'lv|latvian',
105                            'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
106                            'no' => 'no|norwegian',
107                            'pl' => 'pl|polish',
108                            'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
109                            'ro' => 'ro|romanian',
110                            'ru' => 'ru|russian',
111                            'sk' => 'sk|slovak',
112                            'sr' => 'sr|serbian',
113                            'sv' => 'sv|swedish',
114                            'th' => 'th|thai',
115                            'tr' => 'tr|turkish',
116                            'uk' => 'uk|ukrainian',
117                            'tw' => 'zh[-_]tw|chinese traditional',
118                            'zh' => 'zh|chinese simplified');
hpdl
1
119
hpdl
377
120         foreach ($browser_languages as $browser_language) {
121           foreach ($languages as $key => $value) {
122             if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $browser_language) && $this->exists($key)) {
123               return $key;
124             }
hpdl
1
125           }
126         }
127       }
128
hpdl
377
129       return false;
hpdl
1
130     }
131
hpdl
377
132     function exists($code) {
133       return array_key_exists($code, $this->_languages);
hpdl
1
134     }
135
136     function getAll() {
137       return $this->_languages;
138     }
139
hpdl
120
140     function getID() {
hpdl
377
141       return $this->_languages[$this->_code]['id'];
hpdl
1
142     }
hpdl
120
143
144     function getName() {
hpdl
377
145       return $this->_languages[$this->_code]['name'];
hpdl
120
146     }
147
148     function getCode() {
hpdl
377
149       return $this->_code;
hpdl
120
150     }
151
hpdl
386
152     function getLocale() {
153       return $this->_languages[$this->_code]['locale'];
154     }
155
156     function getCharacterSet() {
157       return $this->_languages[$this->_code]['charset'];
158     }
159
160     function getDateFormatShort() {
161       return $this->_languages[$this->_code]['date_format_short'];
162     }
163
164     function getDateFormatLong() {
165       return $this->_languages[$this->_code]['date_format_long'];
166     }
167
168     function getTimeFormat() {
169       return $this->_languages[$this->_code]['time_format'];
170     }
171
172     function getTextDirection() {
173       return $this->_languages[$this->_code]['text_direction'];
174     }
175
hpdl
120
176     function getImage() {
hpdl
377
177       return $this->_languages[$this->_code]['image'];
hpdl
120
178     }
179
180     function getDirectory() {
hpdl
377
181       return $this->_languages[$this->_code]['directory'];
hpdl
120
182     }
183
hpdl
386
184     function getCurrencyID() {
185       return $this->_languages[$this->_code]['currencies_id'];
186     }
187
188     function getNumericDecimalSeparator() {
189       return $this->_languages[$this->_code]['numeric_separator_decimal'];
190     }
191
192     function getNumericThousandsSeparator() {
193       return $this->_languages[$this->_code]['numeric_separator_thousands'];
194     }
195
hpdl
120
196     function load($definition = false) {
197       if (is_string($definition)) {
198         include('includes/languages/' . $this->getDirectory() . '/' . $definition);
199       } else {
200         include('includes/languages/' . $this->getDirectory() . '.php');
201       }
202     }
hpdl
1
203   }
204 ?>