~ubuntu-branches/ubuntu/hardy/squirrelmail/hardy-updates

« back to all changes in this revision

Viewing changes to functions/i18n.php

  • Committer: Bazaar Package Importer
  • Author(s): Sam Johnston
  • Date: 2004-02-04 01:42:12 UTC
  • Revision ID: james.westby@ubuntu.com-20040204014212-ek9533qvd2vo1wa1
Tags: upstream-1.5.0
ImportĀ upstreamĀ versionĀ 1.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * functions/i18n.php
 
5
 *
 
6
 * Copyright (c) 1999-2004 The SquirrelMail Project Team
 
7
 * Licensed under the GNU GPL. For full terms see the file COPYING.
 
8
 *
 
9
 * This file contains variuos functions that are needed to do
 
10
 * internationalization of SquirrelMail.
 
11
 *
 
12
 * Internally the output character set is used. Other characters are
 
13
 * encoded using Unicode entities according to HTML 4.0.
 
14
 *
 
15
 * $Id: i18n.php,v 1.167 2004/01/29 19:38:47 tokul Exp $
 
16
 * @package squirrelmail
 
17
 */
 
18
 
 
19
/** Everything uses global.php... */
 
20
require_once(SM_PATH . 'functions/global.php');
 
21
 
 
22
/**
 
23
 * Converts string from given charset to charset, that can be displayed by user translation.
 
24
 *
 
25
 * Function by default returns html encoded strings, if translation uses different encoding.
 
26
 * If Japanese translation is used - function returns string converted to euc-jp
 
27
 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
 
28
 * If $charset is not supported - function returns unconverted string.
 
29
 * 
 
30
 * sanitizing of html tags is also done by this function.
 
31
 *
 
32
 * @param string $charset
 
33
 * @param string $string Text to be decoded
 
34
 * @return string decoded string
 
35
 */
 
36
function charset_decode ($charset, $string) {
 
37
    global $languages, $squirrelmail_language, $default_charset;
 
38
    global $use_php_recode, $use_php_iconv, $agresive_decoding;
 
39
 
 
40
    if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
 
41
        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
 
42
        $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
 
43
    }
 
44
 
 
45
    $charset = strtolower($charset);
 
46
 
 
47
    set_my_charset();
 
48
 
 
49
    // Variables that allow to use functions without function_exist() calls
 
50
    if (! isset($use_php_recode) || $use_php_recode=="" ) {
 
51
             $use_php_recode=false; }
 
52
    if (! isset($use_php_iconv) || $use_php_iconv=="" ) {
 
53
         $use_php_iconv=false; }
 
54
 
 
55
    // Don't do conversion if charset is the same.
 
56
    if ( $charset == strtolower($default_charset) )
 
57
          return htmlspecialchars($string);
 
58
 
 
59
    // catch iso-8859-8-i thing
 
60
    if ( $charset == "iso-8859-8-i" )
 
61
              $charset = "iso-8859-8";
 
62
 
 
63
    /*
 
64
     * Recode converts html special characters automatically if you use 
 
65
     * 'charset..html' decoding. There is no documented way to put -d option 
 
66
     * into php recode function call.
 
67
     */
 
68
    if ( $use_php_recode ) {
 
69
      if ( $default_charset == "utf-8" ) {
 
70
        // other charsets can be converted to utf-8 without loss.
 
71
        // and output string is smaller
 
72
        $string = recode_string($charset . "..utf-8",$string);
 
73
        return htmlspecialchars($string);
 
74
      } else {
 
75
        $string = recode_string($charset . "..html",$string);
 
76
        // recode does not convert single quote, htmlspecialchars does.
 
77
        $string = str_replace("'", '&#039;', $string);
 
78
        return $string;
 
79
      }
 
80
    }
 
81
 
 
82
    // iconv functions does not have html target and can be used only with utf-8
 
83
    if ( $use_php_iconv && $default_charset=='utf-8') {
 
84
      $string = iconv($charset,$default_charset,$string);
 
85
      return htmlspecialchars($string);
 
86
    }
 
87
 
 
88
    // If we don't use recode and iconv, we'll do it old way.
 
89
 
 
90
    /* All HTML special characters are 7 bit and can be replaced first */
 
91
    
 
92
    $string = htmlspecialchars ($string);
 
93
 
 
94
    /* controls cpu and memory intensive decoding cycles */
 
95
    if (! isset($agresive_decoding) || $agresive_decoding=="" ) {
 
96
         $agresive_decoding=false; }
 
97
 
 
98
    $decode=fixcharset($charset);
 
99
    $decodefile=SM_PATH . 'functions/decode/' . $decode . '.php';
 
100
    if (file_exists($decodefile)) {
 
101
        include_once($decodefile);
 
102
        $ret = call_user_func('charset_decode_'.$decode, $string);
 
103
    } else {
 
104
        $ret = $string;
 
105
    }
 
106
    return( $ret );
 
