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


PHP h2o::getOptions方法代碼示例

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


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

示例1: templize

function templize($source)
{
    $output = array();
    $inline_re = '/^\\s*trans\\s+("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')\\s*/';
    $block_re = "/^\\s*blocktrans(?:\\s+|\$)/";
    $endblock_re = "/^\\s*endblocktrans\$/";
    $plural_re = "/^\\s*plural\$/";
    $var_re = '{
        _\\(
            (
            "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" |   # Double Quote string   
            \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' # Single Quote String
            )
        \\)
    }x';
    $lexer = new H2o_Lexer(h2o::getOptions());
    $tokenstream = $lexer->tokenize($source);
    $in_block = false;
    $is_plural = false;
    $singulars = array();
    $plurals = array();
    while ($t = $tokenstream->next()) {
        if ($in_block) {
            if ($t->type == 'block' && $t->content == 'endblocktrans') {
                if ($is_plural) {
                    $output[] = sprintf(" ngettext('%s', '%s', \$count)", join('', $singulars), join('', $plurals));
                } else {
                    $output[] = sprintf(" gettext('%s')", join('', $singulars));
                }
                $singulars = $plurals = array();
                $in_block = $is_plural = false;
            } elseif ($t->type == 'block' && $t->content == 'plural') {
                $is_plural = true;
            } elseif ($t->type == 'text') {
                if ($is_plural) {
                    $plurals[] = addslashes($t->content);
                } else {
                    $singulars[] = addslashes($t->content);
                }
            } elseif ($t->type == 'variable') {
                @(list($var, $filters) = explode('|', $t->content));
                if ($is_plural) {
                    $plurals[] = sprintf("%%(%s)", $var);
                } else {
                    $singulars[] = sprintf("%%(%s)", $var);
                }
            } elseif ($t->type == 'block') {
                throw new Exception('No block tag is allowed in translation block');
            }
        } else {
            if ($t->type == 'block') {
                if (preg_match($inline_re, $t->content, $matches)) {
                    $output[] = sprintf(" gettext(%s)", $matches[1]);
                } elseif (preg_match($block_re, $t->content, $matches)) {
                    $in_block = true;
                }
            } elseif ($t->type == 'variable') {
                if (preg_match($var_re, $t->content, $matches)) {
                    $output[] = sprintf(" gettext(%s)", $matches[1]);
                }
            }
        }
    }
    $result = str_replace("\r", '', implode(";\n", $output));
    if ($result) {
        return "\n" . $result . ";\n";
    }
}
開發者ID:hbasria,項目名稱:pjango,代碼行數:68,代碼來源:i18n.php


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