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


PHP I18n::locale方法代码示例

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


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

示例1: setLocale

 public static function setLocale($locale)
 {
     self::$locale = $locale;
     if ($locale != DEFAULT_LOCALE) {
         self::loadArray();
     }
 }
开发者ID:chaobj001,项目名称:tt,代码行数:7,代码来源:I18n.php

示例2: beforeAction

 public function beforeAction()
 {
     // clear cache when post data arrives
     if ($this->controller instanceof AdminController) {
         if ($this->controller->request->isPost()) {
             $this->clear();
         }
         return true;
     }
     if ($this->controller->UserLogin->loggedin() || Registry::get('DEBUG') > DEBUG_PRODUCTION) {
         return true;
     }
     if (!isset($this->config[$this->controller->name][$this->controller->action])) {
         return true;
     }
     if ($this->controller->request->isGet()) {
         $ttl = $this->config[$this->controller->name][$this->controller->action];
         $id = $this->controller->name . '_' . $this->controller->layout . '_' . $this->controller->action . '_' . md5($this->controller->action . http_build_query($this->controller->params) . I18n::locale());
         $this->filename = CACHE_DIR . 'views/' . $id . '.html';
         if (file_exists($this->filename)) {
             // read from cache
             if (filemtime($this->filename) + $ttl > time()) {
                 $rendered = file_get_contents($this->filename);
                 // replace MD5
                 $rendered = preg_replace('@md5" value="[\\w\\d]+"@', 'md5" value="' . md5($this->controller->request->host . SALT) . '"', $rendered);
                 $rendered = str_replace('</body>', '<!-- cached ' . ephFrame::compileTime() . ' --></body>', $rendered);
                 echo $rendered;
                 die;
             }
         }
     }
     return true;
 }
开发者ID:Ephigenia,项目名称:harrison,代码行数:33,代码来源:ActionCache.php

示例3: initialize

 /**
  * 
  * Initializes the php-gettext
  * Remember to load first php-gettext
  * @param string $locale
  * @param string $charset
  * @param string $domain
  */
 public static function initialize($locale = 'en_UK', $charset = 'utf-8', $domain = 'messages')
 {
     /**
      * setting the statics so later we can access them from anywhere
      */
     //we allow to choose lang from the url
     if (Core::config('i18n.allow_query_language') == 1) {
         if (Core::get('language') !== NULL) {
             $locale = Core::get('language');
         } elseif (Cookie::get('user_language') !== NULL) {
             $locale = Cookie::get('user_language');
         }
         Cookie::set('user_language', $locale, Core::config('auth.lifetime'));
     }
     self::$lang = $locale;
     //used in i18n kohana
     self::$locale = $locale;
     self::$charset = $charset;
     self::$domain = $domain;
     //time zone set in the config
     date_default_timezone_set(Kohana::$config->load('i18n')->timezone);
     //Kohana core charset, used in the HTML templates as well
     Kohana::$charset = self::$charset;
     /**
      * In Windows LC_MESSAGES are not recognized by any reason.
      * So we check if LC_MESSAGES is defined to avoid bugs,
      * and force using gettext
      */
     if (defined('LC_MESSAGES')) {
         $locale_res = setlocale(LC_MESSAGES, self::$locale);
     } else {
         $locale_res = FALSE;
     }
     // used with a function money_format
     setlocale(LC_MONETARY, self::$locale);
     /**
      * check if gettext exists if not uses gettext dropin
      */
     if (!function_exists('_') or $locale_res === FALSE or empty($locale_res)) {
         /**
          * gettext override
          * v 1.0.11
          * https://launchpad.net/php-gettext/
          * We load php-gettext here since Kohana_I18n tries to create the function __() function when we extend it.
          * PHP-gettext already does this.
          */
         require Kohana::find_file('vendor', 'php-gettext/gettext', 'inc');
         T_setlocale(LC_MESSAGES, self::$locale);
         T_bindtextdomain(self::$domain, DOCROOT . 'languages');
         T_bind_textdomain_codeset(self::$domain, self::$charset);
         T_textdomain(self::$domain);
         //force to use the gettext dropin
         self::$dropin = TRUE;
     } else {
         bindtextdomain(self::$domain, DOCROOT . 'languages');
         bind_textdomain_codeset(self::$domain, self::$charset);
         textdomain(self::$domain);
     }
 }
