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


PHP I18n::locale方法代码示例

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


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

示例1: initialize

 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     $this->layout = 'sl';
     $this->loadComponent('Paginator');
     $this->Auth->allow(array('view', 'index'));
     $this->set('homepage_title', __('Homepage Title'));
     $this->loadModel('BlogCategories');
     $this->set('asideBlogCategories', $this->BlogCategories->find('all', array('conditions' => array('enable' => true), 'recursive' => -1))->toArray());
     $this->loadModel('Tags');
     $this->set('asideTags', $this->Tags->find('all', array('conditions' => array('not' => array('taggings_count' => 0)), 'order' => array('taggings_count desc'), 'recursive' => -1))->toArray());
     $session = $this->request->session();
     $this->set('session', $session);
     /*
     if($session->check('theme')) {
     $this->theme=$session->read('theme');
     } else {
     $this->theme=null;
     }
     */
     if ($session->check('Config.language')) {
         I18n::locale($session->read('Config.language'));
     } else {
         I18n::locale($session->read('ko_KR'));
     }
 }
开发者ID:sleeping-lion,项目名称:slboard_cakephp3,代码行数:33,代码来源:SLController.php

示例2: beforeFilter

 public function beforeFilter(Event $event)
 {
     $permissions_file = json_decode(file_get_contents(DS . CONFIG . DS . 'permissions.json'));
     // set controller shared variables
     $this->permission = $permissions_file;
     $this->active_user = $this->Auth->user();
     // admin section
     if (isset($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin') {
         if ($this->request->params['controller'] == 'Users' && $this->request->params['action'] == 'add') {
             $this->Auth->allow();
         } else {
             $this->Auth->deny();
         }
     } else {
         $this->Auth->allow($this->request['action']);
     }
     // Use this across app views for admin only parts
     $this->set('active_user', $this->Auth->user());
     $this->set('permission', $permissions_file);
     // load posts and check for unapproved posts to add them into notifications
     $this->loadModel('Posts');
     $not_approved_posts = $this->Posts->find('all')->where(['approved' => false])->toArray();
     // set all notifications into this view variable
     $this->set('notifications', [$not_approved_posts]);
     // read session lang var and set app lang var
     $session = $this->request->session();
     if ($session->read('language')) {
         I18n::locale($session->read('language'));
     }
 }
开发者ID:borisknot,项目名称:cmanage,代码行数:30,代码来源:AppController.php

示例3: beforeFilter

 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     $session = $this->request->session();
     $lang = 'en';
     if (isset($this->request->params['lang'])) {
         $lang = $this->request->params['lang'];
     } else {
         if ($session->check('Config.language')) {
             $lang = $session->read('Config.language');
         }
     }
     $session->write('Config.language', $lang);
     // Change current language by post request
     if ($this->request->is('post') && isset($this->request->data['language'])) {
         $newLang = $this->request->data['language'];
         $transUrl = $this->translateUrl($newLang);
         $this->redirect($transUrl);
     }
     $this->set('lang', $lang);
     $this->set('controller', $this->name);
     I18n::locale($lang);
     Time::setToStringFormat('YYYY-MM-dd HH:mm:ss');
     Type::build('datetime')->useLocaleParser();
     $this->Auth->config(['unauthorizedRedirect' => false]);
     $this->Auth->allow(['login', 'init']);
     $user = $this->Auth->user();
     if (isset($user)) {
         $username = $user['username'];
         $this->set(['is_authorized' => true, 'username' => $username]);
     } else {
         $this->set('is_authorized', false);
     }
 }
开发者ID:GreeNoir,项目名称:game-wizard,代码行数:34,代码来源:AppController.php

示例4: testLangEmpty

 /**
  * Test language - empty
  *
  * @return void
  */
 public function testLangEmpty()
 {
     $expected = I18n::locale();
     $this->get('/pages/home');
     $actual = I18n::locale();
     $this->assertEquals($expected, $actual);
 }
开发者ID:jenwei,项目名称:Website,代码行数:12,代码来源:AppControllerTest.php

