hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
121
|
3
|
$Id: language.php 1767 2008-01-05 12:33:05Z frank $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
1512
|
8
|
Copyright (c) 2007 osCommerce
|
hpdl
|
1
|
9
|
|
hpdl
|
1498
|
10
|
This program is free software; you can redistribute it and/or modify
|
|
11
|
it under the terms of the GNU General Public License v2 (1991)
|
|
12
|
as published by the Free Software Foundation.
|
hpdl
|
1
|
13
|
*/
|
|
14
|
|
|
15
|
class osC_Language {
|
|
16
|
|
|
17
|
/* Private variables */
|
hpdl
|
383
|
18
|
var $_code,
|
hpdl
|
410
|
19
|
$_languages = array(),
|
|
20
|
$_definitions = array();
|
hpdl
|
1
|
21
|
|
|
22
|
/* Class constructor */
|
|
23
|
|
|
24
|
function osC_Language() {
|
hpdl
|
368
|
25
|
global $osC_Database;
|
hpdl
|
1
|
26
|
|
|
27
|
$Qlanguages = $osC_Database->query('select * from :table_languages order by sort_order, name');
|
|
28
|
$Qlanguages->bindTable(':table_languages', TABLE_LANGUAGES);
|
|
29
|
$Qlanguages->setCache('languages');
|
|
30
|
$Qlanguages->execute();
|
|
31
|
|
|
32
|
while ($Qlanguages->next()) {
|
|
33
|
$this->_languages[$Qlanguages->value('code')] = array('id' => $Qlanguages->valueInt('languages_id'),
|
hpdl
|
448
|
34
|
'code' => $Qlanguages->value('code'),
|
hpdl
|
1
|
35
|
'name' => $Qlanguages->value('name'),
|
hpdl
|
410
|
36
|
'locale' => $Qlanguages->value('locale'),
|
|
37
|
'charset' => $Qlanguages->value('charset'),
|
|
38
|
'date_format_short' => $Qlanguages->value('date_format_short'),
|
|
39
|
'date_format_long' => $Qlanguages->value('date_format_long'),
|
|
40
|
'time_format' => $Qlanguages->value('time_format'),
|
|
41
|
'text_direction' => $Qlanguages->value('text_direction'),
|
|
42
|
'currencies_id' => $Qlanguages->valueInt('currencies_id'),
|
|
43
|
'numeric_separator_decimal' => $Qlanguages->value('numeric_separator_decimal'),
|
hpdl
|
1512
|
44
|
'numeric_separator_thousands' => $Qlanguages->value('numeric_separator_thousands'),
|
|
45
|
'parent_id' => $Qlanguages->valueInt('parent_id'));
|
hpdl
|
1
|
46
|
}
|
|
47
|
|
|
48
|
$Qlanguages->freeResult();
|
|
49
|
|
hpdl
|
383
|
50
|
$this->set();
|
hpdl
|
1
|
51
|
}
|
|
52
|
|
|
53
|
/* Public methods */
|
|
54
|
|
hpdl
|
1512
|
55
|
function load($key, $language_code = null) {
|
hpdl
|
410
|
56
|
global $osC_Database;
|
|
57
|
|
hpdl
|
1512
|
58
|
if ( is_null($language_code) ) {
|
|
59
|
$language_code = $this->_code;
|
|
60
|
}
|
|
61
|
|
|
62
|
if ( $this->_languages[$language_code]['parent_id'] > 0 ) {
|
|
63
|
$this->load($key, $this->getCodeFromID($this->_languages[$language_code]['parent_id']));
|
|
64
|
}
|
|
65
|
|
hpdl
|
410
|
66
|
$Qdef = $osC_Database->query('select * from :table_languages_definitions where languages_id = :languages_id and content_group = :content_group');
|
|
67
|
$Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
frank
|
1767
|
68
|
$Qdef->bindInt(':languages_id', osC_Language::getData('id', $language_code));
|
hpdl
|
410
|
69
|
$Qdef->bindValue(':content_group', $key);
|
hpdl
|
1512
|
70
|
$Qdef->setCache('languages-' . $language_code . '-' . $key);
|
hpdl
|
410
|
71
|
$Qdef->execute();
|
|
72
|
|
|
73
|
while ($Qdef->next()) {
|
|
74
|
$this->_definitions[$Qdef->value('definition_key')] = $Qdef->value('definition_value');
|
|
75
|
}
|
|
76
|
|
|
77
|
$Qdef->freeResult();
|
|
78
|
}
|
|
79
|
|
|
80
|
function get($key) {
|
|
81
|
if (isset($this->_definitions[$key])) {
|
|
82
|
return $this->_definitions[$key];
|
|
83
|
}
|
|
84
|
|
|
85
|
return $key;
|
|
86
|
}
|
|
87
|
|
hpdl
|
383
|
88
|
function set($code = '') {
|
|
89
|
$this->_code = $code;
|
|
90
|
|
|
91
|
if (empty($this->_code)) {
|
|
92
|
if (isset($_SESSION['language'])) {
|
|
93
|
$this->_code = $_SESSION['language'];
|
|
94
|
} elseif (isset($_COOKIE['language'])) {
|
|
95
|
$this->_code = $_COOKIE['language'];
|
|
96
|
} else {
|
|
97
|
$this->_code = $this->getBrowserSetting();
|
hpdl
|
1
|
98
|
}
|
|
99
|
}
|
|
100
|
|
hpdl
|
383
|
101
|
if (empty($this->_code) || ($this->exists($this->_code) === false)) {
|
|
102
|
$this->_code = DEFAULT_LANGUAGE;
|
hpdl
|
1
|
103
|
}
|
|
104
|
|
hpdl
|
383
|
105
|
if (!isset($_COOKIE['language']) || (isset($_COOKIE['language']) && ($_COOKIE['language'] != $this->_code))) {
|
hpdl
|
757
|
106
|
osc_setcookie('language', $this->_code, time()+60*60*24*90);
|
hpdl
|
1
|
107
|
}
|
|
108
|
|
hpdl
|
383
|
109
|
if ((isset($_SESSION['language']) === false) || (isset($_SESSION['language']) && ($_SESSION['language'] != $this->_code))) {
|
|
110
|
$_SESSION['language'] = $this->_code;
|
hpdl
|
1
|
111
|
}
|
|
112
|
}
|
|
113
|
|
hpdl
|
383
|
114
|
function getBrowserSetting() {
|
|
115
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
|
116
|
$browser_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
hpdl
|
1
|
117
|
|
hpdl
|
383
|
118
|
$languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
|
|
119
|
'bg' => 'bg|bulgarian',
|
|
120
|
'br' => 'pt[-_]br|brazilian portuguese',
|
|
121
|
'ca' => 'ca|catalan',
|
|
122
|
'cs' => 'cs|czech',
|
|
123
|
'da' => 'da|danish',
|
|
124
|
'de' => 'de([-_][[:alpha:]]{2})?|german',
|
|
125
|
'el' => 'el|greek',
|
|
126
|
'en' => 'en([-_][[:alpha:]]{2})?|english',
|
|
127
|
'es' => 'es([-_][[:alpha:]]{2})?|spanish',
|
|
128
|
'et' => 'et|estonian',
|
|
129
|
'fi' => 'fi|finnish',
|
|
130
|
'fr' => 'fr([-_][[:alpha:]]{2})?|french',
|
|
131
|
'gl' => 'gl|galician',
|
|
132
|
'he' => 'he|hebrew',
|
|
133
|
'hu' => 'hu|hungarian',
|
|
134
|
'id' => 'id|indonesian',
|
|
135
|
'it' => 'it|italian',
|
|
136
|
'ja' => 'ja|japanese',
|
|
137
|
'ko' => 'ko|korean',
|
|
138
|
'ka' => 'ka|georgian',
|
|
139
|
'lt' => 'lt|lithuanian',
|
|
140
|
'lv' => 'lv|latvian',
|
|
141
|
'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
|
|
142
|
'no' => 'no|norwegian',
|
|
143
|
'pl' => 'pl|polish',
|
|
144
|
'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
|
|
145
|
'ro' => 'ro|romanian',
|
|
146
|
'ru' => 'ru|russian',
|
|
147
|
'sk' => 'sk|slovak',
|
|
148
|
'sr' => 'sr|serbian',
|
|
149
|
'sv' => 'sv|swedish',
|
|
150
|
'th' => 'th|thai',
|
|
151
|
'tr' => 'tr|turkish',
|
|
152
|
'uk' => 'uk|ukrainian',
|
|
153
|
'tw' => 'zh[-_]tw|chinese traditional',
|
|
154
|
'zh' => 'zh|chinese simplified');
|
hpdl
|
1
|
155
|
|
hpdl
|
383
|
156
|
foreach ($browser_languages as $browser_language) {
|
|
157
|
foreach ($languages as $key => $value) {
|
|
158
|
if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $browser_language) && $this->exists($key)) {
|
|
159
|
return $key;
|
|
160
|
}
|
hpdl
|
1
|
161
|
}
|
|
162
|
}
|
|
163
|
}
|
|
164
|
|
hpdl
|
383
|
165
|
return false;
|
hpdl
|
1
|
166
|
}
|
|
167
|
|
hpdl
|
383
|
168
|
function exists($code) {
|
|
169
|
return array_key_exists($code, $this->_languages);
|
hpdl
|
1
|
170
|
}
|
|
171
|
|
|
172
|
function getAll() {
|
|
173
|
return $this->_languages;
|
|
174
|
}
|
|
175
|
|
hpdl
|
410
|
176
|
function getData($key, $language = '') {
|
|
177
|
if (empty($language)) {
|
|
178
|
$language = $this->_code;
|
|
179
|
}
|
|
180
|
|
|
181
|
return $this->_languages[$language][$key];
|
|
182
|
}
|
|
183
|
|
|
184
|
function getCodeFromID($id) {
|
|
185
|
foreach ($this->_languages as $code => $lang) {
|
|
186
|
if ($lang['id'] == $id) {
|
|
187
|
return $code;
|
|
188
|
}
|
|
189
|
}
|
|
190
|
}
|
|
191
|
|
hpdl
|
121
|
192
|
function getID() {
|
hpdl
|
383
|
193
|
return $this->_languages[$this->_code]['id'];
|
hpdl
|
1
|
194
|
}
|
hpdl
|
121
|
195
|
|
|
196
|
function getName() {
|
hpdl
|
383
|
197
|
return $this->_languages[$this->_code]['name'];
|
hpdl
|
121
|
198
|
}
|
|
199
|
|
|
200
|
function getCode() {
|
hpdl
|
383
|
201
|
return $this->_code;
|
hpdl
|
121
|
202
|
}
|
|
203
|
|
hpdl
|
410
|
204
|
function getLocale() {
|
|
205
|
return $this->_languages[$this->_code]['locale'];
|
|
206
|
}
|
|
207
|
|
|
208
|
function getCharacterSet() {
|
|
209
|
return $this->_languages[$this->_code]['charset'];
|
|
210
|
}
|
|
211
|
|
hpdl
|
758
|
212
|
function getDateFormatShort($with_time = false) {
|
|
213
|
if ($with_time === true) {
|
|
214
|
return $this->_languages[$this->_code]['date_format_short'] . ' ' . $this->getTimeFormat();
|
|
215
|
}
|
|
216
|
|
hpdl
|
410
|
217
|
return $this->_languages[$this->_code]['date_format_short'];
|
|
218
|
}
|
|
219
|
|
|
220
|
function getDateFormatLong() {
|
|
221
|
return $this->_languages[$this->_code]['date_format_long'];
|
|
222
|
}
|
|
223
|
|
|
224
|
function getTimeFormat() {
|
|
225
|
return $this->_languages[$this->_code]['time_format'];
|
|
226
|
}
|
|
227
|
|
|
228
|
function getTextDirection() {
|
|
229
|
return $this->_languages[$this->_code]['text_direction'];
|
|
230
|
}
|
|
231
|
|
|
232
|
function getCurrencyID() {
|
|
233
|
return $this->_languages[$this->_code]['currencies_id'];
|
hpdl
|
121
|
234
|
}
|
|
235
|
|
hpdl
|
410
|
236
|
function getNumericDecimalSeparator() {
|
|
237
|
return $this->_languages[$this->_code]['numeric_separator_decimal'];
|
hpdl
|
121
|
238
|
}
|
hpdl
|
410
|
239
|
|
|
240
|
function getNumericThousandsSeparator() {
|
|
241
|
return $this->_languages[$this->_code]['numeric_separator_thousands'];
|
|
242
|
}
|
hpdl
|
1434
|
243
|
|
|
244
|
function showImage($code = null, $width = '16', $height = '10', $parameters = null) {
|
|
245
|
if ( empty($code) ) {
|
|
246
|
$code = $this->_code;
|
|
247
|
}
|
|
248
|
|
|
249
|
$image_code = strtolower(substr($code, 3));
|
|
250
|
|
|
251
|
if ( !is_numeric($width) ) {
|
|
252
|
$width = 16;
|
|
253
|
}
|
|
254
|
|
|
255
|
if ( !is_numeric($height) ) {
|
|
256
|
$height = 10;
|
|
257
|
}
|
|
258
|
|
|
259
|
return osc_image('images/worldflags/' . $image_code . '.png', $this->_languages[$code]['name'], $width, $height, $parameters);
|
|
260
|
}
|
hpdl
|
1
|
261
|
}
|
|
262
|
?>
|