开发者ID:Wildboard,项目名称:WbWebApp,代码行数:67,代码来源:i18n.php

示例4: getText

 public function getText($varname, $default = null)
 {
     $languageId = I18n::locale();
     $languageModelName = 'Text' . ucFirst(substr($languageId, 0, 2));
     if (!isset($this->{$languageModelName})) {
         $languageModelName = 'Text' . ucfirst(substr(Registry::get('I18n.language'), 0, 2));
     }
     if ($this->{$languageModelName} instanceof Model && $this->{$languageModelName}->hasField($varname)) {
         return coalesce($this->{$languageModelName}->get($varname), $default, false);
     }
 }
开发者ID:Ephigenia,项目名称:harrison,代码行数:11,代码来源:MediaFile.php

示例5: initialize

 public function initialize()
 {
     parent::initialize();
     $this->loadComponent('Flash');
     /*$this->loadComponent(
           'Auth', [
               'logoutRedirect' => [
                   'controller' => 'Pages',
                   'action' => 'display',
                   'home'
               ],
               'authorize' => 'Controller',
               'unauthorizedRedirect' => '/'  // authenticated, but unauthorized
           ]
       );*/
     // Now set role flags
     /*$user_id=$this->Auth->user('id');
       if(!is_null($user_id)) {
           $users = TableRegistry::get('Users');
           $user=$users->get($user_id, ['contain' => ['Roles']]);
           $this->isAdmin = false;
           $this->isTeacher = false;
           foreach($user->roles as $role) {
               if($role->title=='admin') $this->isAdmin=true;
               if($role->title=='teacher') $this->isTeacher=true;
           }
       }*/
     // The language is initially set in bootstrap.php.  If we want to change the language on-the-fly,
     // such as in clicking the little flags, then we need to store the desired language in the session,
     // retrieve that value here, and use that value to override the default language.  Even though the
     // default in bootstrap.php is en_EN, we still need to set it here.
     $lang = $this->request->session()->read('Config.language');
     switch ($lang) {
         case "zh_CN":
             I18n::locale('zh_CN');
             break;
         case "zh_PN":
             I18n::locale('zh_PN');
             break;
         case "en_US":
             I18n::locale('en_US');
             break;
     }
 }
开发者ID:bostontrader,项目名称:acctwerx,代码行数:44,代码来源:AppController.php

示例6: beforeAction

 public function beforeAction()
 {
     // set languages for view
     // @todo move this to language controller or component
     if (isset($this->Language) && ($this->Languages = $this->Language->findAll())) {
         // make languages available in the view
         $this->data->set('Languages', $this->Languages);
         // set new locale from language_id=[de|en|fr] action
         foreach ($this->Languages as $Language) {
             if (!empty($this->params['language_id']) && $Language->id == $this->params['language_id']) {
                 I18n::locale($Language->locale);
                 break;
             }
         }
         // reset locale to default if locale not found in languages
         foreach ($this->Languages as $Language) {
             if ($Language->locale == I18n::locale()) {
                 $found = true;
             }
         }
         if (@$found !== true) {
             I18n::locale(Registry::get('I18n.language'));
         }
     }
     // detect desired content type and return headers and change
     // action to use different template
     $layoutContentTypeMapping = array('json' => 'application/json', 'rss' => 'application/rss+xml', 'vcal' => 'text/calendar', 'txt' => 'text/plain');
     // response as json if requested
     if ($this->request->isAjax() && preg_match('@application\\/json|text\\/javascript@i', $this->request->header->get('accept'))) {
         $this->layout = 'json';
     }
     if (array_key_exists($this->layout, $layoutContentTypeMapping)) {
         $this->response->header->set('Content-Type', $layoutContentTypeMapping[$this->layout]);
         $this->action .= '.' . $this->layout;
     }
     return parent::beforeAction();
 }
开发者ID:Ephigenia,项目名称:harrison,代码行数:37,代码来源:AppController.php

示例7: strtr

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php 
echo I18n::locale();
?>
">
	<head>
		<title><?php 
echo strtr(@$pageTitle, array('<q>' => '"', '</q>' => '"'));
?>
</title>
		<!--[if IE 8]><meta http-equiv="X-UA-Compatible" content="IE=7" /><![endif]-->
		<base href="<?php 
