Partial support for IMAP LOgin Referrals: tell the user what's going on
[squirrelmail.git] / functions / i18n.php
CommitLineData
59177427 1<?php
35586184 2/**
d3bab52e 3 * SquirrelMail internationalization functions
35586184 4 *
6c84ba1e 5 * Copyright (c) 1999-2005 The SquirrelMail Project Team
35586184 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This file contains variuos functions that are needed to do
9 * internationalization of SquirrelMail.
10 *
11 * Internally the output character set is used. Other characters are
12 * encoded using Unicode entities according to HTML 4.0.
13 *
a8a1c36d 14 * @version $Id$
d6c32258 15 * @package squirrelmail
a8a1c36d 16 * @subpackage i18n
35586184 17 */
18
d6c32258 19/** Everything uses global.php... */
961ca3d8 20require_once(SM_PATH . 'functions/global.php');
21
3b84e1b1 22/**
23 * Gettext bindtextdomain wrapper.
24 *
25 * Wrapper solves differences between php versions in order to provide
26 * ngettext support. Should be used if translation uses ngettext
27 * functions.
81be3f39 28 * @since 1.5.1
3b84e1b1 29 * @param string $domain gettext domain name
30 * @param string $dir directory that contains all translations
31 * @return string path to translation directory
32 */
33function sq_bindtextdomain($domain,$dir) {
34 global $l10n, $gettext_flags, $sm_notAlias;
35
36 if ($gettext_flags==7) {
37 // gettext extension without ngettext
38 if (substr($dir, -1) != '/') $dir .= '/';
39 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
40 $input = new FileReader($mofile);
41 $l10n[$domain] = new gettext_reader($input);
42 }
43
44 $dir=bindtextdomain($domain,$dir);
45
46 return $dir;
47}
48
49/**
50 * Gettext textdomain wrapper.
51 * Makes sure that gettext_domain global is modified.
81be3f39 52 * @since 1.5.1
3b84e1b1 53 * @param string $name gettext domain name
54 * @return string gettext domain name
55 */
56function sq_textdomain($domain) {
57 global $gettext_domain;
58 $gettext_domain=textdomain($domain);
59 return $gettext_domain;
60}
61
1989cc04 62/**
63 * php setlocale function wrapper
64 *
65 * From php 4.3.0 it is possible to use arrays in order to set locale.
66 * php gettext extension works only when locale is set. This wrapper
67 * function allows to use more than one locale name.
68 *
598294a7 69 * @param int $category locale category name. Use php named constants
70 * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME)
1989cc04 71 * @param mixed $locale option contains array with possible locales or string with one locale
72 * @return string name of set locale or false, if all locales fail.
480feeac 73 * @since 1.5.1 and 1.4.5
1989cc04 74 * @see http://www.php.net/setlocale
75 */
76function sq_setlocale($category,$locale) {
77 // string with only one locale
78 if (is_string($locale))
79 return setlocale($category,$locale);
80
81 if (! check_php_version(4,3)) {
82 $ret=false;
83 $index=0;
84 while ( ! $ret && $index<count($locale)) {
85 $ret=setlocale($category,$locale[$index]);
86 $index++;
87 }
88 } else {
89 // php 4.3.0 or better, use entire array
90 $ret=setlocale($category,$locale);
91 }
92 return $ret;
93}
94
d6c32258 95/**
51468260 96 * Converts string from given charset to charset, that can be displayed by user translation.
97 *
98 * Function by default returns html encoded strings, if translation uses different encoding.
99 * If Japanese translation is used - function returns string converted to euc-jp
100 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
101 * If $charset is not supported - function returns unconverted string.
62f7daa5 102 *
51468260 103 * sanitizing of html tags is also done by this function.
104 *
d6c32258 105 * @param string $charset
106 * @param string $string Text to be decoded
5341ce66 107 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
480feeac 108 * Argument is available since 1.5.1 and 1.4.5.
51468260 109 * @return string decoded string
d6c32258 110 */
5341ce66 111function charset_decode ($charset, $string, $force_decode=false) {
3ec81e63 112 global $languages, $squirrelmail_language, $default_charset;
f03f6ee7 113 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
a2a7852b 114
3714db45 115 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1bb86586 116 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
117 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
6fbd125b 118 }
b05c8961 119
3ec81e63 120 $charset = strtolower($charset);
121
122 set_my_charset();
123
124 // Variables that allow to use functions without function_exist() calls
edf2c0ba 125 if (! isset($use_php_recode) || $use_php_recode=="" ) {
3b84e1b1 126 $use_php_recode=false; }
edf2c0ba 127 if (! isset($use_php_iconv) || $use_php_iconv=="" ) {
3b84e1b1 128 $use_php_iconv=false; }
3ec81e63 129
130 // Don't do conversion if charset is the same.
5341ce66 131 if ( ! $force_decode && $charset == strtolower($default_charset) )
3b84e1b1 132 return htmlspecialchars($string);
3ec81e63 133
134 // catch iso-8859-8-i thing
135 if ( $charset == "iso-8859-8-i" )
3b84e1b1 136 $charset = "iso-8859-8";
3ec81e63 137
138 /*
62f7daa5 139 * Recode converts html special characters automatically if you use
140 * 'charset..html' decoding. There is no documented way to put -d option
3ec81e63 141 * into php recode function call.
142 */
143 if ( $use_php_recode ) {
3b84e1b1 144 if ( $default_charset == "utf-8" ) {
145 // other charsets can be converted to utf-8 without loss.
146 // and output string is smaller
147 $string = recode_string($charset . "..utf-8",$string);
148 return htmlspecialchars($string);
149 } else {
150 $string = recode_string($charset . "..html",$string);
151 // recode does not convert single quote, htmlspecialchars does.
152 $string = str_replace("'", '&#039;', $string);
153 return $string;
154 }
3ec81e63 155 }
156
157 // iconv functions does not have html target and can be used only with utf-8
158 if ( $use_php_iconv && $default_charset=='utf-8') {
3b84e1b1 159 $string = iconv($charset,$default_charset,$string);
160 return htmlspecialchars($string);
3ec81e63 161 }
162
163 // If we don't use recode and iconv, we'll do it old way.
164
a2a7852b 165 /* All HTML special characters are 7 bit and can be replaced first */
62f7daa5 166
098ea084 167 $string = htmlspecialchars ($string);
a2a7852b 168
5dd23dac 169 /* controls cpu and memory intensive decoding cycles */
f03f6ee7 170 if (! isset($aggressive_decoding) || $aggressive_decoding=="" ) {
3b84e1b1 171 $aggressive_decoding=false; }
5dd23dac 172
b142de74 173 $decode=fixcharset($charset);
174 $decodefile=SM_PATH . 'functions/decode/' . $decode . '.php';
175 if (file_exists($decodefile)) {
3b84e1b1 176 include_once($decodefile);
177 $ret = call_user_func('charset_decode_'.$decode, $string);
a2a7852b 178 } else {
3b84e1b1 179 $ret = $string;
a2a7852b 180 }
181 return( $ret );
182}
03db90bc 183
d3bab52e 184/**
185 * Converts html string to given charset
480feeac 186 * @since 1.5.1 and 1.4.4
d3bab52e 187 * @param string $string
188 * @param string $charset
78be8403 189 * @param boolean $htmlencode keep htmlspecialchars encoding
62f7daa5 190 * @param string
d3bab52e 191 */
78be8403 192function charset_encode($string,$charset,$htmlencode=true) {
3b84e1b1 193 global $default_charset;
194
3b84e1b1 195 $encode=fixcharset($charset);
196 $encodefile=SM_PATH . 'functions/encode/' . $encode . '.php';
197 if (file_exists($encodefile)) {
198 include_once($encodefile);
199 $ret = call_user_func('charset_encode_'.$encode, $string);
200 } else {
201 include_once(SM_PATH . 'functions/encode/us_ascii.php');
202 $ret = charset_encode_us_ascii($string);
203 }
039fee57 204
205 /**
206 * Undo html special chars, some places (like compose form) have
207 * own sanitizing functions and don't need html symbols.
208 * Undo chars only after encoding in order to prevent conversion of
209 * html entities in plain text emails.
210 */
211 if (! $htmlencode ) {
212 $ret = str_replace(array('&amp;','&gt;','&lt;','&quot;'),array('&','>','<','"'),$ret);
213 }
3b84e1b1 214 return( $ret );
d3bab52e 215}
216
217/**
218 * Combined decoding and encoding functions
219 *
220 * If conversion is done to charset different that utf-8, unsupported symbols
221 * will be replaced with question marks.
480feeac 222 * @since 1.5.1 and 1.4.4
d3bab52e 223 * @param string $in_charset initial charset
224 * @param string $string string that has to be converted
225 * @param string $out_charset final charset
78be8403 226 * @param boolean $htmlencode keep htmlspecialchars encoding
d3bab52e 227 * @return string converted string
228 */
78be8403 229function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
5341ce66 230 $string=charset_decode($in_charset,$string,true);
33991968 231 $string=charset_encode($string,$out_charset,$htmlencode);
232 return $string;
d3bab52e 233}
234
b142de74 235/**
236 * Makes charset name suitable for decoding cycles
237 *
480feeac 238 * @since 1.5.0 and 1.4.4
b142de74 239 * @param string $charset Name of charset
240 * @return string $charset Adjusted name of charset
241 */
242function fixcharset($charset) {
91e0dccc 243 /* remove minus and characters that might be used in paths from charset
dbebf058 244 * name in order to be able to use it in function names and include calls.
245 */
246 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
62f7daa5 247
b142de74 248 // windows-125x and cp125x charsets
249 $charset=str_replace('windows_','cp',$charset);
a2a7852b 250
b142de74 251 // ibm > cp
252 $charset=str_replace('ibm','cp',$charset);
253
254 // iso-8859-8-i -> iso-8859-8
255 // use same cycle until I'll find differences
256 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
257
258 return $charset;
259}
a2a7852b 260
51468260 261/**
a2a7852b 262 * Set up the language to be output
263 * if $do_search is true, then scan the browser information
264 * for a possible language that we know
51468260 265 *
62f7daa5 266 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
51468260 267 * gettext translation bindings and html header information.
268 *
5679405c 269 * Function returns error codes, if there is some fatal error.
62f7daa5 270 * 0 = no error,
271 * 1 = mbstring support is not present,
51468260 272 * 2 = mbstring support is not present, user's translation reverted to en_US.
273 *
274 * @param string $sm_language translation used by user's interface
275 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
276 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
62f7daa5 277 * @return int function execution error codes.
a2a7852b 278 */
67a8c90a 279function set_up_language($sm_language, $do_search = false, $default = false) {
a2a7852b 280
281 static $SetupAlready = 0;
9eb0fbd4 282 global $use_gettext, $languages,
fe48c808 283 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
51468260 284 $sm_notAlias, $username, $data_dir;
a2a7852b 285
286 if ($SetupAlready) {
287 return;
288 }
a65846a7 289
5c920668 290 $SetupAlready = TRUE;
961ca3d8 291 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
a2a7852b 292
961ca3d8 293 if ($do_search && ! $sm_language && isset($accept_lang)) {
294 $sm_language = substr($accept_lang, 0, 2);
a2a7852b 295 }
62f7daa5 296
67a8c90a 297 if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
a2a7852b 298 $squirrelmail_language = $squirrelmail_default_language;
66d7950f 299 $sm_language = $squirrelmail_default_language;
a2a7852b 300 }
301 $sm_notAlias = $sm_language;
62f7daa5 302
3ec81e63 303 // Catching removed translation
304 // System reverts to English translation if user prefs contain translation
2ba706ef 305 // that is not available in $languages array
3ec81e63 306 if (!isset($languages[$sm_notAlias])) {
3b84e1b1 307 $sm_notAlias="en_US";
3ec81e63 308 }
309
a2a7852b 310 while (isset($languages[$sm_notAlias]['ALIAS'])) {
311 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
312 }
313
88cb1b4d 314 if ( isset($sm_language) &&
5c920668 315 $use_gettext &&
316 $sm_language != '' &&
317 isset($languages[$sm_notAlias]['CHARSET']) ) {
3b84e1b1 318 sq_bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
319 sq_textdomain( 'squirrelmail' );
1989cc04 320
321 // set codeset in order to avoid gettext charset conversions
03db90bc 322 if (function_exists('bind_textdomain_codeset')) {
1989cc04 323 // Japanese translation uses different internal charset
3b84e1b1 324 if ($sm_notAlias == 'ja_JP') {
598294a7 325 bind_textdomain_codeset ('squirrelmail', 'EUC-JP');
a5970d71 326 } else {
598294a7 327 bind_textdomain_codeset ('squirrelmail', $languages[$sm_notAlias]['CHARSET'] );
03db90bc 328 }
329 }
1989cc04 330
331 // Use LOCALE key, if it is set.
03db90bc 332 if (isset($languages[$sm_notAlias]['LOCALE'])){
3b84e1b1 333 $longlocale=$languages[$sm_notAlias]['LOCALE'];
03db90bc 334 } else {
3b84e1b1 335 $longlocale=$sm_notAlias;
03db90bc 336 }
1989cc04 337
338 // try setting locale
339 $retlocale=sq_setlocale(LC_ALL, $longlocale);
340
341 // check if locale is set and assign that locale to $longlocale
342 // in order to use it in putenv calls.
343 if (! is_bool($retlocale)) {
344 $longlocale=$retlocale;
345 } elseif (is_array($longlocale)) {
346 // setting of all locales failed.
347 // we need string instead of array used in LOCALE key.
348 $longlocale=$sm_notAlias;
349 }
350
5a4689fb 351 if ( !((bool)ini_get('safe_mode')) &&
f2374580 352 getenv( 'LC_ALL' ) != $longlocale ) {
353 putenv( "LC_ALL=$longlocale" );
354 putenv( "LANG=$longlocale" );
355 putenv( "LANGUAGE=$longlocale" );
54b168cf 356 putenv( "LC_NUMERIC=C" );
475df436 357 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
a2a7852b 358 }
54b168cf 359 // Workaround for plugins that use numbers with floating point
91e0dccc 360 // It might be removed if plugins use correct decimal delimiters
361 // according to locale settings.
54b168cf 362 setlocale(LC_NUMERIC, 'C');
363 // Workaround for specific Turkish strtolower/strtoupper rules.
364 // Many functions expect English conversion rules.
475df436 365 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE,'C');
03db90bc 366
367 // Set text direction/alignment variables
8d8da447 368 // These don't appear to be used... are they safe to remove?
62f7daa5 369 if (isset($languages[$sm_notAlias]['DIR']) &&
03db90bc 370 $languages[$sm_notAlias]['DIR'] == 'rtl') {
3b84e1b1 371 /**
372 * Text direction
373 * @global string $text_direction
374 */
375 $text_direction='rtl';
376 /**
377 * Left alignment
378 * @global string $left_align
379 */
380 $left_align='right';
381 /**
382 * Right alignment
383 * @global string $right_align
384 */
385 $right_align='left';
03db90bc 386 } else {
3b84e1b1 387 $text_direction='ltr';
388 $left_align='left';
389 $right_align='right';
03db90bc 390 }
391
392 $squirrelmail_language = $sm_notAlias;
a5970d71 393 if ($squirrelmail_language == 'ja_JP') {
b05c8961 394 header ('Content-Type: text/html; charset=EUC-JP');
395 if (!function_exists('mb_internal_encoding')) {
3b84e1b1 396 // Error messages can't be displayed here
397 $error = 1;
398 // Revert to English if possible.
399 if (function_exists('setPref') && $username!='' && $data_dir!="") {
400 setPref($data_dir, $username, 'language', "en_US");
401 $error = 2;
402 }
403 // stop further execution in order not to get php errors on mb_internal_encoding().
404 return $error;
e842b215 405 }
406 if (function_exists('mb_language')) {
407 mb_language('Japanese');
b05c8961 408 }
409 mb_internal_encoding('EUC-JP');
410 mb_http_output('pass');
fe48c808 411 } elseif ($squirrelmail_language == 'en_US') {
412 header( 'Content-Type: text/html; charset=' . $default_charset );
b05c8961 413 } else {
fe48c808 414 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
415 }
f5c507dc 416
417 /**
418 * mbstring.func_overload fix (#929644).
419 *
420 * php mbstring extension can replace standard string functions with their multibyte
421 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload.
422 *
423 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
424 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
425 * interface can't trust regular string functions. Due to mbstring overloading design
426 * limits php scripts can't control this setting.
427 *
428 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
429 * to disable mbstring overloading. Japanese translation uses different internal encoding.
430 */
431 if ($squirrelmail_language != 'ja_JP' &&
432 function_exists('mb_internal_encoding') &&
433 check_php_version(4,2,0) &&
434 (int)ini_get('mbstring.func_overload')!=0) {
435 mb_internal_encoding('ASCII');
436 }
a2a7852b 437 }
51468260 438 return 0;
b05c8961 439}
a2a7852b 440
51468260 441/**
442 * Sets default_charset variable according to the one that is used by user's translations.
443 *
444 * Function changes global $default_charset variable in order to be sure, that it
445 * contains charset used by user's translation. Sanity of $squirrelmail_default_language
446 * and $default_charset combination provided in SquirrelMail config is also tested.
447 *
448 * There can be a $default_charset setting in the
449 * config.php file, but the user may have a different language
450 * selected for a user interface. This function checks the
451 * language selected by the user and tags the outgoing messages
452 * with the appropriate charset corresponding to the language
453 * selection. This is "more right" (tm), than just stamping the
454 * message blindly with the system-wide $default_charset.
455 */
a2a7852b 456function set_my_charset(){
94965562 457 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
88cb1b4d 458
a2a7852b 459 $my_language = getPref($data_dir, $username, 'language');
5c920668 460 if (!$my_language) {
94965562 461 $my_language = $squirrelmail_default_language ;
5c920668 462 }
3ec81e63 463 // Catch removed translation
464 if (!isset($languages[$my_language])) {
3b84e1b1 465 $my_language="en_US";
3ec81e63 466 }
a2a7852b 467 while (isset($languages[$my_language]['ALIAS'])) {
f7e8861e 468 $my_language = $languages[$my_language]['ALIAS'];
a2a7852b 469 }
5c920668 470 $my_charset = $languages[$my_language]['CHARSET'];
fe48c808 471 if ($my_language!='en_US') {
a2a7852b 472 $default_charset = $my_charset;
473 }
474}
475
e0e1b169 476/**************************
477 * Japanese extra functions
478 **************************/
a2a7852b 479
e0e1b169 480/**
481 * Japanese decoding function
482 *
483 * converts string to euc-jp, if string uses JIS, EUC-JP, ShiftJIS or UTF-8
484 * charset. Needs mbstring support in php.
485 * @param string $ret text, that has to be converted
486 * @return string converted string
487 * @since 1.5.1
488 */
489function japanese_xtra_decode($ret) {
490 if (function_exists('mb_detect_encoding')) {
491 $detect_encoding = @mb_detect_encoding($ret);
492 if ($detect_encoding == 'JIS' ||
493 $detect_encoding == 'EUC-JP' ||
494 $detect_encoding == 'SJIS' ||
495 $detect_encoding == 'UTF-8') {
5c920668 496
e0e1b169 497 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
498 }
499 }
500 return $ret;
a2a7852b 501}
502
51468260 503/**
e0e1b169 504 * Japanese encoding function
51468260 505 *
e0e1b169 506 * converts string to jis, if string uses JIS, EUC-JP, ShiftJIS or UTF-8
507 * charset. Needs mbstring support in php.
508 * @param string $ret text, that has to be converted
509 * @return string converted text
510 * @since 1.5.1
51468260 511 */
e0e1b169 512function japanese_xtra_encode($ret) {
513 if (function_exists('mb_detect_encoding')) {
514 $detect_encoding = @mb_detect_encoding($ret);
515 if ($detect_encoding == 'JIS' ||
516 $detect_encoding == 'EUC-JP' ||
517 $detect_encoding == 'SJIS' ||
518 $detect_encoding == 'UTF-8') {
a8fa8e33 519
e0e1b169 520 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
521 }
522 }
523 return $ret;
524}
a8fa8e33 525
e0e1b169 526/**
527 * Japanese header encoding function
528 *
529 * creates base64 encoded header in iso-2022-jp charset
530 * @param string $ret text, that has to be converted
531 * @return string mime base64 encoded string
532 * @since 1.5.1
533 */
534function japanese_xtra_encodeheader($ret) {
535 if (function_exists('mb_detect_encoding')) {
536 $result = '';
537 if (strlen($ret) > 0) {
538 $tmpstr = mb_substr($ret, 0, 1);
539 $prevcsize = strlen($tmpstr);
540 for ($i = 1; $i < mb_strlen($ret); $i++) {
541 $tmp = mb_substr($ret, $i, 1);
542 if (strlen($tmp) == $prevcsize) {
543 $tmpstr .= $tmp;
544 } else {
545 if ($prevcsize == 1) {
546 $result .= $tmpstr;
547 } else {
548 $result .= str_replace(' ', '',
549 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
550 }
551 $tmpstr = $tmp;
552 $prevcsize = strlen($tmp);
553 }
554 }
555 if (strlen($tmpstr)) {
556 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
557 $result .= $tmpstr;
558 else
559 $result .= str_replace(' ', '',
560 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
561 }
562 }
563 $ret = $result;
564 }
565 return $ret;
566}
a8fa8e33 567
e0e1b169 568/**
569 * Japanese header decoding function
570 *
571 * return human readable string from mime header. string is returned in euc-jp
572 * charset.
573 * @param string $ret header string
574 * @return string decoded header string
575 * @since 1.5.1
576 */
577function japanese_xtra_decodeheader($ret) {
578 if (function_exists('mb_detect_encoding')) {
579 $ret = str_replace("\t", "", $ret);
580 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
581 $ret = @mb_decode_mimeheader($ret);
582 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
583 }
584 return $ret;
585}
a8fa8e33 586
e0e1b169 587/**
588 * Japanese downloaded filename processing function
589 *
590 * Returns shift-jis or euc-jp encoded file name
591 * @param string $ret string
592 * @param string $useragent browser
593 * @return string converted string
594 * @since 1.5.1
595 */
596function japanese_xtra_downloadfilename($ret,$useragent) {
597 if (function_exists('mb_detect_encoding')) {
598 if (strstr($useragent, 'Windows') !== false ||
599 strstr($useragent, 'Mac_') !== false) {
600 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
601 } else {
602 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
603 }
604 }
605 return $ret;
606}
a2a7852b 607
e0e1b169 608/**
609 * Japanese wordwrap function
610 *
611 * wraps text at set number of symbols
612 * @param string $ret text
613 * @param integer $wrap number of symbols per line
614 * @return string wrapped text
615 * @since 1.5.1
616 */
617function japanese_xtra_wordwrap($ret,$wrap) {
618 if (function_exists('mb_detect_encoding')) {
619 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
620 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
621 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
622 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
623 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
624 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
625 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
626 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
8d8da447 627 // This don't appear to be used... is it safe to remove?
e0e1b169 628 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
629 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
3bb3d83b 630
e0e1b169 631 if (strlen($ret) >= $wrap &&
632 substr($ret, 0, 1) != '>' &&
633 strpos($ret, 'http://') === FALSE &&
634 strpos($ret, 'https://') === FALSE &&
635 strpos($ret, 'ftp://') === FALSE) {
a2a7852b 636
e0e1b169 637 $ret = mb_convert_kana($ret, "KV");
a8fa8e33 638
e0e1b169 639 $line_new = '';
640 $ptr = 0;
a8fa8e33 641
e0e1b169 642 while ($ptr < strlen($ret) - 1) {
643 $l = mb_strcut($ret, $ptr, $wrap);
644 $ptr += strlen($l);
645 $tmp = $l;
2d268514 646
e0e1b169 647 $l = mb_strcut($ret, $ptr, 2);
648 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
649 $tmp .= $l;
650 $ptr += strlen($l);
651 $l = mb_strcut($ret, $ptr, 1);
652 }
653 $line_new .= $tmp;
654 if ($ptr < strlen($ret) - 1)
655 $line_new .= "\n";
656 }
657 $ret = $line_new;
658 }
659 }
660 return $ret;
661}
a8fa8e33 662
e0e1b169 663/**
664 * Japanese imap folder name encoding function
665 *
666 * converts folder name from euc-jp to utf7-imap
667 * @param string $ret folder name
668 * @return string converted folder name
669 * @since 1.5.1
670 */
671function japanese_xtra_utf7_imap_encode($ret){
672 if (function_exists('mb_detect_encoding')) {
673 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
674 }
675 return $ret;
676}
a8fa8e33 677
e0e1b169 678/**
679 * Japanese imap folder name decoding function
680 *
681 * converts folder name from utf7-imap to euc-jp.
682 * @param string $ret folder name in utf7-imap
683 * @return string converted folder name
684 * @since 1.5.1
685 */
686function japanese_xtra_utf7_imap_decode($ret) {
687 if (function_exists('mb_detect_encoding')) {
688 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
689 }
690 return $ret;
691}
a8fa8e33 692
e0e1b169 693/**
694 * Japanese string trimming function
695 *
696 * trims string to defined number of symbols
697 * @param string $ret string
698 * @param integer $width number of symbols
699 * @return string trimmed string
700 * @since 1.5.1
701 */
702function japanese_xtra_strimwidth($ret,$width) {
703 if (function_exists('mb_detect_encoding')) {
704 $ret = mb_strimwidth($ret, 0, $width, '...');
705 }
706 return $ret;
707}
a8fa8e33 708
e0e1b169 709/********************************
710 * Korean charset extra functions
711 ********************************/
a8fa8e33 712
e0e1b169 713/**
714 * Korean downloaded filename processing functions
715 *
716 * @param string default return value
717 * @return string
81be3f39 718 * @since 1.5.1
e0e1b169 719 */
720function korean_xtra_downloadfilename($ret) {
721 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
722 for ($i=0;$i<strlen($ret);$i++) {
723 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
724 $i++;
725 continue;
726 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
727 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
728 ($ret[$i] == '.') || ($ret[$i] == '-')) {
729 continue;
730 } else {
731 $ret[$i] = '_';
732 }
733 }
734 return $ret;
735}
a8fa8e33 736
e0e1b169 737/**
738 * Replaces non-braking spaces inserted by some browsers with regular space
739 *
740 * This function can be used to replace non-braking space symbols
741 * that are inserted in forms by some browsers instead of normal
742 * space symbol.
743 *
744 * @param string $string Text that needs to be cleaned
745 * @param string $charset Charset used in text
746 * @return string Cleaned text
747 */
748function cleanup_nbsp($string,$charset) {
a8fa8e33 749
e0e1b169 750 // reduce number of case statements
751 if (stristr('iso-8859-',substr($charset,0,9))){
752 $output_charset="iso-8859-x";
753 }
754 if (stristr('windows-125',substr($charset,0,11))){
755 $output_charset="cp125x";
756 }
757 if (stristr('koi8',substr($charset,0,4))){
758 $output_charset="koi8-x";
759 }
760 if (! isset($output_charset)){
761 $output_charset=strtolower($charset);
762 }
a8fa8e33 763
e0e1b169 764// where is non-braking space symbol
765switch($output_charset):
766 case "iso-8859-x":
767 case "cp125x":
768 case "iso-2022-jp":
769 $nbsp="\xA0";
770 break;
771 case "koi8-x":
772 $nbsp="\x9A";
773 break;
774 case "utf-8":
775 $nbsp="\xC2\xA0";
776 break;
777 default:
778 // don't change string if charset is unmatched
779 return $string;
780endswitch;
a8fa8e33 781
e0e1b169 782// return space instead of non-braking space.
783 return str_replace($nbsp,' ',$string);
784}
a8fa8e33 785
e0e1b169 786/**
787 * Function informs if it is safe to convert given charset to the one that is used by user.
788 *
789 * It is safe to use conversion only if user uses utf-8 encoding and when
790 * converted charset is similar to the one that is used by user.
791 *
792 * @param string $input_charset Charset of text that needs to be converted
793 * @return bool is it possible to convert to user's charset
794 */
795function is_conversion_safe($input_charset) {
796 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
a8fa8e33 797
e0e1b169 798 if (isset($lossy_encoding) && $lossy_encoding )
91e0dccc 799 return true;
a8fa8e33 800
e0e1b169 801 // convert to lower case
802 $input_charset = strtolower($input_charset);
a8fa8e33 803
e0e1b169 804 // Is user's locale Unicode based ?
805 if ( $default_charset == "utf-8" ) {
806 return true;
807 }
a8fa8e33 808
e0e1b169 809 // Charsets that are similar
810switch ($default_charset):
811case "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 }
819case "windows-1257":
820 if ( $input_charset == "iso-8859-13" ||
821 $input_charset == "iso-8859-4" ) {
822 return true;
823 } else {
824 return false;
825 }
826case "iso-8859-4":
827 if ( $input_charset == "iso-8859-13" ||
828 $input_charset == "windows-1257" ) {
829 return true;
830 } else {
831 return false;
832 }
833case "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 }
841case "iso-8859-13":
842 if ( $input_charset == "iso-8859-4" ||
843 $input_charset == "windows-1257" ) {
844 return true;
845 } else {
846 return false;
847 }
848case "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 }
856case "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 }
864default:
865 return false;
866endswitch;
867}
551a09c7 868
a8fa8e33 869
e0e1b169 870/* ------------------------------ main --------------------------- */
a8fa8e33 871
e0e1b169 872global $squirrelmail_language, $languages, $use_gettext;
060c9483 873
e0e1b169 874if (! isset($squirrelmail_language)) {
875 $squirrelmail_language = '';
876}
c30be3cf 877
e0e1b169 878/**
879 * Array specifies the available translations.
880 *
881 * Structure of array:
882 * $languages['language']['variable'] = 'value'
883 *
884 * Possible 'variable' names:
885 * NAME - Translation name in English
886 * CHARSET - Encoding used by translation
887 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
888 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
480feeac 889 * LOCALE - Full locale name (in xx_XX.charset format). It can use array with several locale names since 1.4.5 and 1.5.1
e0e1b169 890 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
891 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
892 *
893 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
894 *
895 * @name $languages
896 * @global array $languages
897 */
898$languages['bg_BG']['NAME'] = 'Bulgarian';
899$languages['bg_BG']['ALTNAME'] = '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;';
900$languages['bg_BG']['CHARSET'] = 'windows-1251';
901$languages['bg_BG']['LOCALE'] = 'bg_BG.CP1251';
902$languages['bg']['ALIAS'] = 'bg_BG';
c30be3cf 903
e0e1b169 904$languages['bn_IN']['NAME'] = 'Bengali';
905$languages['bn_IN']['CHARSET'] = 'utf-8';
906$languages['bn_IN']['LOCALE'] = 'bn_IN.UTF-8';
2729f5a2 907$languages['bn_BD']['ALIAS'] = 'bn_IN';
e0e1b169 908$languages['bn']['ALIAS'] = 'bn_IN';
a8fa8e33 909
e0e1b169 910$languages['ca_ES']['NAME'] = 'Catalan';
911$languages['ca_ES']['CHARSET'] = 'iso-8859-1';
1989cc04 912$languages['ca_ES']['LOCALE'] = array('ca_ES.ISO8859-1','ca_ES.ISO-8859-1','ca_ES');
e0e1b169 913$languages['ca']['ALIAS'] = 'ca_ES';
a8fa8e33 914
e0e1b169 915$languages['cs_CZ']['NAME'] = 'Czech';
916$languages['cs_CZ']['ALTNAME'] = '&#268;e&scaron;tina';
917$languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
1989cc04 918$languages['cs_CZ']['LOCALE'] = array('cs_CZ.ISO8859-2','cs_CZ.ISO-8859-2','cs_CZ');
e0e1b169 919$languages['cs']['ALIAS'] = 'cs_CZ';
4417eead 920
e0e1b169 921$languages['cy_GB']['NAME'] = 'Welsh';
922$languages['cy_GB']['ALTNAME'] = 'Cymraeg';
923$languages['cy_GB']['CHARSET'] = 'iso-8859-1';
1989cc04 924$languages['cy_GB']['LOCALE'] = array('cy_GB.ISO8859-1','cy_GB.ISO-8859-1','cy_GB');
e0e1b169 925$languages['cy']['ALIAS'] = 'cy_GB';
d3b57948 926
e0e1b169 927// Danish locale is da_DK.
928$languages['da_DK']['NAME'] = 'Danish';
929$languages['da_DK']['ALTNAME'] = 'Dansk';
930$languages['da_DK']['CHARSET'] = 'iso-8859-1';
1989cc04 931$languages['da_DK']['LOCALE'] = array('da_DK.ISO8859-1','da_DK.ISO-8859-1','da_DK');
e0e1b169 932$languages['da']['ALIAS'] = 'da_DK';
2ba590f9 933
e0e1b169 934$languages['de_DE']['NAME'] = 'German';
1989cc04 935$languages['de_DE']['ALTNAME'] = 'Deutsch';
e0e1b169 936$languages['de_DE']['CHARSET'] = 'iso-8859-1';
1989cc04 937$languages['de_DE']['LOCALE'] = array('de_DE.ISO8859-1','de_DE.ISO-8859-1','de_DE');
e0e1b169 938$languages['de']['ALIAS'] = 'de_DE';
a2a7852b 939
e0e1b169 940$languages['el_GR']['NAME'] = 'Greek';
941$languages['el_GR']['ALTNAME'] = '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;';
942$languages['el_GR']['CHARSET'] = 'iso-8859-7';
1989cc04 943$languages['el_GR']['LOCALE'] = array('el_GR.ISO8859-7','el_GR.ISO-8859-7','el_GR');
e0e1b169 944$languages['el']['ALIAS'] = 'el_GR';
3b84e1b1 945
e0e1b169 946$languages['en_GB']['NAME'] = 'British';
947$languages['en_GB']['CHARSET'] = 'iso-8859-15';
1989cc04 948$languages['en_GB']['LOCALE'] = array('en_GB.ISO8859-15','en_GB.ISO-8859-15','en_GB');
3b84e1b1 949
e0e1b169 950$languages['en_US']['NAME'] = 'English';
951$languages['en_US']['CHARSET'] = 'iso-8859-1';
952$languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
953$languages['en']['ALIAS'] = 'en_US';
a2a7852b 954
e0e1b169 955$languages['es_ES']['NAME'] = 'Spanish';
956$languages['es_ES']['ALTNAME'] = 'Espa&ntilde;ol';
957$languages['es_ES']['CHARSET'] = 'iso-8859-1';
1989cc04 958$languages['es_ES']['LOCALE'] = array('es_ES.ISO8859-1','es_ES.ISO-8859-1','es_ES');
e0e1b169 959$languages['es']['ALIAS'] = 'es_ES';
1d33e35e 960
e0e1b169 961$languages['et_EE']['NAME'] = 'Estonian';
962$languages['et_EE']['CHARSET'] = 'iso-8859-15';
1989cc04 963$languages['et_EE']['LOCALE'] = array('et_EE.ISO8859-15','et_EE.ISO-8859-15','et_EE');
e0e1b169 964$languages['et']['ALIAS'] = 'et_EE';
62f7daa5 965
e0e1b169 966$languages['eu_ES']['NAME'] = 'Basque';
967$languages['eu_ES']['CHARSET'] = 'iso-8859-1';
1989cc04 968$languages['eu_ES']['LOCALE'] = array('eu_ES.ISO8859-1','eu_ES.ISO-8859-1','eu_ES');
e0e1b169 969$languages['eu']['ALIAS'] = 'eu_ES';
1d33e35e 970
e0e1b169 971$languages['fo_FO']['NAME'] = 'Faroese';
972$languages['fo_FO']['CHARSET'] = 'iso-8859-1';
1989cc04 973$languages['fo_FO']['LOCALE'] = array('fo_FO.ISO8859-1','fo_FO.ISO-8859-1','fo_FO');
e0e1b169 974$languages['fo']['ALIAS'] = 'fo_FO';
1d33e35e 975
e0e1b169 976$languages['fi_FI']['NAME'] = 'Finnish';
977$languages['fi_FI']['ALTNAME'] = 'Suomi';
978$languages['fi_FI']['CHARSET'] = 'iso-8859-1';
1989cc04 979$languages['fi_FI']['LOCALE'] = array('fi_FI.ISO8859-1','fi_FI.ISO-8859-1','fi_FI');
e0e1b169 980$languages['fi']['ALIAS'] = 'fi_FI';
1bb86586 981
e0e1b169 982$languages['fr_FR']['NAME'] = 'French';
983$languages['fr_FR']['ALTNAME'] = 'Fran&#231;ais';
984$languages['fr_FR']['CHARSET'] = 'iso-8859-1';
1989cc04 985$languages['fr_FR']['LOCALE'] = array('fr_FR.ISO8859-1','fr_FR.ISO-8859-1','fr_FR');
e0e1b169 986$languages['fr']['ALIAS'] = 'fr_FR';
1bb86586 987
e0e1b169 988$languages['hr_HR']['NAME'] = 'Croatian';
989$languages['hr_HR']['CHARSET'] = 'iso-8859-2';
1989cc04 990$languages['hr_HR']['LOCALE'] = array('hr_HR.ISO8859-2','hr_HR.ISO-8859-2','hr_HR');
e0e1b169 991$languages['hr']['ALIAS'] = 'hr_HR';
62f7daa5 992
e0e1b169 993$languages['hu_HU']['NAME'] = 'Hungarian';
994$languages['hu_HU']['ALTNAME'] = 'Magyar';
995$languages['hu_HU']['CHARSET'] = 'iso-8859-2';
1989cc04 996$languages['hu_HU']['LOCALE'] = array('hu_HU.ISO8859-2','hu_HU.ISO-8859-2','hu_HU');
e0e1b169 997$languages['hu']['ALIAS'] = 'hu_HU';
1bb86586 998
e0e1b169 999$languages['id_ID']['NAME'] = 'Indonesian';
1000$languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
1001$languages['id_ID']['CHARSET'] = 'iso-8859-1';
1989cc04 1002$languages['id_ID']['LOCALE'] = array('id_ID.ISO8859-1','id_ID.ISO-8859-1','id_ID');
e0e1b169 1003$languages['id']['ALIAS'] = 'id_ID';
1bb86586 1004
e0e1b169 1005$languages['is_IS']['NAME'] = 'Icelandic';
1006$languages['is_IS']['ALTNAME'] = '&Iacute;slenska';
1007$languages['is_IS']['CHARSET'] = 'iso-8859-1';
1989cc04 1008$languages['is_IS']['LOCALE'] = array('is_IS.ISO8859-1','is_IS.ISO-8859-1','is_IS');
e0e1b169 1009$languages['is']['ALIAS'] = 'is_IS';
1bb86586 1010
e0e1b169 1011$languages['it_IT']['NAME'] = 'Italian';
1012$languages['it_IT']['CHARSET'] = 'iso-8859-1';
1989cc04 1013$languages['it_IT']['LOCALE'] = array('it_IT.ISO8859-1','it_IT.ISO-8859-1','it_IT');
e0e1b169 1014$languages['it']['ALIAS'] = 'it_IT';
1bb86586 1015
e0e1b169 1016$languages['ja_JP']['NAME'] = 'Japanese';
1017$languages['ja_JP']['ALTNAME'] = '&#26085;&#26412;&#35486;';
1018$languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
1019$languages['ja_JP']['LOCALE'] = 'ja_JP.EUC-JP';
1020$languages['ja_JP']['XTRA_CODE'] = 'japanese_xtra';
1021$languages['ja']['ALIAS'] = 'ja_JP';
62f7daa5 1022
e0e1b169 1023$languages['ko_KR']['NAME'] = 'Korean';
1024$languages['ko_KR']['CHARSET'] = 'euc-KR';
1025$languages['ko_KR']['LOCALE'] = 'ko_KR.EUC-KR';
1026$languages['ko_KR']['XTRA_CODE'] = 'korean_xtra';
1027$languages['ko']['ALIAS'] = 'ko_KR';
1bb86586 1028
e0e1b169 1029$languages['lt_LT']['NAME'] = 'Lithuanian';
1030$languages['lt_LT']['ALTNAME'] = 'Lietuvi&#371;';
1031$languages['lt_LT']['CHARSET'] = 'utf-8';
1032$languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
1033$languages['lt']['ALIAS'] = 'lt_LT';
62f7daa5 1034
e0e1b169 1035$languages['nl_NL']['NAME'] = 'Dutch';
1036$languages['nl_NL']['ALTNAME'] = 'Nederlands';
1037$languages['nl_NL']['CHARSET'] = 'iso-8859-1';
1989cc04 1038$languages['nl_NL']['LOCALE'] = array('nl_NL.ISO8859-1','nl_NL.ISO-8859-1','nl_NL');
e0e1b169 1039$languages['nl']['ALIAS'] = 'nl_NL';
62f7daa5 1040
e0e1b169 1041$languages['ms_MY']['NAME'] = 'Malay';
1042$languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
1043$languages['ms_MY']['CHARSET'] = 'iso-8859-1';
1989cc04 1044$languages['ms_MY']['LOCALE'] = array('ms_MY.ISO8859-1','ms_MY.ISO-8859-1','ms_MY');
e0e1b169 1045$languages['my']['ALIAS'] = 'ms_MY';
62f7daa5 1046
e0e1b169 1047$languages['nb_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
1048$languages['nb_NO']['ALTNAME'] = 'Norsk (Bokm&aring;l)';
1049$languages['nb_NO']['CHARSET'] = 'iso-8859-1';
1989cc04 1050$languages['nb_NO']['LOCALE'] = array('nb_NO.ISO8859-1','nb_NO.ISO-8859-1','nb_NO');
e0e1b169 1051$languages['nb']['ALIAS'] = 'nb_NO';
1bb86586 1052
e0e1b169 1053$languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
1054$languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
1055$languages['nn_NO']['CHARSET'] = 'iso-8859-1';
1989cc04 1056$languages['nn_NO']['LOCALE'] = array('nn_NO.ISO8859-1','nn_NO.ISO-8859-1','nn_NO');
1bb86586 1057
e0e1b169 1058$languages['pl_PL']['NAME'] = 'Polish';
1059$languages['pl_PL']['ALTNAME'] = 'Polski';
1060$languages['pl_PL']['CHARSET'] = 'iso-8859-2';
1989cc04 1061$languages['pl_PL']['LOCALE'] = array('pl_PL.ISO8859-2','pl_PL.ISO-8859-2','pl_PL');
e0e1b169 1062$languages['pl']['ALIAS'] = 'pl_PL';
1bb86586 1063
e0e1b169 1064$languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
1065$languages['pt_PT']['CHARSET'] = 'iso-8859-1';
1989cc04 1066$languages['pt_PT']['LOCALE'] = array('pt_PT.ISO8859-1','pt_PT.ISO-8859-1','pt_PT');
e0e1b169 1067$languages['pt']['ALIAS'] = 'pt_PT';
1bb86586 1068
e0e1b169 1069$languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
1070$languages['pt_BR']['ALTNAME'] = 'Portugu&ecirc;s do Brasil';
1071$languages['pt_BR']['CHARSET'] = 'iso-8859-1';
1989cc04 1072$languages['pt_BR']['LOCALE'] = array('pt_BR.ISO8859-1','pt_BR.ISO-8859-1','pt_BR');
1bb86586 1073
e0e1b169 1074$languages['ro_RO']['NAME'] = 'Romanian';
1075$languages['ro_RO']['ALTNAME'] = 'Rom&acirc;n&#259;';
1076$languages['ro_RO']['CHARSET'] = 'iso-8859-2';
1989cc04 1077$languages['ro_RO']['LOCALE'] = array('ro_RO.ISO8859-2','ro_RO.ISO-8859-2','ro_RO');
e0e1b169 1078$languages['ro']['ALIAS'] = 'ro_RO';
1d33e35e 1079
e0e1b169 1080$languages['ru_RU']['NAME'] = 'Russian';
1081$languages['ru_RU']['ALTNAME'] = '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;';
1082$languages['ru_RU']['CHARSET'] = 'utf-8';
1083$languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
1084$languages['ru']['ALIAS'] = 'ru_RU';
9af9c0a2 1085
e0e1b169 1086$languages['sk_SK']['NAME'] = 'Slovak';
1087$languages['sk_SK']['CHARSET'] = 'iso-8859-2';
1989cc04 1088$languages['sk_SK']['LOCALE'] = array('sk_SK.ISO8859-2','sk_SK.ISO-8859-2','sk_SK');
e0e1b169 1089$languages['sk']['ALIAS'] = 'sk_SK';
9af9c0a2 1090
e0e1b169 1091$languages['sl_SI']['NAME'] = 'Slovenian';
1092$languages['sl_SI']['ALTNAME'] = 'Sloven&scaron;&#269;ina';
1093$languages['sl_SI']['CHARSET'] = 'iso-8859-2';
1989cc04 1094$languages['sl_SI']['LOCALE'] = array('sl_SI.ISO8859-2','sl_SI.ISO-8859-2','sl_SI');
e0e1b169 1095$languages['sl']['ALIAS'] = 'sl_SI';
9af9c0a2 1096
e0e1b169 1097$languages['sr_YU']['NAME'] = 'Serbian';
1098$languages['sr_YU']['ALTNAME'] = 'Srpski';
1099$languages['sr_YU']['CHARSET'] = 'iso-8859-2';
1989cc04 1100$languages['sr_YU']['LOCALE'] = array('sr_YU.ISO8859-2','sr_YU.ISO-8859-2','sr_YU');
e0e1b169 1101$languages['sr']['ALIAS'] = 'sr_YU';
4e519821 1102
e0e1b169 1103$languages['sv_SE']['NAME'] = 'Swedish';
1104$languages['sv_SE']['ALTNAME'] = 'Svenska';
1105$languages['sv_SE']['CHARSET'] = 'iso-8859-1';
1989cc04 1106$languages['sv_SE']['LOCALE'] = array('sv_SE.ISO8859-1','sv_SE.ISO-8859-1','sv_SE');
e0e1b169 1107$languages['sv']['ALIAS'] = 'sv_SE';
33991968 1108
e0e1b169 1109$languages['th_TH']['NAME'] = 'Thai';
1110$languages['th_TH']['CHARSET'] = 'tis-620';
1111$languages['th_TH']['LOCALE'] = 'th_TH.TIS-620';
1112$languages['th']['ALIAS'] = 'th_TH';
4e519821 1113
e0e1b169 1114$languages['tl_PH']['NAME'] = 'Tagalog';
1115$languages['tl_PH']['CHARSET'] = 'iso-8859-1';
1989cc04 1116$languages['tl_PH']['LOCALE'] = array('tl_PH.ISO8859-1','tl_PH.ISO-8859-1','tl_PH');
e0e1b169 1117$languages['tl']['ALIAS'] = 'tl_PH';
4e519821 1118
e0e1b169 1119$languages['tr_TR']['NAME'] = 'Turkish';
1120$languages['tr_TR']['CHARSET'] = 'iso-8859-9';
1989cc04 1121$languages['tr_TR']['LOCALE'] = array('tr_TR.ISO8859-9','tr_TR.ISO-8859-9','tr_TR');
e0e1b169 1122$languages['tr']['ALIAS'] = 'tr_TR';
4e519821 1123
e0e1b169 1124$languages['zh_TW']['NAME'] = 'Chinese Trad';
1125$languages['zh_TW']['CHARSET'] = 'big5';
1126$languages['zh_TW']['LOCALE'] = 'zh_TW.BIG5';
1127$languages['tw']['ALIAS'] = 'zh_TW';
1128
1129$languages['zh_CN']['NAME'] = 'Chinese Simp';
1130$languages['zh_CN']['CHARSET'] = 'gb2312';
1131$languages['zh_CN']['LOCALE'] = 'zh_CN.GB2312';
1132$languages['cn']['ALIAS'] = 'zh_CN';
1133
1134$languages['uk_UA']['NAME'] = 'Ukrainian';
1135$languages['uk_UA']['CHARSET'] = 'koi8-u';
1136$languages['uk_UA']['LOCALE'] = 'uk_UA.KOI8-U';
1137$languages['uk']['ALIAS'] = 'uk_UA';
1138
1139$languages['ru_UA']['NAME'] = 'Russian (Ukrainian)';
1140$languages['ru_UA']['CHARSET'] = 'koi8-r';
1141$languages['ru_UA']['LOCALE'] = 'ru_UA.KOI8-R';
1142
1143/*
1144$languages['vi_VN']['NAME'] = 'Vietnamese';
1145$languages['vi_VN']['CHARSET'] = 'utf-8';
1146$languages['vi']['ALIAS'] = 'vi_VN';
1147*/
1148
1149// Right to left languages
1150$languages['ar']['NAME'] = 'Arabic';
1151$languages['ar']['CHARSET'] = 'windows-1256';
1152$languages['ar']['DIR'] = 'rtl';
1153
1154$languages['fa_IR']['NAME'] = 'Farsi';
1155$languages['fa_IR']['CHARSET'] = 'utf-8';
1156$languages['fa_IR']['DIR'] = 'rtl';
1157$languages['fa_IR']['LOCALE'] = 'fa_IR.UTF-8';
1158$languages['fa']['ALIAS'] = 'fa_IR';
1159
1160$languages['he_IL']['NAME'] = 'Hebrew';
1161$languages['he_IL']['CHARSET'] = 'windows-1255';
1162$languages['he_IL']['LOCALE'] = 'he_IL.CP1255';
1163$languages['he_IL']['DIR'] = 'rtl';
1164$languages['he']['ALIAS'] = 'he_IL';
1165
1166$languages['ug']['NAME'] = 'Uighur';
1167$languages['ug']['CHARSET'] = 'utf-8';
1168$languages['ug']['DIR'] = 'rtl';
1169
1170/* Detect whether gettext is installed. */
1171$gettext_flags = 0;
1172if (function_exists('_')) {
1173 $gettext_flags += 1;
1174}
1175if (function_exists('bindtextdomain')) {
1176 $gettext_flags += 2;
1177}
1178if (function_exists('textdomain')) {
1179 $gettext_flags += 4;
1180}
1181if (function_exists('ngettext')) {
1182 $gettext_flags += 8;
1183}
1184
1185/* If gettext is fully loaded, cool */
1186if ($gettext_flags == 15) {
1187 $use_gettext = true;
1188}
1189
1190/* If ngettext support is missing, load it */
1191elseif ($gettext_flags == 7) {
1192 $use_gettext = true;
1193 // load internal ngettext functions
1194 include_once(SM_PATH . 'class/l10n.class.php');
1195 include_once(SM_PATH . 'functions/ngettext.php');
1196}
1197
1198/* If we can fake gettext, try that */
1199elseif ($gettext_flags == 0) {
1200 $use_gettext = true;
1201 include_once(SM_PATH . 'functions/gettext.php');
1202} else {
1203 /* Uh-ho. A weird install */
1204 if (! $gettext_flags & 1) {
1205 /**
1206 * Function is used as replacement in broken installs
1207 * @ignore
1208 */
1209 function _($str) {
1210 return $str;
1211 }
1212 }
1213 if (! $gettext_flags & 2) {
1214 /**
1215 * Function is used as replacement in broken installs
1216 * @ignore
1217 */
1218 function bindtextdomain() {
1219 return;
1220 }
1221 }
1222 if (! $gettext_flags & 4) {
1223 /**
1224 * Function is used as replacemet in broken installs
1225 * @ignore
1226 */
1227 function textdomain() {
1228 return;
1229 }
1230 }
1231 if (! $gettext_flags & 8) {
1232 /**
1233 * Function is used as replacemet in broken installs
1234 * @ignore
1235 */
1236 function ngettext($str,$str2,$number) {
1237 if ($number>1) {
1238 return $str2;
1239 } else {
1240 return $str;
1241 }
1242 }
1243 }
4e519821 1244}
51468260 1245?>