當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。