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


PHP Locale::acceptFromHttp方法代碼示例

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


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

示例1: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $e->getApplication()->getServiceManager()->get('translator');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // Add translation
     $translator = $e->getApplication()->getServiceManager()->get('translator');
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $setLang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
     } else {
         $setLang = '';
     }
     $translator->setLocale(\Locale::acceptFromHttp($setLang))->setFallbackLocale('en_US');
     // Add ACL information to the Navigation view helper
     $sm = $e->getApplication()->getServiceManager();
     $authorize = $sm->get('BjyAuthorize\\Service\\Authorize');
     $acl = $authorize->getAcl();
     $role = $authorize->getIdentity();
     \Zend\View\Helper\Navigation::setDefaultAcl($acl);
     \Zend\View\Helper\Navigation::setDefaultRole($role);
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Application', 'dispatch.error', function ($e) use($sm) {
         if ($e->getParam('exception')) {
             $sm->get('Zend\\Log\\Logger')->crit($e->getParam('exception'));
         }
     });
 }
開發者ID:riceri,項目名稱:MvitInvoice,代碼行數:27,代碼來源:Module.php

示例2: onBootstrap

 public function onBootstrap(EventInterface $event)
 {
     /*$eventManager        = $e->getApplication()->getEventManager();
       $moduleRouteListener = new ModuleRouteListener();
       $moduleRouteListener->attach($eventManager);*/
     $application = $event->getTarget();
     $serviceManager = $application->getServiceManager();
     $translator = $serviceManager->get('translator');
     $translator->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']))->setFallbackLocale('en_US');
     $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $event) use($serviceManager) {
         $request = $event->getRequest();
         $response = $event->getResponse();
         if (!($request instanceof HttpRequest && $response instanceof HttpResponse)) {
             return;
             // CLI application maybe?
         }
         $authAdapter = $serviceManager->get('AuthenticationAdapter');
         $authAdapter->setRequest($request);
         $authAdapter->setResponse($response);
         $result = $authAdapter->authenticate();
         if ($result->isValid()) {
             return;
             // OK
         }
         $response->setContent('Access denied');
         $response->setStatusCode(HttpResponse::STATUS_CODE_401);
         $event->setResult($response);
         // to end
         return false;
         // event propagation stop
     });
 }
開發者ID:Checo1983,項目名稱:booklist,代碼行數:32,代碼來源:Module.php

示例3: getLanguage

 public function getLanguage($format = NULL, $test = NULL)
 {
     $locale = $this->getContainer();
     if ($this->getController() != NULL && $this->getController()->params()->fromRoute($this->getIdentifiantRequest())) {
         $language = $this->getController()->params()->fromRoute($this->getIdentifiantRequest());
     } else {
         if ($locale->offsetExists($this->getIdentifiantSession())) {
             $language = $locale->offsetGet($this->getIdentifiantSession());
         } else {
             $language = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
             $language = $this->convertToAuthorizedLanguage($language);
         }
     }
     switch ($format) {
         case 'upper':
             $language = strtoupper($language);
             break;
         case 'lower':
             $language = strtolower($language);
             break;
         default:
             break;
     }
     $this->setLanguage($language);
     $this->saveInSession();
     return $this->language;
 }
開發者ID:b-medias,項目名稱:bZF2,代碼行數:27,代碼來源:LanguagePlugin.php

示例4: translate

 public static function translate($source_string, $locale = null)
 {
     if (!$locale) {
         if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
         } else {
             $locale = 'en_US';
         }
     }
     $languages = self::getConfigValue('languages');
     if ($languages != array()) {
         foreach ($languages as $language_group => $language_codes) {
             if (file_exists($_SERVER['APPLICATION_ROOT'] . "config/i18n/" . $language_group . ".yml")) {
                 foreach ($language_codes as $code) {
                     if (!isset($_SESSION['dinkly']['languages'])) {
                         $_SESSION['dinkly']['languages'] = array();
                     }
                     $translations = Yaml::parse($_SERVER['APPLICATION_ROOT'] . "config/i18n/" . $language_group . ".yml");
                     $_SESSION['dinkly']['languages'][$code] = $translations;
                 }
             }
         }
     }
     if (isset($_SESSION['dinkly']['languages'][$locale]['translations'][$source_string])) {
         return $_SESSION['dinkly']['languages'][$locale]['translations'][$source_string];
     }
     //Default to original string
     return $source_string;
 }
開發者ID:bigSiebs,項目名稱:poetry_vote,代碼行數:29,代碼來源:BaseDinkly.php

