当前位置: 首页>>代码示例>>PHP>>正文


PHP Zikula_View::getDomain方法代码示例

本文整理汇总了PHP中Zikula_View::getDomain方法的典型用法代码示例。如果您正苦于以下问题:PHP Zikula_View::getDomain方法的具体用法?PHP Zikula_View::getDomain怎么用?PHP Zikula_View::getDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zikula_View的用法示例。


在下文中一共展示了Zikula_View::getDomain方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: smarty_block_gettext

/**
 * Zikula_View function to use the _dgettext() function
 *
 * This function takes a identifier and returns the corresponding language constant.
 *
 * Available parameters:
 *   - text:     (required) string to translate
 *   - tagN:     (optional) replace for sprintf() e.g. %s or %1$s
 *   - domain:   (optional) textdomain to be used (not required, the system will fill this out automatically
 *   - comment:  (optional) comment to the translator (this is not processed by this code)
 *   - assign:   If set, the results are assigned to the corresponding variable instead of printed out
 *
 * Examples
 * {gettext}Hello world{/gettext}
 * {gettext tag1=$name}Hello %s{/gettext}
 * {gettext  tag1=$city tag2=$country comment="%1 is a name %2 is the place"}Hello %1$s, welcome to %2$s{/gettext}
 *
 * String replacement follows the rules at http://php.net/sprintf but please note Smarty seems to pass
 * all variables as strings so %s and %n$s are mostly used.
 *
 * @param array       $params  All attributes passed to this function from the template.
 * @param string      $content The block content.
 * @param Zikula_View $view    Reference to the Zikula_View object.
 *
 * @return string Translation if it was available.
 */
function smarty_block_gettext($params, $content, Zikula_View $view)
{
    if ($content) {
        if (isset($params['domain'])) {
            $domain = strtolower($params['domain']) == 'zikula' ? null : $params['domain'];
        } else {
            $domain = $view->getDomain();
            // default domain
        }
        // build array for tags (for %s, %1$s etc) if applicable
        ksort($params);
        $tags = array();
        foreach ($params as $key => $value) {
            if (preg_match('#^tag([0-9]{1,2})$#', $key)) {
                $tags[] = $value;
            }
        }
        $tags = count($tags) == 0 ? null : $tags;
        // perform gettext
        $output = isset($tags) ? __f($content, $tags, $domain) : __($content, $domain);
        if (isset($params['assign'])) {
            $render->assign($params['assign'], $output);
        } else {
            return $output;
        }
    }
}
开发者ID:Silwereth,项目名称:core,代码行数:53,代码来源:block.gettext.php

示例2: smarty_modifier_gt

/**
 * Zikula_View modifier to parse gettext string.
 *
 * Example
 *
 *   {$var|gt:$zikula_view}
 *
 * @param string      $string The contents to transform.
 * @param Zikula_View $view   This Zikula_View object (available as $renderObject in templates).
 *
 * @return string The modified output.
 */
function smarty_modifier_gt($string, $view)
{
    if (!$view instanceof Zikula_View) {
        return __('Error! With modifier_gt, you must use the following form for the gettext modifier (\'gt\'): $var|gt:$zikula_view');
    }
    return __($string, $view->getDomain());
}
开发者ID:Silwereth,项目名称:core,代码行数:19,代码来源:modifier.gt.php

示例3: smarty_function_gt

/**
 * Zikula_View function to use the _dgettext() function
 *
 * This function takes a identifier and returns the corresponding language constant.
 *
 * Available parameters:
 *   - text:     (required) string to translate
 *   - plural:   (optional) plural version of the string
 *   - count:    (optional) if we have plural we need to specify the count
 *   - tagN:     (optional) replace for sprintf() e.g. %s or %1$s
 *   - domain:   (optional) textdomain to be used (not required, the system will fill this out automatically
 *   - comment:  (optional) comment to the translator (this is not processed by this code)
 *   - assign:   If set, the results are assigned to the corresponding variable instead of printed out
 *
 * Examples
 * {gt text="Hello world"}
 * {gt text="Hello %s" tag1=$name}
 * {gt text="You want one cup" plural="You want two cups" count=2}
 * {gt text='Hello %1$s, welcome to %2$s' tag1=$city tag2=$country comment="%1 is a name %2 is the place"}
 * ## WARNING! When using %1$s in a template, smarty compiles this to PHP so the string must be in single quotes or
 * ## the $s will be evaluated as variable $s
 *
 *
 * String replacement follows the rules at http://php.net/sprintf but please note Smarty seems to pass
 * all variables as strings so %s and %n$s are mostly used.
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string Translation if it was available.
 */
function smarty_function_gt($params, Zikula_View $view)
{
    // the check order here is important because:
    // if we are calling from a theme both $view->themeDomain and $view->renderDomain are set.
    // if the call was from a template only $view->renderDomain is set.
    if (isset($params['domain'])) {
        $domain = (strtolower($params['domain']) == 'zikula' ? null : $params['domain']);
    } else {
        $domain = $view->getDomain(); // default domain
    }

    if (!isset($params['text'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_gt', 'text')));
        return false;
    }
    $text = $params['text'];

    // validate plural settings if applicable
    if ((!isset($params['count']) && isset($params['plural'])) || (isset($params['count']) && !isset($params['plural']))) {
        $view->trigger_error(__('Error! If you use a plural or count in gettext, you must use both parameters together.'));
        return false;
    }

    $count = (isset($params['count']) ? (int)$params['count'] : 0);
    $plural = (isset($params['plural']) ? $params['plural'] : false);

    // build array for tags (for %s, %1$s etc) if applicable
    ksort($params);
    $tags = array();
    foreach ($params as $key => $value) {
        if (preg_match('#^tag([0-9]{1,2})$#', $key)) {
            $tags[] = $value;
        }
    }
    $tags = (count($tags) == 0 ? null : $tags);

    // perform gettext
    if ($plural) {
        $result = (isset($tags) ? _fn($text, $plural, $count, $tags, $domain) : _n($text, $plural, $count, $domain));
    } else {
        $result = (isset($tags) ? __f($text, $tags, $domain) : __($text, $domain));
    }

    // assign or return
    if (isset($params['assign'])) {
        $view->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
开发者ID:,项目名称:,代码行数:81,代码来源:


注:本文中的Zikula_View::getDomain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。