示例5: render

    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $locale = isset($data['locale']) ? $data['locale'] : I18n::locale();
        $timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget');
        $timestamp = null;
        $timezoneOffset = null;
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTimeInterface && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            if ($timezoneAware) {
                $timestamp = $val->format('U');
                $dateTimeZone = new DateTimeZone(date_default_timezone_get());
                $timezoneOffset = $dateTimeZone->getOffset($val) / 60;
            }
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
html;
        if ($timezoneAware && isset($timestamp, $timezoneOffset)) {
            $widget .= <<<html
                    data-timestamp="{$timestamp}"
                    data-timezone-offset="{$timezoneOffset}"
html;
        }
        $widget .= <<<html
                    {$required}
                    {$disabled}
                />
                <label for="{$id}" class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </label>
            </div>
html;
        return $widget;
    }
开发者ID:friendsofcake,项目名称:crud-view,代码行数:68,代码来源:DateTimeWidget.php

示例6: restoreLocale

 /**
  * Restore to current locale if applicable.
  *
  * @return void
  */
 protected function restoreLocale()
 {
     $primaryLocale = $this->getPrimaryLocale();
     if ($primaryLocale && $primaryLocale !== $this->locale) {
         I18n::locale($this->locale);
     }
 }
开发者ID:alescx,项目名称:cakephp-tools,代码行数:12,代码来源:Mailer.php

示例7: getDateLocale

 public function getDateLocale()
 {
     $options = [];
     $defaultLocale = I18n::locale();
     $defaultLocale = isset($defaultLocale) ? $defaultLocale : 'en';
     $defaultLocale = strtolower($defaultLocale);
     $defaultLocale = str_replace('-', '_', $defaultLocale);
     switch ($defaultLocale) {
         case 'fr':
         case 'fr_fr':
             echo $this->AlaxosHtml->script('Alaxos.bootstrap/datepicker/locales/bootstrap-datepicker.fr.min', ['block' => true]);
             $options['language'] = 'fr';
             $options['alaxos_js_format'] = 'd/m/y';
             //format for Alaxos JS date parsing
             $options['datepicker_format'] = 'dd/mm/yyyy';
             $options['php_date_format'] = 'd/m/Y';
             break;
         case 'fr_ch':
             echo $this->AlaxosHtml->script('Alaxos.bootstrap/datepicker/locales/bootstrap-datepicker.fr-CH.min', ['block' => true]);
             $options['language'] = 'fr';
             $options['alaxos_js_format'] = 'd.m.y';
             //format for Alaxos JS date parsing
             $options['datepicker_format'] = 'dd.mm.yyyy';
             $options['php_date_format'] = 'd.m.Y';
             break;
         default:
             $options['language'] = 'en';
             $options['alaxos_js_format'] = 'y/m/d';
             //format for Alaxos JS date parsing
             $options['datepicker_format'] = 'yyyy/mm/dd';
             $options['php_date_format'] = 'Y/m/d';
             break;
     }
     return $options;
 }
开发者ID:alaxos,项目名称:cakephp3-libs,代码行数:35,代码来源:AlaxosFormHelper.php

示例8: language

 /**
  * Retrieves information for current language.
  *
  * Useful when you need to read current language's code, language's direction,
  * etc. It will returns all the information if no `$key` is given.
  *
  * ### Usage:
  *
  * ```php
  * language('code');
  * // may return: en
  *
  * language();
  * // may return:
  * [
  *     'name' => 'English (US)',
  *     'locale' => 'en_US',
  *     'code' => 'en',
  *     'country' => 'US',
  *     'direction' => 'ltr',
  *     'icon' => 'us.gif',
  * ]
  * ```
  *
  * Accepted keys are:
  *
  * - `name`: Language's name, e.g. `English`, `Spanish`, etc.
  * - `locale`: Full localized language's code, e.g. `en-US`, `es`, etc.
  * - `code`: Language's ISO 639-1 code, e.g. `en`, `es`, `fr`, etc. (lowercase)
  * - `country`: Language's country code, e.g. `US`, `ES`, `FR`, etc. (uppercase)
  * - `direction`: Language writing direction, possible values are "ltr" or "rtl".
  * - `icon`: Flag icon (it may be empty) e.g. `es.gif`, `es.gif`,
  *    icons files are located in Locale plugin's `/webroot/img/flags/` directory,
  *    to render an icon using HtmlHelper you should do as follow:
  *
  * ```php
  * <?= $this->Html->image('Locale.flags/' . language('icon')); ?>
  * ```
  *
  * @param string|null $key The key to read, or null to read the whole info
  * @return mixed
  */
 function language($key = null)
 {
     $code = I18n::locale();
     if ($key !== null) {
         return Configure::read("QuickApps.languages.{$code}.{$key}");
     }
     return Configure::read('QuickApps.languages.{$code}');
 }
