<?php
/**
- * functions/i18n.php
+ * SquirrelMail internationalization functions
*
* Copyright (c) 1999-2004 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
* Internally the output character set is used. Other characters are
* encoded using Unicode entities according to HTML 4.0.
*
- * $Id$
+ * @version $Id$
* @package squirrelmail
+ * @subpackage i18n
*/
/** Everything uses global.php... */
// Variables that allow to use functions without function_exist() calls
if (! isset($use_php_recode) || $use_php_recode=="" ) {
- $use_php_recode=false; }
+ $use_php_recode=false; }
if (! isset($use_php_iconv) || $use_php_iconv=="" ) {
$use_php_iconv=false; }
*/
if ( $use_php_recode ) {
if ( $default_charset == "utf-8" ) {
- // other charsets can be converted to utf-8 without loss.
- // and output string is smaller
- $string = recode_string($charset . "..utf-8",$string);
- return htmlspecialchars($string);
+ // other charsets can be converted to utf-8 without loss.
+ // and output string is smaller
+ $string = recode_string($charset . "..utf-8",$string);
+ return htmlspecialchars($string);
} else {
- $string = recode_string($charset . "..html",$string);
- // recode does not convert single quote, htmlspecialchars does.
- $string = str_replace("'", ''', $string);
- return $string;
+ $string = recode_string($charset . "..html",$string);
+ // recode does not convert single quote, htmlspecialchars does.
+ $string = str_replace("'", ''', $string);
+ return $string;
}
}
$decode=fixcharset($charset);
$decodefile=SM_PATH . 'functions/decode/' . $decode . '.php';
if (file_exists($decodefile)) {
- include_once($decodefile);
- $ret = call_user_func('charset_decode_'.$decode, $string);
+ include_once($decodefile);
+ $ret = call_user_func('charset_decode_'.$decode, $string);
} else {
- $ret = $string;
+ $ret = $string;
}
return( $ret );
}
-
+
+/**
+ * Converts html string to given charset
+ * @param string $string
+ * @param string $charset
+ * @param boolean $htmlencode keep htmlspecialchars encoding
+ * @param string
+ */
+function charset_encode($string,$charset,$htmlencode=true) {
+ global $default_charset;
+
+ // Undo html special chars
+ if (! $htmlencode ) {
+ $string = str_replace(array('&','>','<','"'),array('&','>','<','"'),$string);
+ }
+
+ $encode=fixcharset($charset);
+ $encodefile=SM_PATH . 'functions/encode/' . $encode . '.php';
+ if (file_exists($encodefile)) {
+ include_once($encodefile);
+ $ret = call_user_func('charset_encode_'.$encode, $string);
+ } else {
+ $ret = $string;
+ }
+ return( $ret );
+}
+
+/**
+ * Combined decoding and encoding functions
+ *
+ * If conversion is done to charset different that utf-8, unsupported symbols
+ * will be replaced with question marks.
+ * @param string $in_charset initial charset
+ * @param string $string string that has to be converted
+ * @param string $out_charset final charset
+ * @param boolean $htmlencode keep htmlspecialchars encoding
+ * @return string converted string
+ */
+function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
+ $string=charset_decode($in_charset,$string);
+ $string=charset_encode($string,$out_charset,$htmlencode);
+ return $string;
+}
+
/**
* Makes charset name suitable for decoding cycles
*
isset($languages[$sm_notAlias]['CHARSET']) ) {
bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
textdomain( 'squirrelmail' );
- if (function_exists('bind_textdomain_codeset')) {
- if ($sm_notAlias == 'ja_JP') {
- bind_textdomain_codeset ("squirrelmail", 'EUC-JP');
+ if (function_exists('bind_textdomain_codeset')) {
+ if ($sm_notAlias == 'ja_JP') {
+ bind_textdomain_codeset ("squirrelmail", 'EUC-JP');
} else {
- bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
- }
- }
- if (isset($languages[$sm_notAlias]['LOCALE'])){
- $longlocale=$languages[$sm_notAlias]['LOCALE'];
- } else {
- $longlocale=$sm_notAlias;
- }
+ bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
+ }
+ }
+ if (isset($languages[$sm_notAlias]['LOCALE'])){
+ $longlocale=$languages[$sm_notAlias]['LOCALE'];
+ } else {
+ $longlocale=$sm_notAlias;
+ }
if ( !ini_get('safe_mode') &&
getenv( 'LC_ALL' ) != $longlocale ) {
putenv( "LC_ALL=$longlocale" );
putenv( "LANG=$longlocale" );
putenv( "LANGUAGE=$longlocale" );
}
- setlocale(LC_ALL, $longlocale);
-
- // Set text direction/alignment variables
- if (isset($languages[$sm_notAlias]['DIR']) &&
- $languages[$sm_notAlias]['DIR'] == 'rtl') {
- $text_direction='rtl';
- $left_align='right';
- $right_align='left';
- } else {
- $text_direction='ltr';
- $left_align='left';
- $right_align='right';
- }
-
- $squirrelmail_language = $sm_notAlias;
+ setlocale(LC_ALL, $longlocale);
+
+ // Set text direction/alignment variables
+ if (isset($languages[$sm_notAlias]['DIR']) &&
+ $languages[$sm_notAlias]['DIR'] == 'rtl') {
+ /**
+ * Text direction
+ * @global string $text_direction
+ */
+ $text_direction='rtl';
+ /**
+ * Left alignment
+ * @global string $left_align
+ */
+ $left_align='right';
+ /**
+ * Right alignment
+ * @global string $right_align
+ */
+ $right_align='left';
+ } else {
+ $text_direction='ltr';
+ $left_align='left';
+ $right_align='right';
+ }
+
+ $squirrelmail_language = $sm_notAlias;
if ($squirrelmail_language == 'ja_JP') {
header ('Content-Type: text/html; charset=EUC-JP');
if (!function_exists('mb_internal_encoding')) {
- // Error messages can't be displayed here
- $error = 1;
- // Revert to English if possible.
- if (function_exists('setPref') && $username!='' && $data_dir!="") {
- setPref($data_dir, $username, 'language', "en_US");
- $error = 2;
- }
- // stop further execution in order not to get php errors on mb_internal_encoding().
- return $error;
+ // Error messages can't be displayed here
+ $error = 1;
+ // Revert to English if possible.
+ if (function_exists('setPref') && $username!='' && $data_dir!="") {
+ setPref($data_dir, $username, 'language', "en_US");
+ $error = 2;
+ }
+ // stop further execution in order not to get php errors on mb_internal_encoding().
+ return $error;
}
if (function_exists('mb_language')) {
mb_language('Japanese');
* Each 'language' definition requires NAME+CHARSET or ALIAS variables.
*
* @name $languages
- * @global $languages
+ * @global array $languages
*/
$languages['bg_BG']['NAME'] = 'Bulgarian';
$languages['bg_BG']['ALTNAME'] = 'Български';
$languages['et_EE']['LOCALE'] = 'et_EE.ISO8859-15';
$languages['et']['ALIAS'] = 'et_EE';
+$languages['eu_ES']['NAME'] = 'Basque';
+$languages['eu_ES']['CHARSET'] = 'iso-8859-1';
+$languages['eu_ES']['LOCALE'] = 'eu_ES.ISO8859-1';
+$languages['eu']['ALIAS'] = 'eu_ES';
+
$languages['fo_FO']['NAME'] = 'Faroese';
$languages['fo_FO']['CHARSET'] = 'iso-8859-1';
$languages['fo_FO']['LOCALE'] = 'fo_FO.ISO8859-1';
$languages['ko_KR']['NAME'] = 'Korean';
$languages['ko_KR']['CHARSET'] = 'euc-KR';
$languages['ko_KR']['LOCALE'] = 'ko_KR.EUC-KR';
-$languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
+// Function does not provide all needed options
+// $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
$languages['ko']['ALIAS'] = 'ko_KR';
$languages['lt_LT']['NAME'] = 'Lithuanian';
} else {
/* Uh-ho. A weird install */
if (! $gettext_flags & 1) {
+ /**
+ * Function is used as replacement in broken installs
+ * @ignore
+ */
function _($str) {
return $str;
}
}
if (! $gettext_flags & 2) {
+ /**
+ * Function is used as replacement in broken installs
+ * @ignore
+ */
function bindtextdomain() {
return;
}
}
if (! $gettext_flags & 4) {
+ /**
+ * Function is used as replacemet in broken installs
+ * @ignore
+ */
function textdomain() {
return;
}
* Default return value is defined by second argument.
* Use of third argument depends on action.
*
- * @param string action performed by this function.
+ * @param string $action action performed by this function.
* possible values:
- * decode - convert returned string to euc-jp. third argument unused
- * encode - convert returned string to jis. third argument unused
- * strimwidth - third argument=$width. trims string to $width symbols.
- * encodeheader - create base64 encoded header in iso-2022-jp. third argument unused
- * decodeheader - return human readable string from mime header. string is returned in euc-jp. third argument unused
- * downloadfilename - third argument $useragent. Arguments provide browser info. Returns shift-jis or euc-jp encoded file name
- * wordwrap - third argument=$wrap. wraps text at $wrap symbols
- * utf7-imap_encode - returns string converted from euc-jp to utf7-imap. third argument unused
- * utf7-imap_decode - returns string converted from utf7-imap to euc-jp. third argument unused
- * @param string default return value
+ * decode - convert returned string to euc-jp. third argument unused
+ * encode - convert returned string to jis. third argument unused
+ * strimwidth - third argument=$width. trims string to $width symbols.
+ * encodeheader - create base64 encoded header in iso-2022-jp. third argument unused
+ * decodeheader - return human readable string from mime header. string is returned in euc-jp. third argument unused
+ * downloadfilename - third argument $useragent. Arguments provide browser info. Returns shift-jis or euc-jp encoded file name
+ * wordwrap - third argument=$wrap. wraps text at $wrap symbols
+ * utf7-imap_encode - returns string converted from euc-jp to utf7-imap. third argument unused
+ * utf7-imap_decode - returns string converted from utf7-imap to euc-jp. third argument unused
+ * @param string $ret default return value
*/
function japanese_charset_xtra() {
$ret = func_get_arg(1); /* default return value */
*
* @param string action performed by this function.
* possible values:
- * downloadfilename - Hangul(Korean Character) Attached File Name Fix.
+ * downloadfilename - Hangul(Korean Character) Attached File Name Fix.
* @param string default return value
*/
function korean_charset_xtra() {
switch ($default_charset):
case "windows-1251":
if ( $input_charset == "iso-8859-5" ||
- $input_charset == "koi8-r" ||
- $input_charset == "koi8-u" ) {
+ $input_charset == "koi8-r" ||
+ $input_charset == "koi8-u" ) {
return true;
} else {
return false;
}
case "windows-1257":
if ( $input_charset == "iso-8859-13" ||
- $input_charset == "iso-8859-4" ) {
+ $input_charset == "iso-8859-4" ) {
return true;
} else {
return false;
}
case "iso-8859-4":
if ( $input_charset == "iso-8859-13" ||
- $input_charset == "windows-1257" ) {
+ $input_charset == "windows-1257" ) {
return true;
} else {
return false;
}
case "iso-8859-5":
if ( $input_charset == "windows-1251" ||
- $input_charset == "koi8-r" ||
- $input_charset == "koi8-u" ) {
+ $input_charset == "koi8-r" ||
+ $input_charset == "koi8-u" ) {
return true;
} else {
return false;
}
case "koi8-r":
if ( $input_charset == "windows-1251" ||
- $input_charset == "iso-8859-5" ||
- $input_charset == "koi8-u" ) {
+ $input_charset == "iso-8859-5" ||
+ $input_charset == "koi8-u" ) {
return true;
} else {
return false;
}
case "koi8-u":
if ( $input_charset == "windows-1251" ||
- $input_charset == "iso-8859-5" ||
- $input_charset == "koi8-r" ) {
+ $input_charset == "iso-8859-5" ||
+ $input_charset == "koi8-r" ) {
return true;
} else {
return false;