Esempio n. 1
0
function set_timezone($lang = '')
{
    if (empty($lang)) {
        return array('UTC', 0);
    }
    $l = accept_language::split_locale_str($lang);
    // When the name of a country is uncertain (国名が不明な場合)
    if (empty($l[2])) {
        $obj_l2c = new lang2country();
        $l[2] = $obj_l2c->get_lang2country($l[1]);
        if (empty($l[2])) {
            return array('UTC', 0);
        }
    }
    $obj = new timezone();
    $obj->set_datetime(UTIME);
    // Setting at judgment time. (判定時刻の設定)
    $obj->set_country($l[2]);
    // The acquisition country is specified. (取得国を指定)
    // With the installation country in case of the same
    // 設置者の国と同一の場合
    if ($lang == DEFAULT_LANG) {
        if (defined('DEFAULT_TZ_NAME')) {
            $obj->set_tz_name(DEFAULT_TZ_NAME);
        }
    }
    list($zone, $zonetime) = $obj->get_zonetime();
    if ($zonetime == 0 || empty($zone)) {
        return array('UTC', 0);
    }
    return array($zone, $zonetime);
}
function plugin_multilang_inline_link($option, $args)
{
    global $vars;
    $body = array();
    $page = $vars['page'];
    $url = get_cmd_uri('multilang', $page, '', 'lang');
    $obj_l2c = new lang2country();
    foreach ($args as $arg) {
        $arg = htmlspecialchars($arg);
        @(list($lang, $style) = split('\\+', $arg));
        // en_US=English+flag=us
        @(list($lang, $title) = split('=', $lang));
        @(list($style, $country) = split('=', $style));
        if ($style != 'text') {
            // flag or text : default is flag
            if (empty($country)) {
                @(list($lng, $country) = split('_', $lang));
                // en_US -> en, US
                if (empty($country)) {
                    $country = $obj_l2c->get_lang2country(strtolower($lng));
                }
            }
            if (!empty($country)) {
                $country = strtolower($country);
                $title = '<img src="' . IMAGE_URI . 'icon/flags/' . $country . '.png" alt="' . $title . '" title="' . $title . '" />';
            }
        }
        array_push($body, '<a href="' . $url . $lang . '">' . $title . '</a>');
    }
    if ($option == 'delim') {
        // default: nodelim
        return PLUGIN_MULTILANG_INLINE_BEFORE . join(PLUGIN_MULTILANG_INLINE_DELIMITER, $body) . PLUGIN_MULTILANG_INLINE_AFTER;
    }
    return join(' ', $body);
}
Esempio n. 3
0
function get_language($level = 0)
{
    global $language_prepared;
    if ($level == 0) {
        return DEFAULT_LANG;
    }
    $lng_func = array('get_cookie_lang', 'get_accept_language', 'get_user_agent_mozilla', 'get_accept_charset', 'get_remote_addr');
    $obj_lng = new accept_language();
    $level = $level > count($lng_func) ? count($lng_func) : $level;
    $obj_l2c = new lang2country();
    for ($i = 0; $i < $level; $i++) {
        if ($i == $level) {
            return DEFAULT_LANG;
        }
        // 指定関数の実行
        $_x = $obj_lng->{$lng_func}[$i]();
        if (!is_array($_x)) {
            continue;
        }
        foreach ($_x as $_lang) {
            // 完全一致の場合 (ex. ja_JP)
            if (in_array($_lang[0], $language_prepared)) {
                return $_lang[0];
            }
            // 言語のみの場合の対応
            $_x1 = split('_', $_lang[0]);
            if (count($_x1) == 2) {
                continue;
            }
            $c = $obj_l2c->get_lang2country($_x1[0]);
            if (empty($c)) {
                continue;
            }
            $str = $_x1[0] . '_' . $c;
            if (in_array($str, $language_prepared)) {
                return $str;
            }
        }
    }
    return DEFAULT_LANG;
}