107
}
 
108
                                                                                                                                           
 
109
/**
 
110
 * Makes charset name suitable for decoding cycles
 
111
 *
 
112
 * @param string $charset Name of charset
 
113
 * @return string $charset Adjusted name of charset
 
114
 */
 
115
function fixcharset($charset) {
 
116
    // minus removed from function names
 
117
    $charset=str_replace('-','_',$charset);
 
118
    
 
119
    // windows-125x and cp125x charsets
 
120
    $charset=str_replace('windows_','cp',$charset);
 
121
 
 
122
    // ibm > cp
 
123
    $charset=str_replace('ibm','cp',$charset);
 
124
 
 
125
    // iso-8859-8-i -> iso-8859-8
 
126
    // use same cycle until I'll find differences
 
127
    $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
 
128
 
 
129
    return $charset;
 
130
}
 
131
 
 
132
/**
 
133
 * Set up the language to be output
 
134
 * if $do_search is true, then scan the browser information
 
135
 * for a possible language that we know
 
136
 *
 
137
 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE), 
 
138
 * gettext translation bindings and html header information.
 
139
 *
 
140
 * Function returns error codes, if there is some fatal error.
 
141
 *  0 = no error, 
 
142
 *  1 = mbstring support is not present, 
 
143
 *  2 = mbstring support is not present, user's translation reverted to en_US.
 
144
 *
 
145
 * @param string $sm_language translation used by user's interface
 
146
 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
 
147
 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
 
148
 * @return int function execution error codes. 
 
149
 */
 
150
function set_up_language($sm_language, $do_search = false, $default = false) {
 
151
 
 
152
    static $SetupAlready = 0;
 
153
    global $use_gettext, $languages,
 
154
           $squirrelmail_language, $squirrelmail_default_language,
 
155
           $sm_notAlias, $username, $data_dir;
 
156
 
 
157
    if ($SetupAlready) {
 
158
        return;
 
159
    }
 
160
 
 
161
    $SetupAlready = TRUE;
 
162
    sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE',  $accept_lang, SQ_SERVER);
 
163
 
 
164
    if ($do_search && ! $sm_language && isset($accept_lang)) {
 
165
        $sm_language = substr($accept_lang, 0, 2);
 
166
    }
 
167
    
 
168
    if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
 
169
        $squirrelmail_language = $squirrelmail_default_language;
 
170
        $sm_language = $squirrelmail_default_language;
 
171
    }
 
172
    $sm_notAlias = $sm_language;
 
173
 
 
174
    // Catching removed translation
 
175
    // System reverts to English translation if user prefs contain translation
 
176
    // that is not available in $languages array
 
177
    if (!isset($languages[$sm_notAlias])) {
 
178
      $sm_notAlias="en_US";
 
179
    }
 
180
 
 
181
    while (isset($languages[$sm_notAlias]['ALIAS'])) {
 
182
        $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
 
183
    }
 
184
 
 
185
    if ( isset($sm_language) &&
 
186
         $use_gettext &&
 
187
         $sm_language != '' &&
 
188
         isset($languages[$sm_notAlias]['CHARSET']) ) {
 
189
        bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
 
190
        textdomain( 'squirrelmail' );
 
191
        if (function_exists('bind_textdomain_codeset')) {
 
192
            if ($sm_notAlias == 'ja_JP') {
 
193
                bind_textdomain_codeset ("squirrelmail", 'EUC-JP');
 
194
            } else {
 
195
                bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
 
196
            }
 
197
        }
 
198
        if (isset($languages[$sm_notAlias]['LOCALE'])){
 
199
          $longlocale=$languages[$sm_notAlias]['LOCALE'];
 
200
        } else {
 
201
          $longlocale=$sm_notAlias;
 
202
        }
 
203
        if ( !ini_get('safe_mode') &&
 
204
             getenv( 'LC_ALL' ) != $longlocale ) {
 
205
            putenv( "LC_ALL=$longlocale" );
 
206
            putenv( "LANG=$longlocale" );
 
207
            putenv( "LANGUAGE=$longlocale" );
 
208
        }
 
209
        setlocale(LC_ALL, $longlocale);
 
210
 
 
211
        // Set text direction/alignment variables
 
212
        if (isset($languages[$sm_notAlias]['DIR']) && 
 
213
                $languages[$sm_notAlias]['DIR'] == 'rtl') {
 
214
            $text_direction='rtl';
 
215
            $left_align='right';
 
216
            $right_align='left';
 
217
        } else {
 
218
            $text_direction='ltr';
 
219
            $left_align='left';
 
220
            $right_align='right';
 
221
        }
 
222
 
 
223
        $squirrelmail_language = $sm_notAlias;
 
224
        if ($squirrelmail_language == 'ja_JP') {
 
225
            header ('Content-Type: text/html; charset=EUC-JP');
 
226
            if (!function_exists('mb_internal_encoding')) {
 
227
                // Error messages can't be displayed here
 
228
                $error = 1;
 
229
                // Revert to English if possible.
 
230
                if (function_exists('setPref')  && $username!='' && $data_dir!="") {
 
231
                    setPref($data_dir, $username, 'language', "en_US");
 
232
                    $error = 2;         
 
233
                }
 
234
                // stop further execution in order not to get php errors on mb_internal_encoding().
 
235
                return $error;
 
236
            }
 
237
            if (function_exists('mb_language')) {
 
238
                mb_language('Japanese');
 
239
            }
 
240
            mb_internal_encoding('EUC-JP');
 
241
            mb_http_output('pass');
 
242
        } else {
 
243
        header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
 
244
    }
 
245
}
 
