Exemple #1
0
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;
    if ($SetupAlready) {
        return;
    }
    $SetupAlready = TRUE;
    sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
    /**
     * detect preferred language from header when SquirrelMail asks for
     * it or when default language is set to empty string.
     */
    if (($do_search || empty($squirrelmail_default_language)) && !$sm_language && isset($accept_lang)) {
        $sm_language = substr($accept_lang, 0, 2);
    }
    /**
     * Use default language when it is not detected or when script
     * asks to use default language.
     */
    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;
    /**
     * Catch 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'])) {
        bindtextdomain('squirrelmail', SM_PATH . 'locale/');
        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']);
            }
        }
        // Use LOCALE key, if it is set.
        if (isset($languages[$sm_notAlias]['LOCALE'])) {
            $longlocale = $languages[$sm_notAlias]['LOCALE'];
        } else {
            $longlocale = $sm_notAlias;
        }
        // try setting locale
        $retlocale = sq_setlocale(LC_ALL, $longlocale);
        // check if locale is set and assign that locale to $longlocale
        // in order to use it in putenv calls.
        if (!is_bool($retlocale)) {
            $longlocale = $retlocale;
        } elseif (is_array($longlocale)) {
            // setting of all locales failed.
            // we need string instead of array used in LOCALE key.
            $longlocale = $sm_notAlias;
        }
        if (!(bool) 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");
            }
        }
        // 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');
        }
        $squirrelmail_language = $sm_notAlias;
        if ($squirrelmail_language == 'ja_JP') {
            header('Content-Type: text/html; charset=EUC-JP');
            if (!function_exists('mb_internal_encoding')) {
                // don't display mbstring warning when user isn't logged
                // in because the user may not be using SM for Japanese;
                // also don't display on webmail page so user has the
                // chance to go back and revert their language setting
                // until admin can get their act together
                if (sqGetGlobalVar('user_is_logged_in', $user_is_logged_in, SQ_SESSION) && $user_is_logged_in && PAGE_NAME != 'webmail') {
                    echo _("You need to have PHP installed with the multibyte string function enabled (using configure option --enable-mbstring).");
                    // Revert to English link has to be added.
                    // stop further execution in order not to get php errors on mb_internal_encoding().
                }
                return;
            }
            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']);
        }
        // mbstring.func_overload<>0 fix. See cvs HEAD comments.
        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('pass');
        }
    }
}
Exemple #2
0
             if (isset($lang_data['LOCALE'])) {
                 $setlocale = $lang_data['LOCALE'];
             } else {
                 $setlocale = $lang_code;
             }
             /* prepare information about tested locales */
             if (is_array($setlocale)) {
                 $display_locale = implode(', ', $setlocale);
                 $locale_count = count($setlocale);
             } else {
                 $display_locale = $setlocale;
                 $locale_count = 1;
             }
             $tested_locales_msg = 'Tested ' . sm_encode_html_special_chars($display_locale) . ' ' . ($locale_count > 1 ? 'locales' : 'locale') . '.';
             echo $IND . $IND . $IND . $lang_data['NAME'] . ' (' . $lang_code . ') - ';
             $retlocale = sq_setlocale(LC_ALL, $setlocale);
             if (is_bool($retlocale)) {
                 echo '<font color="red">unsupported</font>. ';
                 echo $tested_locales_msg;
             } else {
                 echo 'supported. ' . $tested_locales_msg . ' setlocale() returned "' . sm_encode_html_special_chars($retlocale) . '"';
             }
             echo "<br />\n";
         }
     }
     echo $IND . $IND . '<a href="configtest.php">Don\'t test translations</a>';
 } else {
     echo $IND . $IND . '<a href="configtest.php?testlocales=1">Test translations</a>. ' . 'This test is not accurate and might work only on some systems.' . "\n";
 }
 echo "<br />\n";
 /* end of translation tests */