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


PHP i18n::getLang方法代码示例

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


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

示例1: smarty_block_t

/**
 * This method will translate or create an enter in the module xliff locale file
 * 
 * @param array $params         An array of parameters to give to i18n::translate()
 * @param string $content       The string to translate {t}...content...{/t}
 * @param Smarty $smarty        The current Smarty instance
 * @param boolean $repeat       Are we in the end of {t} tag
 * @return string               The translated string, else the original string
 */
function smarty_block_t($params, $content, &$smarty, &$repeat)
{
    if ($repeat == false) {
        // we get the template locale if setted by {setLocale} tag
        $srcLocale = isset($smarty->tpl_vars['TPL_LOCALE']) ? $smarty->tpl_vars['TPL_LOCALE']->value : i18n::getDefaultLocale();
        // if template locale is equal to current locale we don't need to translate
        if ($srcLocale === i18n::getLocale()) {
            return i18n::replaceArgs($content, $params);
        }
        // we get the template path
        $path = explode(DS, str_replace(APP_DIR . DS, '', $smarty->template_resource));
        // module var has been setted in smarty
        if (isset($smarty->smarty->module)) {
            $isModule = true;
            $module = $smarty->smarty->module;
        } else {
            $isModule = array_search('module', $path);
            if ($isModule !== false) {
                $module = $path[$isModule + 1];
            }
        }
        // we are in a module, we can translate
        if ($isModule !== false) {
            // Get locale file with full locale code (ex : fr_CA) for overloading
            if ($file = get_module_file($module, '/i18n/templates.' . $srcLocale . '.xml')) {
                $str = I18n::t($file, $content, $params, $srcLang, end($path));
                if ($str !== $string) {
                    return $str;
                }
                // There is a specific translation for full locale code, return
            }
            // get the lang code
            preg_match('/^([a-z]{2,3})[_-]([A-Z]{2})$/', $srcLocale, $m);
            $srcLang = $m[0];
            // If default lang is equal to the current lang : return
            if ($srcLang == i18n::getLang()) {
                return i18n::replaceArgs($content, $params);
            }
            // Get locale file with only lang code (ex : fr) or create it
            $file = get_module_file($module, '/i18n/templates.' . I18n::getLang() . '.xml', false);
            return I18n::t($file, $content, $params, $srcLang, end($path));
        }
        return i18n::replaceArgs($content, $params);
    }
}
开发者ID:salomalo,项目名称:php-oxygen,代码行数:54,代码来源:block.t.php

示例2: url

function url($action = null, $lang = null)
{
    // If an absolute URL is provided, simply return it
    if (preg_match('/^https?:\\/\\//', $action)) {
        return $action;
    }
    // Trim slashes
    $action = trim($action, '/');
    // i18n language prefix
    if (!$lang && Kennel::getSetting('i18n', 'enabled')) {
        $prefix = '/' . i18n::getLang();
    } elseif ($lang) {
        $prefix = "/{$lang}";
    } else {
        $prefix = '';
    }
    // Action string
    if ($action) {
        if (Kennel::getSetting('application', 'use_mod_rewrite')) {
            $url = Kennel::$ROOT_URL . "{$prefix}/{$action}/";
        } else {
            $url = Kennel::$ROOT_URL . "/index.php/{$prefix}/{$action}/";
        }
    } else {
        if (Kennel::getSetting('application', 'use_mod_rewrite')) {
            $url = Kennel::$ROOT_URL . ($prefix ? "{$prefix}/" : '/');
        } else {
            $url = Kennel::$ROOT_URL . ($prefix ? "/index.php/{$prefix}/" : '/');
        }
    }
    // Trim slash for query or hash strings
    if (strpos($url, '?') !== false || strpos($url, '#') !== false) {
        $url = trim($url, '/');
    }
    return $url;
}
开发者ID:rev087,项目名称:kennel,代码行数:36,代码来源:Core.php