246
    return 0;
 
247
}
 
248
 
 
249
/**
 
250
 * Sets default_charset variable according to the one that is used by user's translations.
 
251
 *
 
252
 * Function changes global $default_charset variable in order to be sure, that it
 
253
 * contains charset used by user's translation. Sanity of $squirrelmail_default_language
 
254
 * and $default_charset combination provided in SquirrelMail config is also tested.
 
255
 *
 
256
 * There can be a $default_charset setting in the
 
257
 * config.php file, but the user may have a different language
 
258
 * selected for a user interface. This function checks the
 
259
 * language selected by the user and tags the outgoing messages
 
260
 * with the appropriate charset corresponding to the language
 
261
 * selection. This is "more right" (tm), than just stamping the
 
262
 * message blindly with the system-wide $default_charset.
 
263
 */
 
264
function set_my_charset(){
 
265
    global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
 
266
 
 
267
    $my_language = getPref($data_dir, $username, 'language');
 
268
    if (!$my_language) {
 
269
        $my_language = $squirrelmail_default_language ;
 
270
    }
 
271
    // Catch removed translation
 
272
    if (!isset($languages[$my_language])) {
 
273
      $my_language="en_US";
 
274
    }
 
275
    while (isset($languages[$my_language]['ALIAS'])) {
 
276
        $my_language = $languages[$my_language]['ALIAS'];
 
277
    }
 
278
    $my_charset = $languages[$my_language]['CHARSET'];
 
279
    if ($my_charset) {
 
280
        $default_charset = $my_charset;
 
281
    }
 
282
}
 
283
 
 
284
/* ------------------------------ main --------------------------- */
 
285
 
 
286
global $squirrelmail_language, $languages, $use_gettext;
 
287
 
 
288
if (! isset($squirrelmail_language)) {
 
289
    $squirrelmail_language = '';
 
290
}
 
291
 
 
292
/**
 
293
 * Array specifies the available translations.
 
294
 *
 
295
 * Structure of array:
 
296
 * $languages['language']['variable'] = 'value'
 
297
 * 
 
298
 * Possible 'variable' names:
 
299
 *  NAME      - Translation name in English
 
300
 *  CHARSET   - Encoding used by translation
 
301
 *  ALIAS     - used when 'language' is only short name and 'value' should provide long language name
 
302
 *  ALTNAME   - Native translation name. Any 8bit symbols must be html encoded.
 
303
 *  LOCALE    - Full locale name (in xx_XX.charset format)
 
304
 *  DIR       - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
 
305
 *  XTRA_CODE - translation uses special functions. 'value' provides name of that extra function
 
306
 * 
 
307
 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
 
308
 *
 
309
 * @name $languages
 
310
 * @global $languages
 
311
 */
 
312
$languages['bg_BG']['NAME']    = 'Bulgarian';
 
313
$languages['bg_BG']['ALTNAME'] = '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;';
 
314
$languages['bg_BG']['CHARSET'] = 'windows-1251';
 
315
$languages['bg']['ALIAS'] = 'bg_BG';
 
316
 
 
317
$languages['ca_ES']['NAME']    = 'Catalan';
 
318
$languages['ca_ES']['CHARSET'] = 'iso-8859-1';
 
319
$languages['ca']['ALIAS'] = 'ca_ES';
 
320
 
 
321
$languages['cs_CZ']['NAME']    = 'Czech';
 
322
$languages['cs_CZ']['ALTNAME'] = '&#268;e&scaron;tina';
 
323
$languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
 
324
$languages['cs']['ALIAS']      = 'cs_CZ';
 
325
 
 
326
$languages['cy_GB']['NAME']    = 'Welsh';
 
327
$languages['cy_GB']['ALTNAME'] = 'Cymraeg';
 
328
$languages['cy_GB']['CHARSET'] = 'iso-8859-1';
 
329
$languages['cy']['ALIAS'] = 'cy_GB';
 
330
 
 
331
// Danish locale is da_DK.
 
332
$languages['da_DK']['NAME']    = 'Danish';
 
333
$languages['da_DK']['ALTNAME'] = 'Dansk';
 
334
$languages['da_DK']['CHARSET'] = 'iso-8859-1';
 
