/* Decodes a string to the internal encoding from the given charset */
function charset_decode ($charset, $string) {
+ global $languages, $squirrelmail_language;
+
+ if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
+ function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
+ $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
+ }
/* All HTML special characters are 7 bit and can be replaced first */
$string = htmlspecialchars ($string);
* ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
* These are Unicode 900-902
*/
- while (ereg("([\264-\266])", $string, $res)) {
- $replace = '&#' . (ord($res[1])+720) . ';';
- $string = str_replace($res[1], $replace, $string);
- }
-
+ $string = preg_replace("/([\264-\266])/","'&#' . (ord(\\1)+720)",$string);
+
/* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */
$string = str_replace("\267", '·', $string);
* ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
* These are Unicode 900-902
*/
- while (ereg("([\270-\272])", $string, $res)) {
- $replace = '&#' . (ord($res[1])+720) . ";";
- $string = str_replace($res[1], $replace, $string);
- }
+ $string = preg_replace("/([\270-\272])/","'&#' . (ord(\\1)+720)",$string);
/*
* 11/11 (0xBB) Right angle quotation mark is the same as in
$string = str_replace("\273", '»', $string);
/* And now the rest of the charset */
- while (ereg("([\274-\376])", $string, $res)) {
- $replace = '&#' . (ord($res[1])+720) . ';';
- $string = str_replace($res[1], $replace, $string);
- }
+ $string = preg_replace("/([\274-\376])/","'&#' . (ord(\\1)+720)",$string);
return $string;
}
// Euro sign
$string = str_replace ("\244", '€', $string);
// Latin capital letter S with caron
- $string = str_replace ("\244", 'Š', $string);
+ $string = str_replace ("\246", 'Š', $string);
// Latin small letter s with caron
$string = str_replace ("\250", 'š', $string);
// Latin capital letter Z with caron
return (charset_decode_iso_8859_1($string));
}
-/* ISO-8859-15 is Cyrillic */
+/* ISO-8859-5 is Cyrillic */
function charset_decode_iso_8859_5 ($string) {
// Convert to KOI8-R, then return this decoded.
$string = convert_cyr_string($string, 'i', 'k');
return $string;
}
+
+/*
+ * Japanese charset extra function
+ *
+ */
+function japanese_charset_xtra() {
+ $ret = func_get_arg(1); /* default return value */
+ if (function_exists('mb_detect_encoding')) {
+ switch (func_get_arg(0)) { /* action */
+ case 'decode':
+ $detect_encoding = mb_detect_encoding($ret);
+ if ($detect_encoding == 'JIS' ||
+ $detect_encoding == 'EUC-JP' ||
+ $detect_encoding == 'SJIS') {
+
+ $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
+ }
+ break;
+ case 'encode':
+ $detect_encoding = mb_detect_encoding($ret);
+ if ($detect_encoding == 'JIS' ||
+ $detect_encoding == 'EUC-JP' ||
+ $detect_encoding == 'SJIS') {
+
+ $ret = mb_convert_encoding($ret, 'JIS', 'AUTO');
+ }
+ break;
+ case 'strimwidth':
+ $width = func_get_arg(2);
+ $ret = mb_strimwidth($ret, 0, $width, '...');
+ break;
+ case 'encodeheader':
+ $ret = mb_encode_mimeheader($ret);
+ break;
+ case 'decodeheader':
+ $ret = str_replace("\t", "", $ret);
+ if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
+ $ret = mb_decode_mimeheader($ret);
+ $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
+ break;
+ case 'downloadfilename':
+ $useragent = func_get_arg(2);
+ if (strstr($useragent, 'Windows') !== false ||
+ strstr($useragent, 'Mac_') !== false) {
+ $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
+ } else {
+ $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
+}
+ break;
+ default:
+ break;
+ }
+ }
+ return $ret;
+}
+
+
/*
* Set up the language to be output
* if $do_search is true, then scan the browser information
$sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
}
- if ( isset($sm_language) &&
+ if ( isset($sm_language) &&
$use_gettext &&
$sm_language != '' &&
isset($languages[$sm_notAlias]['CHARSET']) ) {
bindtextdomain( 'squirrelmail', '../locale/' );
- textdomain( 'squirrelmail' );
- if ( !ini_get('safe_mode') &&
+ textdomain( 'squirrelmail' );
+ if ( !ini_get('safe_mode') &&
getenv( 'LC_ALL' ) != $sm_notAlias ) {
putenv( "LC_ALL=$sm_notAlias" );
putenv( "LANG=$sm_notAlias" );
putenv( "LANGUAGE=$sm_notAlias" );
}
- setlocale('LC_ALL', $sm_notAlias);
+ setlocale(LC_ALL, $sm_notAlias);
$squirrelmail_language = $sm_notAlias;
+ if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
+ header ('Content-Type: text/html; charset=EUC-JP');
+ if (!function_exists('mb_internal_encoding')) {
+ echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --with-mbstring).");
+ }
+ mb_internal_encoding('EUC-JP');
+ mb_http_output('pass');
+ } else {
header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
}
}
+}
function set_my_charset(){
* message blindly with the system-wide $default_charset.
*/
global $data_dir, $username, $default_charset, $languages;
-
+
$my_language = getPref($data_dir, $username, 'language');
if (!$my_language) {
return;
$languages['it_IT']['CHARSET'] = 'iso-8859-1';
$languages['it']['ALIAS'] = 'it_IT';
+$languages['ja_JP']['NAME'] = 'Japanese';
+$languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
+$languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
+$languages['ja']['ALIAS'] = 'ja_JP';
+
$languages['ko_KR']['NAME'] = 'Korean';
$languages['ko_KR']['CHARSET'] = 'euc-KR';
$languages['ko']['ALIAS'] = 'ko_KR';
$languages['no_NO']['NAME'] = 'Norwegian (Bokmål)';
$languages['no_NO']['CHARSET'] = 'iso-8859-1';
$languages['no']['ALIAS'] = 'no_NO';
-$languages['no_NO_ny']['NAME'] = 'Norwegian (Nynorsk)';
-$languages['no_NO_ny']['CHARSET'] = 'iso-8859-1';
+$languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
+$languages['nn_NO']['CHARSET'] = 'iso-8859-1';
$languages['pl_PL']['NAME'] = 'Polish';
$languages['pl_PL']['CHARSET'] = 'iso-8859-2';
$languages['ru_RU']['CHARSET'] = 'koi8-r';
$languages['ru']['ALIAS'] = 'ru_RU';
-$languages['sr']['NAME'] = 'Serbian';
-$languages['sr']['CHARSET'] = 'iso-8859-2';
-$languages['sr_YU']['ALIAS'] = 'sr';
+$languages['sr_YU']['NAME'] = 'Serbian';
+$languages['sr_YU']['CHARSET'] = 'iso-8859-2';
+$languages['sr']['ALIAS'] = 'sr_YU';
$languages['sv_SE']['NAME'] = 'Swedish';
$languages['sv_SE']['CHARSET'] = 'iso-8859-1';
$languages['tr_TR']['CHARSET'] = 'iso-8859-9';
$languages['tr']['ALIAS'] = 'tr_TR';
-// it's zh_TW, actually.
-
$languages['zh_TW']['NAME'] = 'Taiwan';
$languages['zh_TW']['CHARSET'] = 'big5';
$languages['tw']['ALIAS'] = 'zh_TW';
+$languages['zh_TW']['NAME'] = 'Chinese';
+$languages['zh_TW']['CHARSET'] = 'gb2312';
+$languages['tw']['ALIAS'] = 'zh_CN';
+
$languages['sk_SK']['NAME'] = 'Slovak';
$languages['sk_SK']['CHARSET'] = 'iso-8859-2';
$languages['sk']['ALIAS'] = 'sk_SK';
$languages['bg_BG']['CHARSET'] = 'windows-1251';
$languages['bg']['ALIAS'] = 'bg_BG';
+// Right to left languages
+
+$languages['he_HE']['NAME'] = 'Hebrew';
+$languages['he_HE']['CHARSET'] = 'windows-1255';
+$languages['he_HE']['DIR'] = 'rtl';
+$languages['he']['ALIAS'] = 'he_HE';
+
+
/* Detect whether gettext is installed. */
$gettext_flags = 0;
if (function_exists('_')) {
}
}
-?>
\ No newline at end of file
+?>