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


PHP Request::getPreferredLanguage方法代码示例

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


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

示例1: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Detect the bot case => if bot we do nothing
     $isBot = isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']);
     /**
      * If User has never been logged => it will be redirected to his local url
      */
     if (!$request->cookie('locale') && !$isBot) {
         $locale = \App::getLocale();
         // if local doesn't match the current user local => we redirect
         $preferedLocale = $request->getPreferredLanguage($this->locales);
         // If local doesn't match the current user => we redirect the user to the correct url
         if ($locale !== $preferedLocale) {
             // Get Locales of the preferred local
             Session::put('locale', $preferedLocale);
         }
     } elseif ($request->cookie('locale')) {
         Session::put('locale', $request->cookie('locale'));
     }
     if ($request->has('force_locale')) {
         Session::put('locale', $request->get('force_locale'));
         \App::setLocale(Session::get('locale', env('APP_DEFAULT_LOCALE', 'en')));
         return $next($request)->withCookie(cookie()->forever('locale', Session::get('locale')));
     }
     \App::setLocale(Session::get('locale', env('APP_DEFAULT_LOCALE', 'en')));
     return $next($request);
 }
开发者ID:philippejadin,项目名称:Mobilizator,代码行数:34,代码来源:RedirectLang.php

示例2: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string  $l
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //Session::flush();
     if (!Session::has('locale')) {
         /**
          * Get the browser local code and lang code.
          */
         $localCode = $request->getPreferredLanguage();
         $localLang = substr($localCode, 0, 2);
         if (in_array($localLang, $this->lang)) {
             Session::set('locale', $localLang);
         } else {
             Session::set('locale', Config::get('app.locale'));
         }
     }
     /**
      * Set the local config.
      */
     App::setLocale(Session::get('locale'));
     Config::set('app.locale', Session::get('locale'));
     /**
      * Share variables in view.
      */
     if (Config::get('app.locale') == 'fr') {
         View::share(['lang' => 'fr', 'langreverse' => 'en']);
     } else {
         View::share(['lang' => 'en', 'langreverse' => 'fr']);
     }
     return $next($request);
 }
开发者ID:remimetral,项目名称:laravel,代码行数:38,代码来源:LangAutoDetection.php

示例3: tryHeaders

 /**
  * Try to get a prefered Locale from Accept-Headers
  *
  * @return bool
  */
 protected function tryHeaders()
 {
     $language_list = $this->job->languages->lists('slug');
     if ($slug = $this->request->getPreferredLanguage($language_list)) {
         return $this->isValidLanguage($slug);
     }
     return false;
 }
开发者ID:wegnermedia,项目名称:melon,代码行数:13,代码来源:CurrentLanguageDetector.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!Session::has('locale')) {
         Session::put('locale', $request->getPreferredLanguage($this->languages));
     }
     app()->setLocale(Session::get('locale'));
     return $next($request);
 }
开发者ID:Berenes,项目名称:INPQprueba,代码行数:15,代码来源:App.php

示例5: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $this->languages = array_keys(Config::get('app.locales'));
     if (!Session::has('locale')) {
         Session::put('locale', $request->getPreferredLanguage($this->languages));
     }
     $this->app->setLocale(Session::get('locale'));
     return $next($request);
 }
开发者ID:b-l4ck,项目名称:AbuseIO,代码行数:16,代码来源:Locale.php

示例6: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!Session::has('locale')) {
         Session::put('locale', $request->getPreferredLanguage($this->languages));
     }
     app()->setLocale(Session::get('locale'));
     if (!Session::has('statut')) {
         Session::put('statut', Auth::check() ? Auth::user()->role->slug : 'visitor');
     }
     return $next($request);
 }
开发者ID:vihoangson,项目名称:my_blog,代码行数:18,代码来源:App.php

示例7: getCurrentLocale

 /**
  * Returns current language
  *
  * @return string current language
  */
 public function getCurrentLocale()
 {
     if ($this->currentLocale) {
         return $this->currentLocale;
     }
     // Get preferred locale from browser
     if ($this->getConfig('useAcceptLanguageHeader', true)) {
         return $this->request->getPreferredLanguage($this->getSupportedLanguagesKeys());
     }
     // or get application default language
     return $this->defaultLocale;
 }
开发者ID:torann,项目名称:localization,代码行数:17,代码来源:LocaleManager.php

示例8: getPreferredLanguage

 /**
  * Returns the preferred language.
  *
  * @param array $locales An array of ordered available locales
  * @return string|null The preferred locale
  * @static 
  */
 public static function getPreferredLanguage($locales = null)
 {
     //Method inherited from \Symfony\Component\HttpFoundation\Request
     return \Illuminate\Http\Request::getPreferredLanguage($locales);
 }
开发者ID:satriashp,项目名称:tour,代码行数:12,代码来源:_ide_helper.php

示例9: getRequestLocale

 /**
  * @param \Illuminate\Http\Request $request
  * @return string
  */
 protected function getRequestLocale($request)
 {
     $locales = array_unique(array_merge([$this->repository->getDefault()], $this->repository->getAvailable()));
     return $request->getPreferredLanguage($locales);
 }
开发者ID:czim,项目名称:laravel-cms-core,代码行数:9,代码来源:SetLocale.php


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