echo Router::url('admin');
?>
" />
		<?php 
if (isset($MetaTags)) {
    echo String::indent($MetaTags->render(), 2, TAB, 1);
}
if (isset($CSS)) {
    $CSS->addFiles(array('reset', 'simplePreview', 'mainMenu', 'debug', 'admin', 'form', 'login', 'dialog', 'table', 'debug', 'mediaFile'));
    echo String::indent($CSS->render(), 2, TAB, 1);
}
// admin favicon
if (file_exists('./faviconAdmin.ico')) {
    echo '<link rel="shortcut icon" type="image/ico" href="' . WEBROOT . 'faviconAdmin.ico" />' . LF;
    // normal favicon
} elseif (file_exists('./favicon.ico')) {
    echo '<link rel="shortcut icon" type="image/ico" href="' . WEBROOT . 'favicon.ico" />' . LF;
}
// iPod-Touch/iPhone Icons
开发者ID:Ephigenia,项目名称:harrison,代码行数:31,代码来源:default.php

示例8: config

 public static function config($options)
 {
     I18n::$locale = $options['locale'];
     I18n::loadLocaleFiles();
 }
开发者ID:quyen91,项目名称:lfpr,代码行数:5,代码来源:I18nClass.php

示例9: set_locale

 public static function set_locale($locale)
 {
     // Reset the translations array
     I18n::$translations = array();
     I18n::$locale = $locale;
 }
开发者ID:assad2012,项目名称:gallery3-appfog,代码行数:6,代码来源:I18n.php

示例10: findNode

 /**
  * Tries to find a node by the passed $idOrNodeName
  *	
  * @param integer|string $idOrNodeName
  * @return Node|boolean
  */
 public function findNode($idOrNodeName, $languageId = null)
 {
     $this->depth = 1;
     $languageId = coalesce(@$languageId, I18n::locale());
     if (is_int($idOrNodeName)) {
         $conditions = array('id' => $idOrNodeName);
     } else {
         $conditions = array('NodeText' . ucfirst(substr($languageId, 0, 2)) . '.uri' => DBQuery::quote($idOrNodeName));
     }
     return $this->find(array('conditions' => $conditions));
 }
开发者ID:Ephigenia,项目名称:harrison,代码行数:17,代码来源:Node.php

示例11: __

<!DOCTYPE html>
<html lang="<?php 
echo I18n::locale()->getPrimaryLanguage();
?>
">
	<head>
	
		<meta charset="UTF-8" />
		<meta name="description" content="<?php 
echo __("layout.meta_description");
?>
" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		
		<link rel="stylesheet" type="text/css" media="all" href="<?php 
echo Helpers::asset("all.min.css");
?>
" />
		<link rel="shortcut icon" href="<?php 
echo Helpers::asset("images/favicon.ico");
?>
" />
		
		<script type="text/javascript" src="<?php 
echo Helpers::asset("all.min.js");
?>
"></script>
		
		<title>
			<?php 
echo $this->title();
开发者ID:solymosi,项目名称:bexio-exercise,代码行数:31,代码来源:layout.php

示例12: setLocale

 /**
  * Set locale
  * 
  * <b>Note:</b> This will sequentially call <samp>setlocale(LC_ALL, $locale)</samp>
  * 
  * @param  string  Locale in 2-character notation. ie. 'en' or 'sv'.
  * @return string  Old locale or "" if none
  */
 public static function setLocale($locale)
 {
     if (self::$locale == $locale) {
         return $locale;
     }
     $old_locale = self::$locale;
     self::$locale = strtolower(substr($locale, 0, 2));
     if ($old_locale) {
         foreach (self::$domains as $domain) {
             $domain->freeResources($old_locale);
         }
     }
     setlocale(LC_ALL, $locale);
     return $old_locale;
 }
开发者ID:rsms,项目名称:phpab,代码行数:23,代码来源:I18n.php

示例13: setLocale

 public static function setLocale($locale)
 {
     self::$locale = $locale;
 }
开发者ID:silentworks,项目名称:the-compressor,代码行数:4,代码来源:I18n.php

示例14: setLocale

 public static function setLocale($locale)
 {
     self::$locale = $locale;
     self::loadArray();
 }
开发者ID:ariksavage,项目名称:superior-optical-eyewear,代码行数:5,代码来源:I18n.php


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