示例5: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
     $fallbackLocale = 'en_US';
     $sm = $e->getApplication()->getServiceManager();
     $sm->get('translator')->setLocale($locale)->setFallbackLocale($fallbackLocale);
     $type = 'phpArray';
     $pattern = './vendor/zendframework/zendframework/resources/languages/%s/Zend_Validate.php';
     $textDomain = 'default';
     $translator = $e->getApplication()->getServiceManager()->get('translator');
     if (file_exists(sprintf($pattern, $locale))) {
         $translator->addTranslationFile($type, sprintf($pattern, $locale), $textDomain);
     } else {
         if (file_exists(sprintf($pattern, preg_replace('/_(.*)/', '', $locale)))) {
             $translator->addTranslationFile($type, sprintf($pattern, preg_replace('/_(.*)/', '', $locale)), $textDomain);
         } else {
             $pattern = sprintf($pattern, preg_replace('/_(.*)/', '', $fallbackLocale));
             $translator->addTranslationFile($type, $pattern, $textDomain);
         }
     }
     \Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
 }
開發者ID:juizmill,項目名稱:ZF2-Test-Authentication,代碼行數:25,代碼來源:Module.php

示例6: getLocaleFromBrowser

 /**
  * Get locale from browser
  *
  * @return string
  * @throws LocaleNotFoundException
  */
 public function getLocaleFromBrowser()
 {
     $locale = \Locale::acceptFromHttp($this->localeHeader);
     if (is_null($locale)) {
         throw new LocaleNotFoundException('Locale could not be obtain from browser');
     }
     return $this->getLocaleFromOptionsByKey($locale);
 }
開發者ID:jakubigla,項目名稱:zf-locale,代碼行數:14,代碼來源:LocaleNameParserService.php

示例7: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $tanslator = $e->getApplication()->getServiceManager()->get('translator');
     $tanslator->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']))->setFallBackLocale('en_US');
 }
開發者ID:ahmed-hamdy90,項目名稱:build_web_app_using_Zend_2,代碼行數:8,代碼來源:Module.php

示例8: getCanonicalLocale

 /**
  * @return string
  */
 public static function getCanonicalLocale()
 {
     try {
         $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
         return \Locale::canonicalize($locale);
     } catch (\Exception $e) {
         return static::getDefaultLocale();
     }
 }
開發者ID:chansig,項目名稱:directoryindex,代碼行數:12,代碼來源:Translation.php

示例9: getLocale

 public function getLocale()
 {
     if ($this->locale === null) {
         if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             $this->locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
         }
     }
     return $this->locale;
 }
開發者ID:ThaDafinser,項目名稱:Piwik-GeoIpChain,代碼行數:9,代碼來源:LocationProvider.php

示例10: getTranslatedDate

 public static function getTranslatedDate(\DateTime $date)
 {
     $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
     if ($locale == "el_GR" || $locale == "el") {
         $day = self::$translatedDays[$date->format("w")];
     } else {
         $day = $date->format("D");
     }
     return $day . " " . $date->format("j/m");
 }
開發者ID:JoshBour,項目名稱:karolina,代碼行數:10,代碼來源:DateUtils.php