335
$languages['da']['ALIAS'] = 'da_DK';
 
336
 
 
337
$languages['de_DE']['NAME']    = 'German';
 
338
$languages['de_DE']['ALTNAME']    = 'Deutsch';
 
339
$languages['de_DE']['CHARSET'] = 'iso-8859-1';
 
340
$languages['de']['ALIAS'] = 'de_DE';
 
341
 
 
342
$languages['el_GR']['NAME']    = 'Greek';
 
343
$languages['el_GR']['ALTNAME'] = '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;';
 
344
$languages['el_GR']['CHARSET'] = 'iso-8859-7';
 
345
$languages['el']['ALIAS'] = 'el_GR';
 
346
 
 
347
$languages['en_GB']['NAME']    = 'British';
 
348
$languages['en_GB']['CHARSET'] = 'iso-8859-15';
 
349
$languages['en_GB']['LOCALE']  = 'en_GB.ISO-8859-15';
 
350
 
 
351
$languages['en_US']['NAME']    = 'English';
 
352
$languages['en_US']['CHARSET'] = 'iso-8859-1';
 
353
$languages['en']['ALIAS'] = 'en_US';
 
354
 
 
355
$languages['es_ES']['NAME']    = 'Spanish';
 
356
$languages['es_ES']['ALTNAME'] = 'Espa&ntilde;ol';
 
357
$languages['es_ES']['CHARSET'] = 'iso-8859-1';
 
358
$languages['es']['ALIAS'] = 'es_ES';
 
359
 
 
360
$languages['et_EE']['NAME']    = 'Estonian';
 
361
$languages['et_EE']['CHARSET'] = 'iso-8859-15';
 
362
$languages['et']['ALIAS'] = 'et_EE';
 
363
 
 
364
$languages['fo_FO']['NAME']    = 'Faroese';
 
365
$languages['fo_FO']['CHARSET'] = 'iso-8859-1';
 
366
$languages['fo']['ALIAS'] = 'fo_FO';
 
367
 
 
368
$languages['fi_FI']['NAME']    = 'Finnish';
 
369
$languages['fi_FI']['ALTNAME'] = 'Suomi';
 
370
$languages['fi_FI']['CHARSET'] = 'iso-8859-1';
 
371
$languages['fi']['ALIAS'] = 'fi_FI';
 
372
 
 
373
$languages['fr_FR']['NAME']    = 'French';
 
374
$languages['fr_FR']['ALTNAME'] = 'Fran&#231;ais';
 
375
$languages['fr_FR']['CHARSET'] = 'iso-8859-1';
 
376
$languages['fr']['ALIAS'] = 'fr_FR';
 
377
 
 
378
$languages['hr_HR']['NAME']    = 'Croatian';
 
379
$languages['hr_HR']['CHARSET'] = 'iso-8859-2';
 
380
$languages['hr']['ALIAS'] = 'hr_HR';
 
381
 
 
382
$languages['hu_HU']['NAME']    = 'Hungarian';
 
383
$languages['hu_HU']['ALTNAME'] = 'Magyar';
 
384
$languages['hu_HU']['CHARSET'] = 'iso-8859-2';
 
385
$languages['hu']['ALIAS'] = 'hu_HU';
 
386
 
 
387
$languages['id_ID']['NAME']    = 'Indonesian';
 
388
$languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
 
389
$languages['id_ID']['CHARSET'] = 'iso-8859-1';
 
390
$languages['id']['ALIAS'] = 'id_ID';
 
391
 
 
392
$languages['is_IS']['NAME']    = 'Icelandic';
 
393
$languages['is_IS']['ALTNAME'] = '&Iacute;slenska';
 
394
$languages['is_IS']['CHARSET'] = 'iso-8859-1';
 
395
$languages['is']['ALIAS'] = 'is_IS';
 
396
 
 
397
$languages['it_IT']['NAME']    = 'Italian';
 
398
$languages['it_IT']['CHARSET'] = 'iso-8859-1';
 
399
$languages['it']['ALIAS'] = 'it_IT';
 
400
 
 
401
$languages['ja_JP']['NAME']    = 'Japanese';
 
402
$languages['ja_JP']['ALTNAME'] = '&#26085;&#26412;&#35486;';
 
403
$languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
 
404
$languages['ja_JP']['LOCALE'] = 'ja_JP.EUC-JP';
 
405
$languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
 
406
$languages['ja']['ALIAS'] = 'ja_JP';
 
407
 
 
408
$languages['ko_KR']['NAME']    = 'Korean';
 
409
$languages['ko_KR']['CHARSET'] = 'euc-KR';
 
410
$languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
 
411
$languages['ko']['ALIAS'] = 'ko_KR';
 
412
 
 
413
$languages['lt_LT']['NAME']    = 'Lithuanian';
 
414
$languages['lt_LT']['ALTNAME'] = 'Lietuvi&#371;';
 
