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