示例11: onRoute

 /**
  * Called after routing
  *
  * @param MvcEvent $event
  */
 public function onRoute(MvcEvent $event)
 {
     $serviceManager = $event->getApplication()->getServiceManager();
     /* @var RouteMatch $routeMatch */
     $routeMatch = $event->getRouteMatch();
     $language = '';
     // check if the language is set by routing (parameter, domain name, etc)
     if ($routeMatch->getParam('language') == '') {
         // get route
         $route = explode('/', $routeMatch->getMatchedRouteName());
         //
         $module = $route[0];
         /** @var \Msingi\Cms\Settings $settings */
         $settings = $event->getApplication()->getServiceManager()->get('Settings');
         // get defaults from settings
         $multilanguage = (bool) $settings->get($module . ':languages:multilanguage');
         $language_default = $settings->get($module . ':languages:default');
         $languages_enabled = $settings->get($module . ':languages:enabled');
         if ($multilanguage && is_array($languages_enabled)) {
             /** @var \Zend\Http\Request $request */
             $request = $event->getRequest();
             // try to get language from cookie
             if ($request->getCookie('language') != '') {
                 $language = $event->getRequest()->getCookie('language');
             }
             // try to get language from browser
             if ($language == '' && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $language = \Locale::getPrimaryLanguage(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']));
             }
             // fallback to default language if given one is not supported
             if (!in_array($language, $languages_enabled)) {
                 $language = $language_default;
             }
         } else {
             // not multilanguage module, use default language
             $language = $language_default;
         }
         $routeMatch->setParam('language', $language);
     } else {
         $language = $routeMatch->getParam('language');
         $language_default = $language;
     }
     // translator
     $translator = $serviceManager->get('Translator');
     $translator->setLocale($language)->setFallbackLocale($language_default);
     // cache
     $cache = $serviceManager->get('Application\\Cache');
     if ($cache) {
         $translator->setCache($cache);
     }
 }
開發者ID:msingi,項目名稱:msingi,代碼行數:56,代碼來源:LocaleListener.php

示例12: init

 public function init()
 {
     parent::init();
     // Set language
     if (!isset(Yii::app()->request->cookies['lang'])) {
         $language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']) ?: 'en_US';
         $cookie = new CHttpCookie('lang', $language);
         $cookie->expire = time() + 60 * 60 * 24 * 30;
         Yii::app()->request->cookies['lang'] = $cookie;
     } else {
         $language = (string) Yii::app()->request->cookies['lang'];
     }
     Yii::app()->setLanguage($language);
 }
開發者ID:latik,項目名稱:yii-user,代碼行數:14,代碼來源:User.php

示例13: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     Paginator::setDefaultItemCountPerPage(30);
     ini_set('html_errors', 'Off');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $sm = $e->getApplication()->getServiceManager();
     $em = $sm->get('doctrine.entitymanager.orm_default');
     $auth = $sm->get('Zend\\Authentication\\AuthenticationService');
     if (Cons::isConsole()) {
         $locale = locale_get_default();
     } else {
         /* @var $al \Zend\Http\Header\Accept */
         $al = $e->getRequest()->getHeaders('accept-language');
         if ($al) {
             $locales = $al->getPrioritized();
             $locale = reset($locales)->getTypeString();
             \Locale::acceptFromHttp($locale);
         } else {
             $locale = locale_get_default();
         }
     }
     /** @var Translator $translator */
     $translator = $sm->get('MvcTranslator');
     $translator->setLocale(mb_substr($locale, 0, 2));
     //        $translator->getEventManager()->attach('missingTranslation', array($this, 'translationListener'));
     AbstractValidator::setDefaultTranslator($translator);
     //
     // Narediti session tako, da se virtual hosti ne bodo med seboj mešali
     // da se avtentikacija ne prenaša med vhosti
     // poskrbim za identiteto uporabnika
     if ($e->getRequest() instanceof Request) {
         // handling autorizacij preko konzole
         $this->setIdentity('console@ifigenija.si', $auth, $em);
     } else {
         /* @var $request Request2 */
         $request = $e->getRequest();
         $header = $request->getHeader('Authorization');
         if ($header instanceof Authorization && strlen($header->getFieldValue()) > 10) {
             $this->tryHttpAuth($auth, $em, $e);
         }
     }
     $identity = $auth->getIdentity();
     $evm = $em->getEventManager();
     $evm->addEventSubscriber(new RevisionsListener($sm, $identity));
     $config = $sm->get('entity.metadata.factory')->getAllEntityConfig();
     $evm->addEventSubscriber(new PrePersistListener($config));
 }
開發者ID:ifigenija,項目名稱:server,代碼行數:49,代碼來源:Module.php

示例14: onBootstrap

 /**
  * @internal
  */
 public function onBootstrap(\Zend\EventManager\EventInterface $e)
 {
     $eventManager = $e->getParam('application')->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'forceLogin'));
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'setStrictVars'));
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'setMenu'));
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'setLayoutTitle'));
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'onError'));
     $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'onError'));
     // Evaluate locale from HTTP header. Affects translations, date/time rendering etc.
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         \Locale::setDefault(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']));
     }
     // Attach translator to validators
     \Zend\Validator\AbstractValidator::setDefaultTranslator($e->getApplication()->getServiceManager()->get('MvcTranslator'));
 }
開發者ID:hschletz,項目名稱:braintacle,代碼行數:19,代碼來源:Module.php

示例15: onRoute

 public function onRoute(\Zend\EventManager\EventInterface $e)
 {
     // Event manager of the app
     $application = $e->getApplication();
     $routeMatch = $e->getRouteMatch();
     $sm = $application->getServiceManager();
     $translator = $sm->get('translator');
     // $routeMatch->getParam('lang');
     // By default, the translator will get the locale to use from the Intl extension’s Locale class. If you want to set an alternative locale explicitly, you can do so by passing it to the setLocale() method.
     // $translator->setLocale('bg_BG');
     // echo $_SERVER["HTTP_ACCEPT_LANGUAGE"];
     // allow intl extension
     $translator->setLocale(\Locale::acceptFromHttp($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
     //-		echo '<h1>On Route</h1>';
     // echo $translator->getLocale();
 }
開發者ID:houzoumi,項目名稱:fmi,代碼行數:16,代碼來源:Module.php


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