示例3: _getOutput

 private function _getOutput()
 {
     // Make $template and $title accessible in the descendant views
     $this->__set('template', $this);
     $this->__set('title', $this->title);
     // Template View (must run first since ancestor views might call functions from $template)
     $templateView = XML::text($this->_template->__toString());
     // <html>
     $this->_html = XML::element('html');
     $this->_html->dir = $this->dir;
     if (Kennel::getSetting('i18n', 'enabled')) {
         $this->_html->lang = i18n::getLang();
     }
     // <head>
     $this->_head = XML::element('head', $this->_html);
     // <title>
     $title = XML::element('title', $this->_head);
     $title->setValue($this->getTitle());
     // favicon
     if ($this->favicon) {
         $this->_head->adopt(html::favicon($this->favicon));
     }
     // Content Type
     $this->_head->adopt(html::meta(array('charset' => 'utf-8')));
     // <meta>
     foreach ($this->_meta as $meta) {
         $this->_head->adopt(html::meta($meta));
     }
     // <link>
     foreach ($this->_links as $link) {
         $this->_head->adopt(html::link($link['rel'], $link['href'], $link['type'], $link['title']));
     }
     // <style>
     $this->_head->adopt(html::css($this->_stylesheets));
     // <script>
     $this->_head->adopt(html::js($this->_scripts));
     // <body>
     $this->_body = XML::element('body', $this->_html);
     $this->_body->class = browser::css();
     if (Kennel::getSetting('i18n', 'enabled')) {
         $this->_body->class .= ' ' . i18n::getLang();
     }
     if ($this->bodyClass) {
         $this->_body->class .= ' ' . $this->bodyClass;
     }
     // Inject the Template View
     $this->_body->adopt($templateView);
     // Return the whole shebang
     return self::$DOCTYPE_DECLARATIONS[$this->doctype] . $this->_html->output(true);
 }
开发者ID:rev087,项目名称:kennel,代码行数:50,代码来源:Template.php

示例4: i18n

 function i18n($lang = null)
 {
     // If i18n is not enabled, return itself
     if (!Kennel::getSetting('i18n', 'enabled')) {
         return $this;
     }
     if (!$lang) {
         $lang = i18n::getLang();
     }
     $primaryKey = $this->schema->getPrimaryKey()->name;
     $this->_fetchI18n();
     foreach ($this->_i18n as $i18n) {
         if ($i18n->lang == $lang) {
             return $i18n;
         }
     }
     // If no localized version was found, create one now
     $primaryKey = $this->schema->getPrimaryKey()->name;
     $i18n = new Model("{$this->model_name}_i18n");
     $i18n->__set("{$this->model_name}_{$primaryKey}", $this->{$primaryKey});
     $i18n->lang = $lang;
     // … and populate it with default values, if any.
     // Useful as base data for internationalization of existing, populated models
     foreach ($i18n->_data as $key => $value) {
         if ($key != 'id' && isset($this->_data[$key])) {
             $i18n->{$key} = $this->{$key};
         }
     }
     return $this->_i18n[] = $i18n;
 }
开发者ID:rev087,项目名称:kennel,代码行数:30,代码来源:Model.php