415
$languages['lt_LT']['CHARSET'] = 'utf-8';
 
416
$languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
 
417
$languages['lt']['ALIAS'] = 'lt_LT';
 
418
 
 
419
$languages['nl_NL']['NAME']    = 'Dutch';
 
420
$languages['nl_NL']['ALTNAME'] = 'Nederlands';
 
421
$languages['nl_NL']['CHARSET'] = 'iso-8859-1';
 
422
$languages['nl']['ALIAS'] = 'nl_NL';
 
423
 
 
424
$languages['ms_MY']['NAME']    = 'Malay';
 
425
$languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
 
426
$languages['ms_MY']['CHARSET'] = 'iso-8859-1';
 
427
$languages['my']['ALIAS'] = 'ms_MY';
 
428
 
 
429
$languages['no_NO']['NAME']    = 'Norwegian (Bokm&aring;l)';
 
430
$languages['no_NO']['ALTNAME'] = 'Norsk (Bokm&aring;l)';
 
431
$languages['no_NO']['CHARSET'] = 'iso-8859-1';
 
432
$languages['no']['ALIAS'] = 'no_NO';
 
433
 
 
434
$languages['nn_NO']['NAME']    = 'Norwegian (Nynorsk)';
 
435
$languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
 
436
$languages['nn_NO']['CHARSET'] = 'iso-8859-1';
 
437
 
 
438
$languages['pl_PL']['NAME']    = 'Polish';
 
439
$languages['pl_PL']['ALTNAME'] = 'Polski';
 
440
$languages['pl_PL']['CHARSET'] = 'iso-8859-2';
 
441
$languages['pl']['ALIAS'] = 'pl_PL';
 
442
 
 
443
$languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
 
444
$languages['pt_PT']['CHARSET'] = 'iso-8859-1';
 
445
$languages['pt']['ALIAS'] = 'pt_PT';
 
446
 
 
447
$languages['pt_BR']['NAME']    = 'Portuguese (Brazil)';
 
448
$languages['pt_BR']['ALTNAME'] = 'Portugu&ecirc;s do Brasil';
 
449
$languages['pt_BR']['CHARSET'] = 'iso-8859-1';
 
450
 
 
451
$languages['ro_RO']['NAME']    = 'Romanian';
 
452
$languages['ro_RO']['ALTNAME'] = 'Rom&acirc;n&#259;';
 
453
$languages['ro_RO']['CHARSET'] = 'iso-8859-2';
 
454
$languages['ro']['ALIAS'] = 'ro_RO';
 
455
 
 
456
$languages['ru_RU']['NAME']    = 'Russian';
 
457
$languages['ru_RU']['ALTNAME'] = '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;';
 
458
$languages['ru_RU']['CHARSET'] = 'utf-8';
 
459
$languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
 
460
$languages['ru']['ALIAS'] = 'ru_RU';
 
461
 
 
462
$languages['sk_SK']['NAME']     = 'Slovak';
 
463
$languages['sk_SK']['CHARSET']  = 'iso-8859-2';
 
464
$languages['sk']['ALIAS']       = 'sk_SK';
 
465
 
 
466
$languages['sl_SI']['NAME']    = 'Slovenian';
 
467
$languages['sl_SI']['ALTNAME'] = 'Sloven&scaron;&#269;ina';
 
468
$languages['sl_SI']['CHARSET'] = 'iso-8859-2';
 
469
$languages['sl']['ALIAS'] = 'sl_SI';
 
470
 
 
471
$languages['sr_YU']['NAME']    = 'Serbian';
 
472
$languages['sr_YU']['ALTNAME'] = 'Srpski';
 
473
$languages['sr_YU']['CHARSET'] = 'iso-8859-2';
 
474
$languages['sr']['ALIAS'] = 'sr_YU';
 
475
 
 
476
$languages['sv_SE']['NAME']    = 'Swedish';
 
477
$languages['sv_SE']['ALTNAME'] = 'Svenska';
 
478
$languages['sv_SE']['CHARSET'] = 'iso-8859-1';
 
479
$languages['sv']['ALIAS'] = 'sv_SE';
 
480
 
 
481
$languages['th_TH']['NAME']    = 'Thai';
 
482
$languages['th_TH']['CHARSET'] = 'tis-620';
 
483
$languages['th']['ALIAS'] = 'th_TH';
 
484
 
 
485
$languages['tr_TR']['NAME']    = 'Turkish';
 
486
$languages['tr_TR']['CHARSET'] = 'iso-8859-9';
 
487
$languages['tr']['ALIAS'] = 'tr_TR';
 
488
 
 
489
$languages['zh_TW']['NAME']    = 'Chinese Trad';
 
490
$languages['zh_TW']['CHARSET'] = 'big5';
 
491
$languages['tw']['ALIAS'] = 'zh_TW';
 
492
 
 
493
$languages['zh_CN']['NAME']    = 'Chinese Simp';
 
