Skip to content

Commit

Permalink
Set language from browser header if available iRail#242
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertware committed Dec 6, 2016
1 parent 7e9986a commit c54d189
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/Http/Middleware/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ class Language
*/
public function handle($request, Closure $next)
{
$language = (Input::get('lang')) ?: Session::get('lang');
$this->setSupportedLanguage($language);

$browserLanguage = \Locale::lookup(['nl', 'fr', 'en'], $request->server('HTTP_ACCEPT_LANGUAGE'));

// if the user didn't set a language in the cookie, and a browser language is available, use browser language.
if (empty(Session::get('lang') && !empty($browserLanguage))) {
$language = $browserLanguage;
} else {
$language = (Input::get('lang')) ?: Session::get('lang');
}

$this->setSupportedLanguage($language);
return $next($request);
}

Expand Down

0 comments on commit c54d189

Please sign in to comment.