Esempio n. 1
0
File: i18n.php Progetto: jprice/EHCP
/**
 * Wrapper for textdomain(), bindtextdomain() and
 * bind_textdomain_codeset() primarily intended for
 * plugins when changing into their own text domain
 * and back again.
 *
 * Note that if plugins using this function have
 * their translation files located in the SquirrelMail
 * locale directory, the second argument is optional.
 *
 * @param string $domain_name The name of the text domain
 *                            (usually the plugin name, or
 *                            "squirrelmail") being switched to.
 * @param string $directory   The directory that contains 
 *                            all translations for the domain
 *                            (OPTIONAL; default is SquirrelMail
 *                            locale directory).
 *
 * @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 = '')
{
    global $use_gettext;
    static $domains_already_seen = array();
    $return_value = textdomain(NULL);
    // empty domain defaults to "squirrelmail"
    //
    if (empty($domain_name)) {
        $domain_name = 'squirrelmail';
    }
    // only need to call bindtextdomain() once unless
    // $use_gettext is turned on
    //
    if (!$use_gettext && in_array($domain_name, $domains_already_seen)) {
        textdomain($domain_name);
        return $return_value;
    }
    $domains_already_seen[] = $domain_name;
    if (empty($directory)) {
        $directory = SM_PATH . 'locale/';
    }
    sq_bindtextdomain($domain_name, $directory);
    textdomain($domain_name);
    return $return_value;
}
Esempio n. 2
0
/**
 * Set up the language to be output
 * if $do_search is true, then scan the browser information
 * for a possible language that we know
 *
 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
 * gettext translation bindings and html header information.
 *
 * Function returns error codes, if there is some fatal error.
 *  0 = no error,
 *  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.
 * @return int function execution error codes.
 */
function set_up_language($sm_language, $do_search = false, $default = false)
{
    static $SetupAlready = 0;
    global $use_gettext, $languages, $squirrelmail_language, $squirrelmail_default_language, $default_charset, $sm_notAlias, $username, $data_dir;
    if ($SetupAlready) {
        return;
    }
    $SetupAlready = TRUE;
    sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
    if ($do_search && !$sm_language && isset($accept_lang)) {
        $sm_language = substr($accept_lang, 0, 2);
    }
    if ((!$sm_language || $default) && isset($squirrelmail_default_language)) {
        $squirrelmail_language = $squirrelmail_default_language;
        $sm_language = $squirrelmail_default_language;
    }
    $sm_notAlias = $sm_language;
    // Catching removed translation
    // System reverts to English translation if user prefs contain translation
    // that is not available in $languages array
    if (!isset($languages[$sm_notAlias])) {
        $sm_notAlias = "en_US";
    }
    while (isset($languages[$sm_notAlias]['ALIAS'])) {
        $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
    }
    if (isset($sm_language) && $use_gettext && $sm_language != '' && isset($languages[$sm_notAlias]['CHARSET'])) {
        sq_bindtextdomain('squirrelmail', SM_PATH . 'locale/');
        sq_textdomain('squirrelmail');
        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;
        }
        if (!ini_get('safe_mode') && getenv('LC_ALL') != $longlocale) {
            putenv("LC_ALL={$longlocale}");
            putenv("LANG={$longlocale}");
            putenv("LANGUAGE={$longlocale}");
            putenv("LC_NUMERIC=C");
            if ($sm_notAlias == 'tr_TR') {
                putenv("LC_CTYPE=C");
            }
        }
        setlocale(LC_ALL, $longlocale);
        // Workaround for plugins that use numbers with floating point
        // It might be removed if plugins use correct decimal delimiters
        // according to locale settings.
        setlocale(LC_NUMERIC, 'C');
        // Workaround for specific Turkish strtolower/strtoupper rules.
        // Many functions expect English conversion rules.
        if ($sm_notAlias == 'tr_TR') {
            setlocale(LC_CTYPE, 'C');
        }
        // 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;
            }
            if (function_exists('mb_language')) {
                mb_language('Japanese');
            }
            mb_internal_encoding('EUC-JP');
            mb_http_output('pass');
        } elseif ($squirrelmail_language == 'en_US') {
            header('Content-Type: text/html; charset=' . $default_charset);
        } else {
            header('Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET']);
        }
    }
    return 0;
}
Esempio n. 3
0
/**/
if (file_exists('../../include/init.php')) {
    include_once '../../include/init.php';
} else {
    if (file_exists('../../include/validate.php')) {
        //if (!defined('SM_PATH')) define('SM_PATH', '../../');
        define('SM_PATH', '../../');
        include_once SM_PATH . 'include/validate.php';
    } else {
        chdir('..');
        include_once '../src/validate.php';
    }
}
displayPageHeader($color, 'none');
/** sm 1.5.1 code */
sq_bindtextdomain('test', SM_PATH . 'locale');
sq_textdomain('test');
?>
<h3 align="center">ngettext test strings</h3>
<p>Test depends on selected translation and translated strings in 
locale/xx/LC_MESSAGES/test.mo files.</p>

<?php 
echo "<pre>";
for ($i = -10; $i <= 250; $i++) {
    echo sprintf(ngettext("%s squirrel on the tree.", "%s squirrels on the tree.", $i), $i);
    echo "\n";
}
echo "</pre>";
sq_textdomain('squirrelmail');
echo "</body></html>";