494
$languages['zh_CN']['CHARSET'] = 'gb2312';
 
495
$languages['cn']['ALIAS'] = 'zh_CN';
 
496
 
 
497
/*
 
498
$languages['uk_UA']['NAME']    = 'Ukrainian';
 
499
$languages['uk_UA']['CHARSET'] = 'koi8-u';
 
500
$languages['uk']['ALIAS'] = 'uk_UA';
 
501
*/
 
502
/*
 
503
if ( file_exists( SM_PATH . 'locale/vi_VN') ) {
 
504
    $languages['vi_VN']['NAME']    = 'Vietnamese';
 
505
    $languages['vi_VN']['CHARSET'] = 'utf-8';
 
506
    $languages['vi']['ALIAS'] = 'vi_VN';
 
507
}
 
508
*/
 
509
 
 
510
// Right to left languages
 
511
$languages['ar']['NAME']    = 'Arabic';
 
512
$languages['ar']['CHARSET'] = 'windows-1256';
 
513
$languages['ar']['DIR']     = 'rtl';
 
514
 
 
515
$languages['he_IL']['NAME']    = 'Hebrew';
 
516
$languages['he_IL']['CHARSET'] = 'windows-1255';
 
517
$languages['he_IL']['DIR']     = 'rtl';
 
518
$languages['he']['ALIAS']      = 'he_IL';
 
519
 
 
520
/* Detect whether gettext is installed. */
 
521
$gettext_flags = 0;
 
522
if (function_exists('_')) {
 
523
    $gettext_flags += 1;
 
524
}
 
525
if (function_exists('bindtextdomain')) {
 
526
    $gettext_flags += 2;
 
527
}
 
528
if (function_exists('textdomain')) {
 
529
    $gettext_flags += 4;
 
530
}
 
531
 
 
532
/* If gettext is fully loaded, cool */
 
533
if ($gettext_flags == 7) {
 
534
    $use_gettext = true;
 
535
}
 
536
/* If we can fake gettext, try that */
 
537
elseif ($gettext_flags == 0) {
 
538
    $use_gettext = true;
 
539
    include_once(SM_PATH . 'functions/gettext.php');
 
540
} else {
 
541
    /* Uh-ho.  A weird install */
 
542
    if (! $gettext_flags & 1) {
 
543
        function _($str) {
 
544
            return $str;
 
545
        }
 
546
    }
 
547
    if (! $gettext_flags & 2) {
 
548
        function bindtextdomain() {
 
549
            return;
 
550
        }
 
551
    }
 
552
    if (! $gettext_flags & 4) {
 
553
        function textdomain() {
 
554
            return;
 
555
        }
 
556
    }
 
557
}
 
558
 
 
559
 
 
560
/**
 
561
 * Japanese charset extra function
 
562
 *
 
563
 * Action performed by function is defined by first argument.
 
564
 * Default return value is defined by second argument.
 
565
 * Use of third argument depends on action.
 
566
 *
 
567
 * @param string action performed by this function. 
 
568
 *    possible values:
 
569
 *      decode - convert returned string to euc-jp. third argument unused
 
570
 *      encode - convert returned string to jis. third argument unused
 
571
 *      strimwidth - third argument=$width. trims string to $width symbols.
 
572
 *      encodeheader - create base64 encoded header in iso-2022-jp. third argument unused
 
573
 *      decodeheader - return human readable string from mime header. string is returned in euc-jp. third argument unused
 
574
 *      downloadfilename - third argument $useragent. Arguments provide browser info. Returns shift-jis or euc-jp encoded file name
 
575
 *      wordwrap - third argument=$wrap. wraps text at $wrap symbols
 
576
 *      utf7-imap_encode - returns string converted from euc-jp to utf7-imap. third argument unused
 
577
 *      utf7-imap_decode - returns string converted from utf7-imap to euc-jp. third argument unused
 
578
 * @param string default return value
 
579
 */
 
