當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TranslateUtils::assetPath方法代碼示例

本文整理匯總了PHP中TranslateUtils::assetPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP TranslateUtils::assetPath方法的具體用法?PHP TranslateUtils::assetPath怎麽用?PHP TranslateUtils::assetPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TranslateUtils的用法示例。


在下文中一共展示了TranslateUtils::assetPath方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: languages

    /**
     * @param $data
     * @param $params
     * @param $parser Parser
     * @return string
     */
    public static function languages($data, $params, $parser)
    {
        $title = $parser->getTitle();
        // Check if this is a source page or a translation page
        $page = TranslatablePage::newFromTitle($title);
        if ($page->getMarkedTag() === false) {
            $page = TranslatablePage::isTranslationPage($title);
        }
        if ($page === false || $page->getMarkedTag() === false) {
            return '';
        }
        $status = $page->getTranslationPercentages();
        if (!$status) {
            return '';
        }
        // Fix title
        $title = $page->getTitle();
        // Sort by language code, which seems to be the only sane method
        ksort($status);
        $options = $parser->getOptions();
        if (method_exists($options, 'getUserLang')) {
            $userLangCode = $options->getUserLang();
        } else {
            // Backward compat for MediaWiki 1.17
            global $wgLang;
            $userLangCode = $wgLang->getCode();
        }
        // BC for <1.19
        $linker = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
        $languages = array();
        foreach ($status as $code => $percent) {
            $name = TranslateUtils::getLanguageName($code, false, $userLangCode);
            $name = htmlspecialchars($name);
            // Unlikely, but better safe
            /* Percentages are too accurate and take more
             * space than simple images */
            $percent *= 100;
            if ($percent < 20) {
                $image = 1;
            } elseif ($percent < 40) {
                $image = 2;
            } elseif ($percent < 60) {
                $image = 3;
            } elseif ($percent < 80) {
                $image = 4;
            } else {
                $image = 5;
            }
            $percent = Xml::element('img', array('src' => TranslateUtils::assetPath("resources/images/prog-{$image}.png"), 'alt' => "{$percent}%", 'title' => "{$percent}%", 'width' => '9', 'height' => '9'));
            // Add links to other languages
            $suffix = $code === 'en' ? '' : "/{$code}";
            $_title = Title::makeTitle($title->getNamespace(), $title->getDBkey() . $suffix);
            if ($parser->getTitle()->getText() === $_title->getText()) {
                $name = Html::rawElement('span', array('class' => 'mw-pt-languages-selected'), $name);
                $languages[] = "{$name} {$percent}";
            } else {
                if ($code === $userLangCode) {
                    $name = Html::rawElement('span', array('class' => 'mw-pt-languages-ui'), $name);
                }
                $languages[] = $linker->linkKnown($_title, "{$name} {$percent}");
            }
        }
        $legend = wfMsg('tpt-languages-legend');
        $languages = implode(wfMsg('tpt-languages-separator'), $languages);
        return <<<FOO
<div class="mw-pt-languages">
<table><tbody>

<tr valign="top">
<td class="mw-pt-languages-label"><b>{$legend}</b></td>
<td class="mw-pt-languages-list">{$languages}</td></tr>

</tbody></table>
</div>
FOO;
    }
開發者ID:schwarer2006,項目名稱:wikia,代碼行數:82,代碼來源:PageTranslationHooks.php


注:本文中的TranslateUtils::assetPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。