* existing PHP installation and implements fallback functions when required
* functions are not available. Scripts in functions/ directory should not
* setup anything when they are loaded.
- * @copyright © 1999-2007 The SquirrelMail Project Team
+ * @copyright © 1999-2009 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package squirrelmail
* (OPTIONAL; default is SquirrelMail
* locale directory).
*
- * @return void
+ * @return string The name of the text domain that was set
+ * *BEFORE* it is changed herein - NOTE that
+ * this differs from PHP's textdomain()
*
* @since 1.5.2 and 1.4.10
*/
function sq_change_text_domain($domain_name, $directory='') {
- if (empty($directory)) $directory = SM_PATH . 'locale/';
-
static $domains_already_seen = array();
+ global $gettext_domain;
+ $return_value = $gettext_domain;
+
+ // empty domain defaults to "squirrelmail"
+ //
+ if (empty($domain_name)) $domain_name = 'squirrelmail';
// only need to call bindtextdomain() once
//
if (in_array($domain_name, $domains_already_seen)) {
sq_textdomain($domain_name);
- return;
+ return $return_value;
}
$domains_already_seen[] = $domain_name;
+ if (empty($directory)) $directory = SM_PATH . 'locale/';
+
sq_bindtextdomain($domain_name, $directory);
sq_textdomain($domain_name);
+ return $return_value;
}
/**
*
* @since 1.4.10 and 1.5.1
* @param string $domain gettext domain name
- * @param string $dir directory that contains all translations
+ * @param string $dir directory that contains all translations (OPTIONAL;
+ * if not specified, defaults to SquirrelMail locale
+ * directory)
* @return string path to translation directory
*/
-function sq_bindtextdomain($domain,$dir) {
+function sq_bindtextdomain($domain,$dir='') {
global $l10n, $gettext_flags, $sm_notAlias;
+ if (empty($dir)) $dir = SM_PATH . 'locale/';
+
if ($gettext_flags==7) {
// gettext extension without ngettext
if (substr($dir, -1) != '/') $dir .= '/';
* @return string $charset Adjusted name of charset
*/
function fixcharset($charset) {
- /* remove minus and characters that might be used in paths from charset
+
+ /* Remove minus and characters that might be used in paths from charset
* name in order to be able to use it in function names and include calls.
+ * Also make sure it's in lower case (ala "UTF" --> "utf")
*/
- $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
+ $charset=preg_replace("/[-:.\/\\\]/",'_', strtolower($charset));
// OE ks_c_5601_1987 > cp949
$charset=str_replace('ks_c_5601_1987','cp949',$charset);
* 1 = mbstring support is not present,
* 2 = mbstring support is not present, user's translation reverted to en_US.
*
- * @param string $sm_language translation used by user's interface
- * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
- * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
+ * @param string $sm_language Translation used by user's interface
+ * @param bool $do_search Use browser's preferred language detection functions.
+ * Defaults to false.
+ * @param bool $default Set $sm_language to $squirrelmail_default_language if
+ * language detection fails or language is not set.
+ * Defaults to false.
+ * @param string $content_type The content type being served currently (OPTIONAL;
+ * if not specified, defaults to whatever the template
+ * set that is in use has defined).
+ *
* @return int function execution error codes.
+ *
*/
-function set_up_language($sm_language, $do_search = false, $default = false) {
+function set_up_language($sm_language, $do_search=false,
+ $default=false, $content_type='') {
static $SetupAlready = 0;
- global $use_gettext, $languages,
+ global $use_gettext, $languages, $oTemplate,
$squirrelmail_language, $squirrelmail_default_language, $default_charset,
$sm_notAlias, $username, $data_dir;
$SetupAlready = TRUE;
sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
+ // grab content type if needed
+ //
+ if (empty($content_type)) $content_type = $oTemplate->get_content_type();
+
/**
* If function is asked to detect preferred language
* OR squirrelmail default language is set to empty string
$squirrelmail_language = $sm_notAlias;
if ($squirrelmail_language == 'ja_JP') {
- header ('Content-Type: text/html; charset=EUC-JP');
+ $oTemplate->header ('Content-Type: ' . $content_type . '; charset=EUC-JP');
if (!function_exists('mb_internal_encoding')) {
// Error messages can't be displayed here
$error = 1;
mb_internal_encoding('EUC-JP');
mb_http_output('pass');
} elseif ($squirrelmail_language == 'en_US') {
- header( 'Content-Type: text/html; charset=' . $default_charset );
+ $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $default_charset );
} else {
- header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
+ $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $languages[$sm_notAlias]['CHARSET'] );
}
/**
* mbstring.func_overload fix (#929644).
* ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
* LOCALE - Full locale name (in xx_XX.charset format). It can use array with more than one locale name since 1.4.5 and 1.5.1
* DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
- * XTRA_CODE - translation uses special functions. See doc/i18n.txt
+ * XTRA_CODE - translation uses special functions. See http://www.squirrelmail.org/docs/devel/devel-3.html
*
* Each 'language' definition requires NAME+CHARSET or ALIAS variables.
*