580
function japanese_charset_xtra() {
 
581
    $ret = func_get_arg(1);  /* default return value */
 
582
    if (function_exists('mb_detect_encoding')) {
 
583
        switch (func_get_arg(0)) { /* action */
 
584
        case 'decode':
 
585
            $detect_encoding = @mb_detect_encoding($ret);
 
586
            if ($detect_encoding == 'JIS' ||
 
587
                $detect_encoding == 'EUC-JP' ||
 
588
                $detect_encoding == 'SJIS' ||
 
589
                $detect_encoding == 'UTF-8') {
 
590
                
 
591
                $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
 
592
            }
 
593
            break;
 
594
        case 'encode':
 
595
            $detect_encoding = @mb_detect_encoding($ret);
 
596
            if ($detect_encoding == 'JIS' ||
 
597
                $detect_encoding == 'EUC-JP' ||
 
598
                $detect_encoding == 'SJIS' ||
 
599
                $detect_encoding == 'UTF-8') {
 
600
                
 
601
                $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
 
602
            }
 
603
            break;
 
604
        case 'strimwidth':
 
605
            $width = func_get_arg(2);
 
606
            $ret = mb_strimwidth($ret, 0, $width, '...'); 
 
607
            break;
 
608
        case 'encodeheader':
 
609
            $result = '';
 
610
            if (strlen($ret) > 0) {
 
611
                $tmpstr = mb_substr($ret, 0, 1);
 
612
                $prevcsize = strlen($tmpstr);
 
613
                for ($i = 1; $i < mb_strlen($ret); $i++) {
 
614
                    $tmp = mb_substr($ret, $i, 1);
 
615
                    if (strlen($tmp) == $prevcsize) {
 
616
                        $tmpstr .= $tmp;
 
617
                    } else {
 
618
                        if ($prevcsize == 1) {
 
619
                            $result .= $tmpstr;
 
620
                        } else {
 
621
                            $result .= str_replace(' ', '', 
 
622
                                                   mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
 
623
                        }
 
624
                        $tmpstr = $tmp;
 
625
                        $prevcsize = strlen($tmp);
 
626
                    }
 
627
                }
 
628
                if (strlen($tmpstr)) {
 
629
                    if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
 
630
                        $result .= $tmpstr;
 
631
                    else
 
632
                        $result .= str_replace(' ', '',
 
633
                                               mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
 
634
                }
 
635
            }
 
636
            $ret = $result;
 
637
            break;
 
638
        case 'decodeheader':
 
639
            $ret = str_replace("\t", "", $ret);
 
640
            if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
 
641
                $ret = @mb_decode_mimeheader($ret);
 
642
            $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
 
643
            break;
 
644
        case 'downloadfilename':
 
645
            $useragent = func_get_arg(2);
 
646
            if (strstr($useragent, 'Windows') !== false ||
 
647
                strstr($useragent, 'Mac_') !== false) {
 
648
                $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
 
649
            } else {
 
650
                $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
 
651
}
 
652
            break;
 
653
        case 'wordwrap':
 
654
            $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
 
655
                "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
 
656
                "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
 
657
                "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
 
658
                "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
 
659
                "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
 
660
                "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
 
661
                "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
 
662
            $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
 
663
                "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
 
664
            $wrap = func_get_arg(2);
 
665
            
 
666
            if (strlen($ret) >= $wrap && 
 
667
                substr($ret, 0, 1) != '>' &&
 
668
                strpos($ret, 'http://') === FALSE &&
 
669
                strpos($ret, 'https://') === FALSE &&
 
670
                strpos($ret, 'ftp://') === FALSE) {
 
671
                
 
672
                $ret = mb_convert_kana($ret, "KV");
 
673
 
 
674
                $line_new = '';
 
675
                $ptr = 0;
 
676
                
 
677
                while ($ptr < strlen($ret) - 1) {
 
678
                    $l = mb_strcut($ret, $ptr, $wrap);
 
679
                    $ptr += strlen($l);
 
680
                    $tmp = $l;
 
681
                    
 
682
                    $l = mb_strcut($ret, $ptr, 2);
 
683
                    while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
 
684
                        $tmp .= $l;
 
685
                        $ptr += strlen($l);
 
686
                        $l = mb_strcut($ret, $ptr, 1);
 
687
                    }
 
688
                    $line_new .= $tmp;
 
689
                    if ($ptr < strlen($ret) - 1)
 
690
                        $line_new .= "\n";
 
691
                }
 
692
                $ret = $line_new;
 
693
            }
 
694
            break;
 
695
        case 'utf7-imap_encode':
 
696
            $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
 
697
            break;
 
698
        case 'utf7-imap_decode':
 
699
            $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
 
700
            break;
 
701
        }
 
702
    }
 
703
    return $ret;
 
704
}
 
705
 
 
706
 
 
707
/**
 
708
 * Korean charset extra functions
 
709
 *
 
710
 * Action performed by function is defined by first argument.
 
711
 * Default return value is defined by second argument.
 
712
 *
 
713
 * @param string action performed by this function. 
 
714
 *    possible values:
 
715
 *      downloadfilename - Hangul(Korean Character) Attached File Name Fix.
 
716
 * @param string default return value
 
717
 */
 
718
function korean_charset_xtra() {
 
719
    
 
720
    $ret = func_get_arg(1);  /* default return value */
 
721
    if (func_get_arg(0) == 'downloadfilename') { /* action */
 
722
        $ret = str_replace("\x0D\x0A", '', $ret);  /* Hanmail's CR/LF Clear */
 
723
        for ($i=0;$i<strlen($ret);$i++) {
 
724
            if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") {   /* 0xA1 - 0XFE are Valid */
 
725
                $i++;
 
726
                continue;
 
727
            } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
 
728
                       ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
 
729
                       ($ret[$i] == '.') || ($ret[$i] == '-')) {
 
730
                continue;
 
731
            } else {
 
732
                $ret[$i] = '_';
 
733
            }
 
734
        }
 
735
 
 
736
    }
 