示例5: process

 static function process()
 {
     // Set the method
     self::$METHOD = $_SERVER['REQUEST_METHOD'];
     // Get the request parts
     $request_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     if (Kennel::getSetting('application', 'use_mod_rewrite')) {
         $action_string = substr(trim($request_url, '/'), strlen(Kennel::$ROOT_URL));
     } else {
         $action_string = substr(trim($request_url, '/'), strlen(Kennel::$ROOT_URL . '/index.php'));
     }
     $action_string = str_replace(strstr($action_string, '?'), '', $action_string);
     $action_array = array_filter(explode('/', $action_string));
     // Reasign action keys (to avoid empty entries due to double slashes) and convert to lowercase
     foreach ($action_array as $key => $part) {
         if ($part) {
             if (strpos($part, ':') === false) {
                 self::$PARTS[] = input::clean($part);
             } else {
                 $named_arg = explode(':', $part);
                 self::$NAMED_ARGS[$named_arg[0]] = $named_arg[1];
             }
         }
     }
     // Process any hooks if present
     if (is_array(self::$HOOKS) && count(self::$HOOKS > 0)) {
         foreach (self::$HOOKS as $hook) {
             self::$PARTS = call_user_func($hook, self::$PARTS);
         }
     }
     // Make the Resource String available to the API
     self::$RESOURCE = implode('/', self::$PARTS);
     // i18n URL redirection
     if (Kennel::getSetting('i18n', 'enabled') && Kennel::getSetting('i18n', 'redirect') && !router::$PREFIX) {
         header('location: ' . url(Request::$RESOURCE, i18n::getLang()));
     }
     // 0. Render the Home Page if no Request::PARTS are present
     if (count(self::$PARTS) == 0) {
         self::$CONTROLLER = 'Main';
         self::$ACTION = 'index';
     }
     // 1. First check: method in the main controller
     if (isset(self::$PARTS[0]) && method_exists('Main_controller', str_replace('-', '_', self::$PARTS[0]))) {
         self::$CONTROLLER = 'main';
         self::$ACTION = str_replace('-', '_', self::$PARTS[0]);
         self::$ARGS = array_slice(self::$PARTS, 1);
     }
     // 2. Second check: user defined controller...
     if (isset(self::$PARTS[0]) && is_file(Kennel::$ROOT_PATH . '/application/controllers/' . str_replace('-', '_', self::$PARTS[0]) . '.php')) {
         self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0]));
         if (isset(self::$PARTS[1]) && method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) {
             self::$ACTION = str_replace('-', '_', self::$PARTS[1]);
             self::$ARGS = array_slice(self::$PARTS, 2);
         } else {
             self::$ACTION = 'index';
             self::$ARGS = array_slice(self::$PARTS, 1);
         }
     }
     // 3. Third check: module controller
     if (isset(self::$PARTS[0])) {
         if (!Kennel::$MODULES) {
             Kennel::fetchModules();
         }
         foreach (Kennel::$MODULES as $module => $info) {
             if (is_file(Kennel::$ROOT_PATH . "/modules/{$module}/controllers/" . str_replace('-', '_', self::$PARTS[0]) . '.php')) {
                 self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0]));
                 if (isset(self::$PARTS[1]) && method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) {
                     self::$ACTION = str_replace('-', '_', self::$PARTS[1]);
                     self::$ARGS = array_slice(self::$PARTS, 2);
                 } else {
                     self::$ACTION = 'index';
                     self::$ARGS = array_slice(self::$PARTS, 1);
                 }
             }
         }
     }
     // 4. Forth check: system controller
     if (isset(self::$PARTS[0]) && is_file(Kennel::$ROOT_PATH . '/system/controllers/' . str_replace('-', '_', self::$PARTS[0]) . '.php')) {
         self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0]));
         if (isset(self::$PARTS[1])) {
             if (method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) {
                 self::$ACTION = str_replace('-', '_', self::$PARTS[1]);
                 self::$ARGS = array_slice(self::$PARTS, 2);
             }
         } else {
             self::$ACTION = 'index';
             self::$ARGS = array_slice(self::$PARTS, 1);
         }
     }
     // 5. Fifth check: nothing found
     if (!self::$CONTROLLER) {
         self::$CONTROLLER = 'Main';
     }
     if (!self::$ACTION) {
         self::$ACTION = 'notfound';
     }
     if (self::$CONTROLLER == 'Main' && self::$ACTION == 'notfound') {
         self::$ARGS = self::$PARTS;
     }
     return Kennel::controllerAction(self::$CONTROLLER, self::$ACTION, self::$ARGS);
//.........这里部分代码省略.........
开发者ID:rev087,项目名称:kennel,代码行数:101,代码来源:Request.php


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