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