开发者ID:quickapps-plugins,项目名称:locale,代码行数:50,代码来源:bootstrap.php

示例9: initialize

 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * @return void
  */
 public function initialize()
 {
     I18n::locale('fr_FR');
     $this->loadComponent('Flash');
     $this->loadComponent('Auth', ['authenticate' => ['Form' => ['fields' => ['username' => 'email', 'password' => 'password']]], 'loginAction' => ['controller' => 'Users', 'action' => 'login']]);
     // Allow the display action so our pages controller
     // continues to work.
     $this->Auth->allow(['login']);
 }
开发者ID:eripoll,项目名称:webiplan,代码行数:16,代码来源:AppController.php

示例10: beforeDispatch

 /**
  * Inspects the request for the Accept-Language header and sets the
  * Locale for the current runtime if it matches the list of valid locales
  * as passed in the configuration.
  *
  * @param \Cake\Event\Event $event The event instance.
  * @return void
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     $locale = Locale::acceptFromHttp($request->header('Accept-Language'));
     if (!$locale || !empty($this->_locales) && !in_array($locale, $this->_locales)) {
         return;
     }
     I18n::locale($locale);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:17,代码来源:LocaleSelectorFilter.php

示例11: testTokenExpiredLocale

 /**
  * Test tokenExpired another locale
  *
  * @return void
  */
 public function testTokenExpiredLocale()
 {
     I18n::locale('es_AR');
     $this->User->token_expires = '+1 day';
     $isExpired = $this->User->tokenExpired();
     $this->assertFalse($isExpired);
     $this->User->token_expires = '-1 day';
     $isExpired = $this->User->tokenExpired();
     $this->assertTrue($isExpired);
 }
开发者ID:GF-TIC,项目名称:users,代码行数:15,代码来源:UserTest.php

示例12: initialize

 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * e.g. `$this->loadComponent('Security');`
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     $this->loadComponent('RequestHandler');
     $this->loadComponent('Flash');
     if ($this->request->session()->check('Config.locale')) {
         I18n::locale($this->request->session()->read('Config.locale'));
         // cambio del idioma
     }
 }
开发者ID:avg0043,项目名称:TFG_Autocorrecc_Java,代码行数:19,代码来源:AppController.php

示例13: checkLanguage

 /**
  * Check for browser language and set website language to it
  *
  * @return void
  */
 protected function checkLanguage()
 {
     if (!empty($_GET['lang'])) {
         $this->request->session()->write('lang', $_GET['lang']);
         I18n::locale($_GET['lang']);
     } else {
         $lang = $this->request->session()->read('lang');
         I18n::locale($lang);
     }
 }
开发者ID:jenwei,项目名称:Website,代码行数:15,代码来源:AppController.php

示例14: beforeFilter

 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     $this->_setLanguage();
     $language = $this->request->session()->read('Config.language');
     I18n::locale($language);
     if (!$this->request->session()->check('User') && $this->action == 'admin_login') {
         $this->redirect('/admin/admin_login');
     }
 }
开发者ID:TranBinhLuan,项目名称:junzeron,代码行数:10,代码来源:AppController.php

示例15: change

 /**
  * Index method
  *
  * @return void
  */
 public function change($locale = null)
 {
     if ($locale == null) {
         $locale = 'en_US';
     }
     I18n::locale($locale);
     $session = $this->request->session();
     $session->write('locale', $locale);
     $this->redirect($this->referer());
 }
开发者ID:blackfalck,项目名称:receiptcontrol,代码行数:15,代码来源:LocaleController.php


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