737
    return $ret;
 
738
}
 
739
 
 
740
/**
 
741
 * Replaces non-braking spaces inserted by some browsers with regular space
 
742
 * 
 
743
 * This function can be used to replace non-braking space symbols 
 
744
 * that are inserted in forms by some browsers instead of normal 
 
745
 * space symbol.
 
746
 *
 
747
 * @param string $string Text that needs to be cleaned
 
748
 * @param string $charset Charset used in text
 
749
 * @return string Cleaned text
 
750
 */
 
751
function cleanup_nbsp($string,$charset) {
 
752
 
 
753
  // reduce number of case statements
 
754
  if (stristr('iso-8859-',substr($charset,0,9))){
 
755
    $output_charset="iso-8859-x";
 
756
  }
 
757
  if (stristr('windows-125',substr($charset,0,11))){
 
758
    $output_charset="cp125x";
 
759
  }
 
760
  if (stristr('koi8',substr($charset,0,4))){
 
761
    $output_charset="koi8-x";
 
762
  }
 
763
  if (! isset($output_charset)){
 
764
    $output_charset=strtolower($charset);
 
765
  }
 
766
 
 
767
// where is non-braking space symbol
 
768
switch($output_charset):
 
769
 case "iso-8859-x":
 
770
 case "cp125x":
 
771
 case "iso-2022-jp":
 
772
  $nbsp="\xA0";
 
773
  break;
 
774
 case "koi8-x":
 
775
   $nbsp="\x9A";
 
776
   break;
 
777
 case "utf-8":
 
778
   $nbsp="\xC2\xA0";
 
779
   break;
 
780
 default:
 
781
   // don't change string if charset is unmatched
 
782
   return $string;
 
783
endswitch;
 
784
 
 
785
// return space instead of non-braking space. 
 
786
 return str_replace($nbsp,' ',$string);
 
787
}
 
788
 
 
789
/**
 
790
 * Function informs if it is safe to convert given charset to the one that is used by user.
 
791
 *
 
792
 * It is safe to use conversion only if user uses utf-8 encoding and when 
 
793
 * converted charset is similar to the one that is used by user.
 
794
 *
 
795
 * @param string $input_charset Charset of text that needs to be converted
 
796
 * @return bool is it possible to convert to user's charset
 
797
 */
 
798
function is_conversion_safe($input_charset) {
 
799
  global $languages, $sm_notAlias, $default_charset;
 
800
 
 
801
 // convert to lower case
 
802
 $input_charset = strtolower($input_charset);
 
803
 
 
804
 // Is user's locale Unicode based ?
 
805
 if ( $default_charset == "utf-8" ) {
 
806
   return true;
 
807
 }
 
808
 
 
809
 // Charsets that are similar
 
810
switch ($default_charset):
 
811
case "windows-1251":
 
812
      if ( $input_charset == "iso-8859-5" || 
 
813
           $input_charset == "koi8-r" ||
 
814
           $input_charset == "koi8-u" ) {
 
815
        return true;
 
816
     } else {
 
817
        return false;
 
818
     }
 
819
case "windows-1257":
 
820
  if ( $input_charset == "iso-8859-13" || 
 
821
         $input_charset == "iso-8859-4" ) {
 
822
    return true;
 
823
  } else {
 
824
    return false;
 
825
  }
 
826
case "iso-8859-4":
 
827
  if ( $input_charset == "iso-8859-13" || 
 
828
         $input_charset == "windows-1257" ) {
 
829
     return true;
 
830
  } else {
 
831
     return false;
 
832
  }
 
833
case "iso-8859-5":
 
834
  if ( $input_charset == "windows-1251" || 
 
835
         $input_charset == "koi8-r" || 
 
836
         $input_charset == "koi8-u" ) {
 
837
     return true;
 
838
  } else {
 
839
     return false;
 
840
  }
 
841
case "iso-8859-13":
 
842
  if ( $input_charset == "iso-8859-4" ||
 
843
       $input_charset == "windows-1257" ) {
 
844
     return true;
 
845
  } else {
 
846
     return false;
 
847
  }
 
848
case "koi8-r":
 
849
  if ( $input_charset == "windows-1251" ||
 
850
         $input_charset == "iso-8859-5" || 
 
851
         $input_charset == "koi8-u" ) {
 
852
     return true;
 
853
  } else {
 
854
     return false;
 
855
  }
 
856
case "koi8-u":
 
857
  if ( $input_charset == "windows-1251" ||
 
858
        $input_charset == "iso-8859-5" ||
 
859
        $input_charset == "koi8-r" ) {
 
860
     return true;
 
861
  } else {
 
862
     return false;
 
863
  }
 
864
default:
 
865
   return false;
 
866
endswitch;
 
867
}
 
868
?>
 
 
b'\\ No newline at end of file'