Skip to content

Commit

Permalink
When determining language from HTTP_ACCEPT_LANGUAGE, also try base la…
Browse files Browse the repository at this point in the history
…nguage only (#1402)

Fixes Safari sending the language code always with a locale (e.g. it-it
or fr-fr)
  • Loading branch information
flaviocopes authored and rhukster committed Apr 4, 2017
1 parent 459b7c4 commit d338d79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#bugfix)
* Fixed a bad method signature causing warning when running tests on `GPMTest` object
* When determining language from `HTTP_ACCEPT_LANGUAGE`, also try base language only

# v1.2.0
## 03/31/2017
Expand Down
9 changes: 9 additions & 0 deletions system/src/Grav/Common/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ public function setActiveFromUri($uri)
}
}

// repeat if not found, try base language only - fixes Safari sending the language code always
// with a locale (e.g. it-it or fr-fr)
foreach ($preferred as $lang) {
$lang = substr($lang, 0, 2);
if ($this->validate($lang)) {
$this->active = $lang;
break;
}
}
}
}
}
Expand Down

0 comments on commit d338d79

Please sign in to comment.