*
* @param string $charset
* @param string $string Text to be decoded
- * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
+ * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
* Argument is available since 1.5.1 and 1.4.5.
* @return string decoded string
*/
$SetupAlready = TRUE;
sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
- if ($do_search && ! $sm_language && isset($accept_lang)) {
+ /**
+ * If function is asked to detect preferred language
+ * OR squirrelmail default language is set to empty string
+ * AND
+ * squirrelmail language ($sm_language) is empty string
+ * (not set in user's prefs and no cookie with language info)
+ * AND
+ * browser provides list of preferred languages
+ * THEN
+ * get preferred language from HTTP_ACCEPT_LANGUAGE header
+ */
+ if (($do_search || empty($squirrelmail_default_language)) &&
+ ! $sm_language &&
+ isset($accept_lang)) {
+ // TODO: use more than one language, if first language is not available
+ // FIXME: function assumes that string contains two or more characters.
+ // FIXME: some languages use 5 chars
$sm_language = substr($accept_lang, 0, 2);
}
- if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
+ /**
+ * If language preference is not set OR script asks to use default language
+ * AND
+ * default squirrelmail language is not set to empty string
+ * THEN
+ * use default squirrelmail language value from configuration.
+ */
+ if ((!$sm_language||$default) &&
+ ! empty($squirrelmail_default_language)) {
$squirrelmail_language = $squirrelmail_default_language;
$sm_language = $squirrelmail_default_language;
}
+
+ /** provide failsafe language when detection fails */
+ if (! $sm_language) $sm_language='en_US';
+
$sm_notAlias = $sm_language;
// Catching removed translation
} else {
header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
}
-
/**
* mbstring.func_overload fix (#929644).
*
- * php mbstring extension can replace standard string functions with their multibyte
- * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload.
+ * php mbstring extension can replace standard string functions with their multibyte
+ * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
+ * was added in php v.4.2.0
*
* Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
* to use mbstring functions and mbstring internal encoding is set to multibyte charset,
- * interface can't trust regular string functions. Due to mbstring overloading design
+ * interface can't trust regular string functions. Due to mbstring overloading design
* limits php scripts can't control this setting.
*
* This hack should fix some issues related to 8bit strings in passwords. Correct fix is
* to disable mbstring overloading. Japanese translation uses different internal encoding.
*/
- if ($squirrelmail_language != 'ja_JP' &&
+ if ($squirrelmail_language != 'ja_JP' &&
function_exists('mb_internal_encoding') &&
check_php_version(4,2,0) &&
(int)ini_get('mbstring.func_overload')!=0) {
- mb_internal_encoding('ASCII');
+ mb_internal_encoding('pass');
}
}
return 0;
* Sets default_charset variable according to the one that is used by user's translations.
*
* Function changes global $default_charset variable in order to be sure, that it
- * contains charset used by user's translation. Sanity of $squirrelmail_default_language
- * and $default_charset combination provided in SquirrelMail config is also tested.
+ * contains charset used by user's translation. Sanity of $squirrelmail_language
+ * and $default_charset combination is also tested.
*
* There can be a $default_charset setting in the
* config.php file, but the user may have a different language
* message blindly with the system-wide $default_charset.
*/
function set_my_charset(){
- global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
+ global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
$my_language = getPref($data_dir, $username, 'language');
if (!$my_language) {
- $my_language = $squirrelmail_default_language ;
+ $my_language = $squirrelmail_language ;
}
// Catch removed translation
if (!isset($languages[$my_language])) {
global $squirrelmail_language, $languages, $use_gettext;
-if (! isset($squirrelmail_language)) {
+if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE)) {
$squirrelmail_language = '';
}
*
* Each 'language' definition requires NAME+CHARSET or ALIAS variables.
*
+ * @todo TODO: make language loading modular (similar to plugins, with locale/xx_XX/setup.php files)
* @name $languages
* @global array $languages
*/